+ result.append("{\"messages\": {");
+
+ //Received
+ QSqlQuery receivedQuery(QString("SELECT notification.id, notification.senderid, "
+ "notification.receiverid, user.name, user.image_url, "
+ "notification.timestamp, notification.text, "
+ "notification.latitude, notification.longitude "
+ "FROM notification, user WHERE notification.receiverid = '%1' AND "
+ "notification.senderid = user.id "
+ "ORDER BY notification.timestamp DESC")
+ .arg(userId));
+
+ result.append("\"received\": [");
+
+ while (receivedQuery.next()) {
+ result.append("{");
+ result.append("\"id\": \"" + receivedQuery.value(0).toString() + "\",");
+ result.append("\"sender_id\": \"" + receivedQuery.value(1).toString() + "\",");
+ result.append("\"receiver_id\": \"" + receivedQuery.value(2).toString() + "\",");
+ result.append("\"sender_name\": \"" + receivedQuery.value(3).toString() + "\",");
+ result.append("\"image_url\": \"" + receivedQuery.value(4).toString() + "\",");
+ result.append("\"timestamp\": \"" + receivedQuery.value(5).toString() + "\",");
+ result.append("\"text\": \"" + receivedQuery.value(6).toString() + "\",");
+ result.append("\"latitude\": \"" + receivedQuery.value(7).toString() + "\",");
+ result.append("\"longitude\": \"" + receivedQuery.value(8).toString() + "\"");
+ result.append("},");
+ }
+
+ int receivedLastComma = result.lastIndexOf(",");
+ if (receivedLastComma != -1)
+ result.remove(result.lastIndexOf(","), 1);
+
+ result.append("],");
+
+ //Sent
+ QSqlQuery sentQuery(QString("SELECT notification.id, notification.senderid, "
+ "notification.receiverid, user.name, user.image_url, "
+ "notification.timestamp, notification.text, "
+ "notification.latitude, notification.longitude "
+ "FROM notification, user WHERE notification.senderid = '%1' AND "
+ "notification.receiverid = user.id "
+ "ORDER BY notification.timestamp DESC")
+ .arg(userId));