mirror of
https://gitlab.com/comunic/comunicmessages
synced 2025-06-20 08:55:17 +00:00
Get information about the members of the conversations.
This commit is contained in:
@ -4,6 +4,7 @@
|
||||
#include "conversationslisthelper.h"
|
||||
#include "apihelper.h"
|
||||
#include "../data/apirequest.h"
|
||||
#include "../data/conversationslist.h"
|
||||
|
||||
ConversationsListHelper::ConversationsListHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
@ -25,7 +26,7 @@ void ConversationsListHelper::getConvListCallback(int code, const QJsonDocument
|
||||
qobject_cast<APIRequest *>(sender())->deleteLater();
|
||||
|
||||
if(code != 200){
|
||||
emit onGotList(false, QList<Conversation>());
|
||||
emit onGotList(false, ConversationsList());
|
||||
return;
|
||||
}
|
||||
|
||||
@ -33,7 +34,7 @@ void ConversationsListHelper::getConvListCallback(int code, const QJsonDocument
|
||||
QJsonArray arr = document.array();
|
||||
|
||||
//Process the list of conversations
|
||||
QList<Conversation> list;
|
||||
ConversationsList list;
|
||||
for(int i = 0; i < arr.size(); i++)
|
||||
list.append(GetConversationFromJson(arr.at(i).toObject()));
|
||||
|
||||
@ -54,8 +55,9 @@ Conversation ConversationsListHelper::GetConversationFromJson(const QJsonObject
|
||||
//Process the list of members of the conversation
|
||||
QJsonArray members_arr = obj.value("members").toArray();
|
||||
QList<int> members_list;
|
||||
for(int i = 0; i < members_arr.size(); i++)
|
||||
members_list.append(members_arr.at(i).toInt());
|
||||
for(int i = 0; i < members_arr.size(); i++){
|
||||
members_list.append(members_arr.at(i).toString().toInt());
|
||||
}
|
||||
conv.setMembers(members_list);
|
||||
|
||||
return conv;
|
||||
|
@ -13,9 +13,11 @@
|
||||
|
||||
#include "../data/conversation.h"
|
||||
|
||||
class APIHelper;
|
||||
class QJsonObject;
|
||||
|
||||
class APIHelper;
|
||||
class ConversationsList;
|
||||
|
||||
class ConversationsListHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
@ -35,7 +37,7 @@ signals:
|
||||
* @param success TRUE for a success / FALSE else
|
||||
* @param list The list of conversations
|
||||
*/
|
||||
void onGotList(bool success, const QList<Conversation> &list);
|
||||
void onGotList(bool success, const ConversationsList &list);
|
||||
|
||||
public slots:
|
||||
|
||||
|
55
helpers/usershelper.cpp
Normal file
55
helpers/usershelper.cpp
Normal file
@ -0,0 +1,55 @@
|
||||
#include <QJsonObject>
|
||||
|
||||
#include "usershelper.h"
|
||||
#include "apihelper.h"
|
||||
|
||||
UsersHelper::UsersHelper(QObject *parent) : QObject(parent)
|
||||
{
|
||||
mAPIHelper = new APIHelper(this);
|
||||
}
|
||||
|
||||
void UsersHelper::getList(QList<int> ids)
|
||||
{
|
||||
APIRequest *request = new APIRequest(this);
|
||||
request->setURI("user/getInfosMultiple");
|
||||
|
||||
QString ids_str;
|
||||
for(int id : ids)
|
||||
ids_str += QString::number(id) + ",";
|
||||
|
||||
request->addString("usersID", ids_str);
|
||||
mAPIHelper->execute(request);
|
||||
|
||||
//Make connection
|
||||
connect(request, &APIRequest::finished, this, &UsersHelper::getUsersInformationFinished);
|
||||
}
|
||||
|
||||
void UsersHelper::getUsersInformationFinished(int code, const QJsonDocument &document)
|
||||
{
|
||||
//Delete the request
|
||||
qobject_cast<APIRequest *>(sender())->deleteLater();
|
||||
|
||||
//Check for error
|
||||
if(code != 200){
|
||||
emit onGotUsersInfo(false, QList<User>());
|
||||
return;
|
||||
}
|
||||
|
||||
//Parse the list of object
|
||||
QList<User> list;
|
||||
QJsonObject obj = document.object();
|
||||
for(QString id : obj.keys())
|
||||
list.append(ParseJSONToUser(obj.value(id).toObject()));
|
||||
|
||||
emit onGotUsersInfo(true, list);
|
||||
}
|
||||
|
||||
User UsersHelper::ParseJSONToUser(const QJsonObject &obj)
|
||||
{
|
||||
User user;
|
||||
user.setID(obj.value("userID").toInt());
|
||||
user.setFirstName(obj.value("firstName").toString());
|
||||
user.setLastName(obj.value("lastName").toString());
|
||||
user.setAccountImage(obj.value("accountImage").toString());
|
||||
return user;
|
||||
}
|
69
helpers/usershelper.h
Normal file
69
helpers/usershelper.h
Normal file
@ -0,0 +1,69 @@
|
||||
/**
|
||||
* Users helper
|
||||
*
|
||||
* It is used to get information about users
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
#ifndef USERSHELPER_H
|
||||
#define USERSHELPER_H
|
||||
|
||||
#include <QObject>
|
||||
|
||||
#include "../data/user.h"
|
||||
|
||||
class QJsonObject;
|
||||
|
||||
class APIHelper;
|
||||
|
||||
class UsersHelper : public QObject
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
explicit UsersHelper(QObject *parent = nullptr);
|
||||
|
||||
/**
|
||||
* Query information about a list of users
|
||||
*
|
||||
* @param ids The ID of the users to get
|
||||
*/
|
||||
void getList(QList<int> ids);
|
||||
|
||||
signals:
|
||||
|
||||
/**
|
||||
* Signal emitted when we have got new users information
|
||||
*
|
||||
* @param success TRUE for a success / FALSE else
|
||||
* @param list Information about the users
|
||||
*/
|
||||
void onGotUsersInfo(bool success, const QList<User> &list);
|
||||
|
||||
public slots:
|
||||
|
||||
private slots:
|
||||
|
||||
/**
|
||||
* Slot called once the API request to get users information has been finished
|
||||
*
|
||||
* @param code Result code of the operation (200 for a success)
|
||||
* @param document Document
|
||||
*/
|
||||
void getUsersInformationFinished(int code, const QJsonDocument &document);
|
||||
|
||||
private:
|
||||
|
||||
/**
|
||||
* Turn a JSON object into a User object
|
||||
*
|
||||
* @param obj The object to convert
|
||||
* @return Generated user object
|
||||
*/
|
||||
User ParseJSONToUser(const QJsonObject &obj);
|
||||
|
||||
//Private fields
|
||||
APIHelper *mAPIHelper;
|
||||
};
|
||||
|
||||
#endif // USERSHELPER_H
|
Reference in New Issue
Block a user