{
qDebug() << __PRETTY_FUNCTION__;
- QByteArray arr = m_database->getPopularTags();
-
- parsePopularTagsData(arr);
+ buildRequest(GET_POPULAR_TAGS, QHash<QString, QString>());
}
void SituareService::fetchLocations()
return SituareService::RequestSendMessage;
else if (url.toString().contains(GET_PEOPLE_WITH_SIMILAR_INTEREST))
return SituareService::RequestGetPeopleWithSimilarInterest;
+ else if (url.toString().contains(GET_POPULAR_TAGS))
+ return SituareService::RequestGetPopularTags;
else
return SituareService::RequestUnknown;
}
emit updateWasSuccessful((SituareService::SuccessfulSendMessage));
else if (requestName == SituareService::RequestGetPeopleWithSimilarInterest)
parseInterestingPeopleData(resultData);
+ else if (requestName == SituareService::RequestGetPopularTags)
+ parsePopularTagsData(resultData);
}
}
}
emit messagesReceived(received, sent);
}
-void SituareService::parsePopularTagsData(const QByteArray &jsonReply)
+void SituareService::parsePopularTagsData(const QVariant &popularTagsData)
{
qDebug() << __PRETTY_FUNCTION__;
- QJson::Parser parser;
- bool ok;
-
- QVariantMap result = parser.parse(jsonReply, &ok).toMap();
-
- if (!ok) {
- emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
- return;
- } else {
- QHash<QString, QString> popularTags;
+ QVariantMap result = popularTagsData.toMap();
+ QHash<QString, QString> popularTags;
- foreach (QVariant tagVariant, result["popular_tags"].toList()) {
- QMap<QString, QVariant> tag = tagVariant.toMap();
- popularTags.insert(tag["id"].toString(), tag["name"].toString());
- }
-
- emit popularTagsReceived(popularTags);
+ foreach (QVariant tagVariant, result["popular_tags"].toList()) {
+ QMap<QString, QVariant> tag = tagVariant.toMap();
+ popularTags.insert(tag["tid"].toString(), tag["name"].toString());
}
+
+ emit popularTagsReceived(popularTags);
}
void SituareService::removeMessage(const QString &id)
RequestGetMessages,
RequestRemoveMessage,
RequestSendMessage,
- RequestGetPeopleWithSimilarInterest};
+ RequestGetPeopleWithSimilarInterest,
+ RequestGetPopularTags};
public:
/**
* @brief Parses popular tags data from JSON string
*
- * @param jsonReply JSON string
+ * @param popularTagsData popular tags data QVariant tree
*/
- void parsePopularTagsData(const QByteArray &jsonReply);
+ void parsePopularTagsData(const QVariant &popularTagsData);
/**
* @brief Parses reply from JSON string