return result.toUtf8();
}
-QList<Notification*> &Database::getNotifications(qulonglong userId)
+QByteArray Database::getNotifications(qulonglong userId)
{
qDebug() << __PRETTY_FUNCTION__;
- m_notifications.clear();
+ QSqlQuery query(QString("SELECT notification.id, notification.senderid, user.name, "
+ "user.image_url, notification.timestamp, notification.text "
+ "FROM notification, user WHERE notification.receiverid = '%1' "
+ "AND notification.senderid = user.id").arg(userId));
- QSqlQuery query(QString("SELECT message.id, message.senderid, user.name, message.text FROM "
- "message, user WHERE message.receiverid = '%1' AND "
- "message.senderid = user.id").arg(userId));
+ QString result;
+ result.append("{\"notifications\": [");
while (query.next()) {
- Notification *notification = new Notification();
- notification->setId(query.value(0).toString());
- notification->setSenderId(query.value(1).toString());
- notification->setTitle(query.value(2).toString());
- notification->setText(query.value(3).toString());
- m_notifications.append(notification);
+ result.append("{");
+ result.append("\"id\": \"" + query.value(0).toString() + "\",");
+ result.append("\"sender_id\": \"" + query.value(1).toString() + "\",");
+ result.append("\"sender_name\": \"" + query.value(2).toString() + "\",");
+ result.append("\"image_url\": \"" + query.value(3).toString() + "\",");
+ result.append("\"timestamp\": \"" + query.value(4).toString() + "\",");
+ result.append("\"text\": \"" + query.value(5).toString() + "\"");
+ result.append("},");
}
- return m_notifications;
+ int lastComma = result.lastIndexOf(",");
+ if (lastComma != -1)
+ result.remove(result.lastIndexOf(","), 1);
+
+ result.append("]}");
+ qWarning() << result;
+ return result.toUtf8();
}
QStringList Database::getTags(qulonglong userId)