Changed Notification class to Message.
[situare] / src / situareservice / situareservice.cpp
index ebd6ec8..0b5bdac 100644 (file)
@@ -76,13 +76,14 @@ SituareService::~SituareService()
     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,
@@ -90,6 +91,7 @@ void SituareService::fetchPeopleWithSimilarInterest(const GeoCoordinate &southWe
 {
     qDebug() << __PRETTY_FUNCTION__;
 
+    //Request sent to server does not need the UID
     QByteArray arr = m_database->getInterestingPeople(m_user->userId().toULongLong(),
                                                       southWestCoordinates,
                                                       northEastCoordinates);
@@ -252,6 +254,13 @@ QString SituareService::formUrlParameters(const GeoCoordinate &coordinates, QStr
     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__;
@@ -351,7 +360,7 @@ void SituareService::parseInterestingPeopleData(const QByteArray &jsonReply)
     }
 }
 
-void SituareService::parseNotificationsData(const QByteArray &jsonReply)
+void SituareService::parseMessagesData(const QByteArray &jsonReply)
 {
     QJson::Parser parser;
     bool ok;
@@ -362,26 +371,26 @@ void SituareService::parseNotificationsData(const QByteArray &jsonReply)
         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);
     }
 }