m_friendsList.clear();
}
-void SituareService::fetchNotifications()
+void SituareService::fetchMessages()
{
qDebug() << __PRETTY_FUNCTION__;
+ //Request sent to server does not need the UID
QByteArray arr = m_database->getNotifications(m_user->userId().toULongLong());
- parseNotificationsData(arr);
+ parseMessagesData(arr);
}
void SituareService::fetchPeopleWithSimilarInterest(const GeoCoordinate &southWestCoordinates,
{
qDebug() << __PRETTY_FUNCTION__;
+ //Request sent to server does not need the UID
QByteArray arr = m_database->getInterestingPeople(m_user->userId().toULongLong(),
southWestCoordinates,
northEastCoordinates);
return parameters;
}
+void SituareService::sendMessage(const QString &receiverId, const QString &message)
+{
+ qDebug() << __PRETTY_FUNCTION__;
+
+ qWarning() << __PRETTY_FUNCTION__ << m_database->sendMessage(m_user->userId().toULongLong(), receiverId.toULongLong(), message);
+}
+
void SituareService::sendRequest(const QUrl &url, const QString &cookieType, const QString &cookie)
{
qDebug() << __PRETTY_FUNCTION__;
}
}
-void SituareService::parseNotificationsData(const QByteArray &jsonReply)
+void SituareService::parseMessagesData(const QByteArray &jsonReply)
{
QJson::Parser parser;
bool ok;
emit error(ErrorContext::SITUARE, SituareError::INVALID_JSON);
return;
} else {
- QList<Notification> notifications;
-
- foreach (QVariant notificationVariant, result["notifications"].toList()) {
- Notification notification;
- QMap<QString, QVariant> notificationMap = notificationVariant.toMap();
- notification.setId(notificationMap["id"].toString());
- notification.setSenderId(notificationMap["sender_id"].toString());
- notification.setSenderName(notificationMap["sender_name"].toString());
- uint timestampSeconds = notificationMap["timestamp"].toUInt();
- notification.setTimestamp(QDateTime::fromTime_t(timestampSeconds));
- notification.setText(notificationMap["text"].toString());
- notification.setImage(AvatarImage::create(
+ QList<Message> messages;
+
+ foreach (QVariant messageVariant, result["messages"].toList()) {
+ Message message;
+ QMap<QString, QVariant> messageMap = messageVariant.toMap();
+ message.setId(messageMap["id"].toString());
+ message.setSenderId(messageMap["sender_id"].toString());
+ message.setSenderName(messageMap["sender_name"].toString());
+ uint timestampSeconds = messageMap["timestamp"].toUInt();
+ message.setTimestamp(QDateTime::fromTime_t(timestampSeconds));
+ message.setText(messageMap["text"].toString());
+ message.setImage(AvatarImage::create(
QPixmap(":/res/images/empty_avatar.png"), AvatarImage::Small));
- notifications.append(notification);
+ messages.append(message);
- emit fetchImage(notification.id(), notificationMap["image_url"].toString());
+ emit fetchImage(message.id(), messageMap["image_url"].toString());
}
- emit notificationsReceived(notifications);
+ emit messagesReceived(messages);
}
}