mirror of
https://gitlab.com/comunic/comunicmessages
synced 2024-12-04 19:24:11 +00:00
Get information about the members of the conversations.
This commit is contained in:
parent
12f4e2ece1
commit
3d9748ad62
@ -18,7 +18,11 @@ SOURCES += \
|
|||||||
controllers/initcontroller.cpp \
|
controllers/initcontroller.cpp \
|
||||||
data/conversation.cpp \
|
data/conversation.cpp \
|
||||||
helpers/conversationslisthelper.cpp \
|
helpers/conversationslisthelper.cpp \
|
||||||
widgets/conversationslistwidget.cpp
|
widgets/conversationslistwidget.cpp \
|
||||||
|
widgets/conversationitemwidget.cpp \
|
||||||
|
data/user.cpp \
|
||||||
|
helpers/usershelper.cpp \
|
||||||
|
data/conversationslist.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
helpers/accounthelper.h \
|
helpers/accounthelper.h \
|
||||||
@ -38,9 +42,14 @@ HEADERS += \
|
|||||||
controllers/initcontroller.h \
|
controllers/initcontroller.h \
|
||||||
data/conversation.h \
|
data/conversation.h \
|
||||||
helpers/conversationslisthelper.h \
|
helpers/conversationslisthelper.h \
|
||||||
widgets/conversationslistwidget.h
|
widgets/conversationslistwidget.h \
|
||||||
|
widgets/conversationitemwidget.h \
|
||||||
|
data/user.h \
|
||||||
|
helpers/usershelper.h \
|
||||||
|
data/conversationslist.h
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
widgets/loginwidget.ui \
|
widgets/loginwidget.ui \
|
||||||
widgets/mainwindow.ui \
|
widgets/mainwindow.ui \
|
||||||
widgets/aboutthisappdialog.ui
|
widgets/aboutthisappdialog.ui \
|
||||||
|
widgets/conversationitemwidget.ui
|
||||||
|
2
config.h
2
config.h
@ -15,6 +15,8 @@
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* API credentials
|
* API credentials
|
||||||
|
*
|
||||||
|
* Note : only HTTPS should be used in production
|
||||||
*/
|
*/
|
||||||
#define API_URL "https://api.communiquons.org/"
|
#define API_URL "https://api.communiquons.org/"
|
||||||
#define API_SERVICE_NAME "ComunicAndroid"
|
#define API_SERVICE_NAME "ComunicAndroid"
|
||||||
|
17
data/conversationslist.cpp
Normal file
17
data/conversationslist.cpp
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
#include "conversationslist.h"
|
||||||
|
|
||||||
|
ConversationsList::ConversationsList()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
QList<int> ConversationsList::getAllMembersId() const
|
||||||
|
{
|
||||||
|
QList<int> members;
|
||||||
|
for(Conversation conv : *this){
|
||||||
|
for(int memberID : conv.members())
|
||||||
|
if(!members.contains(memberID))
|
||||||
|
members.append(memberID);
|
||||||
|
}
|
||||||
|
return members;
|
||||||
|
}
|
28
data/conversationslist.h
Normal file
28
data/conversationslist.h
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
/**
|
||||||
|
* Conversations list
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef CONVERSATIONSLIST_H
|
||||||
|
#define CONVERSATIONSLIST_H
|
||||||
|
|
||||||
|
#include <QList>
|
||||||
|
|
||||||
|
#include "conversation.h"
|
||||||
|
|
||||||
|
class ConversationsList : public QList<Conversation>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ConversationsList();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get and return the ID of all the members of
|
||||||
|
* the conversations
|
||||||
|
*
|
||||||
|
* @return The IDs of the conversations
|
||||||
|
*/
|
||||||
|
QList<int> getAllMembersId() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // CONVERSATIONSLIST_H
|
46
data/user.cpp
Normal file
46
data/user.cpp
Normal file
@ -0,0 +1,46 @@
|
|||||||
|
#include "user.h"
|
||||||
|
|
||||||
|
User::User()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
int User::iD() const
|
||||||
|
{
|
||||||
|
return mID;
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::setID(int iD)
|
||||||
|
{
|
||||||
|
mID = iD;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString User::firstName() const
|
||||||
|
{
|
||||||
|
return mFirstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::setFirstName(const QString &firstName)
|
||||||
|
{
|
||||||
|
mFirstName = firstName;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString User::lastName() const
|
||||||
|
{
|
||||||
|
return mLastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::setLastName(const QString &lastName)
|
||||||
|
{
|
||||||
|
mLastName = lastName;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString User::accountImage() const
|
||||||
|
{
|
||||||
|
return mAccountImage;
|
||||||
|
}
|
||||||
|
|
||||||
|
void User::setAccountImage(const QString &accountImage)
|
||||||
|
{
|
||||||
|
mAccountImage = accountImage;
|
||||||
|
}
|
36
data/user.h
Normal file
36
data/user.h
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
/**
|
||||||
|
* This object contains information about a single user
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#ifndef USER_H
|
||||||
|
#define USER_H
|
||||||
|
|
||||||
|
#include <QString>
|
||||||
|
|
||||||
|
class User
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
User();
|
||||||
|
|
||||||
|
int iD() const;
|
||||||
|
void setID(int iD);
|
||||||
|
|
||||||
|
QString firstName() const;
|
||||||
|
void setFirstName(const QString &firstName);
|
||||||
|
|
||||||
|
QString lastName() const;
|
||||||
|
void setLastName(const QString &lastName);
|
||||||
|
|
||||||
|
QString accountImage() const;
|
||||||
|
void setAccountImage(const QString &accountImage);
|
||||||
|
|
||||||
|
private:
|
||||||
|
int mID;
|
||||||
|
QString mFirstName;
|
||||||
|
QString mLastName;
|
||||||
|
QString mAccountImage;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USER_H
|
@ -4,6 +4,7 @@
|
|||||||
#include "conversationslisthelper.h"
|
#include "conversationslisthelper.h"
|
||||||
#include "apihelper.h"
|
#include "apihelper.h"
|
||||||
#include "../data/apirequest.h"
|
#include "../data/apirequest.h"
|
||||||
|
#include "../data/conversationslist.h"
|
||||||
|
|
||||||
ConversationsListHelper::ConversationsListHelper(QObject *parent) : QObject(parent)
|
ConversationsListHelper::ConversationsListHelper(QObject *parent) : QObject(parent)
|
||||||
{
|
{
|
||||||
@ -25,7 +26,7 @@ void ConversationsListHelper::getConvListCallback(int code, const QJsonDocument
|
|||||||
qobject_cast<APIRequest *>(sender())->deleteLater();
|
qobject_cast<APIRequest *>(sender())->deleteLater();
|
||||||
|
|
||||||
if(code != 200){
|
if(code != 200){
|
||||||
emit onGotList(false, QList<Conversation>());
|
emit onGotList(false, ConversationsList());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -33,7 +34,7 @@ void ConversationsListHelper::getConvListCallback(int code, const QJsonDocument
|
|||||||
QJsonArray arr = document.array();
|
QJsonArray arr = document.array();
|
||||||
|
|
||||||
//Process the list of conversations
|
//Process the list of conversations
|
||||||
QList<Conversation> list;
|
ConversationsList list;
|
||||||
for(int i = 0; i < arr.size(); i++)
|
for(int i = 0; i < arr.size(); i++)
|
||||||
list.append(GetConversationFromJson(arr.at(i).toObject()));
|
list.append(GetConversationFromJson(arr.at(i).toObject()));
|
||||||
|
|
||||||
@ -54,8 +55,9 @@ Conversation ConversationsListHelper::GetConversationFromJson(const QJsonObject
|
|||||||
//Process the list of members of the conversation
|
//Process the list of members of the conversation
|
||||||
QJsonArray members_arr = obj.value("members").toArray();
|
QJsonArray members_arr = obj.value("members").toArray();
|
||||||
QList<int> members_list;
|
QList<int> members_list;
|
||||||
for(int i = 0; i < members_arr.size(); i++)
|
for(int i = 0; i < members_arr.size(); i++){
|
||||||
members_list.append(members_arr.at(i).toInt());
|
members_list.append(members_arr.at(i).toString().toInt());
|
||||||
|
}
|
||||||
conv.setMembers(members_list);
|
conv.setMembers(members_list);
|
||||||
|
|
||||||
return conv;
|
return conv;
|
||||||
|
@ -13,9 +13,11 @@
|
|||||||
|
|
||||||
#include "../data/conversation.h"
|
#include "../data/conversation.h"
|
||||||
|
|
||||||
class APIHelper;
|
|
||||||
class QJsonObject;
|
class QJsonObject;
|
||||||
|
|
||||||
|
class APIHelper;
|
||||||
|
class ConversationsList;
|
||||||
|
|
||||||
class ConversationsListHelper : public QObject
|
class ConversationsListHelper : public QObject
|
||||||
{
|
{
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
@ -35,7 +37,7 @@ signals:
|
|||||||
* @param success TRUE for a success / FALSE else
|
* @param success TRUE for a success / FALSE else
|
||||||
* @param list The list of conversations
|
* @param list The list of conversations
|
||||||
*/
|
*/
|
||||||
void onGotList(bool success, const QList<Conversation> &list);
|
void onGotList(bool success, const ConversationsList &list);
|
||||||
|
|
||||||
public slots:
|
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
|
@ -1,5 +1,9 @@
|
|||||||
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "conversationslistwidget.h"
|
#include "conversationslistwidget.h"
|
||||||
#include "../helpers/conversationslisthelper.h"
|
#include "../helpers/conversationslisthelper.h"
|
||||||
|
#include "../helpers/usershelper.h"
|
||||||
|
#include "../data/conversationslist.h"
|
||||||
|
|
||||||
ConversationsListWidget::ConversationsListWidget(QWidget *parent) :
|
ConversationsListWidget::ConversationsListWidget(QWidget *parent) :
|
||||||
QWidget(parent)
|
QWidget(parent)
|
||||||
@ -7,6 +11,10 @@ ConversationsListWidget::ConversationsListWidget(QWidget *parent) :
|
|||||||
//Create conversations helper
|
//Create conversations helper
|
||||||
mConversationsList = new ConversationsListHelper(this);
|
mConversationsList = new ConversationsListHelper(this);
|
||||||
connect(mConversationsList, &ConversationsListHelper::onGotList, this, &ConversationsListWidget::onGotConversationsList);
|
connect(mConversationsList, &ConversationsListHelper::onGotList, this, &ConversationsListWidget::onGotConversationsList);
|
||||||
|
|
||||||
|
//Create users helper
|
||||||
|
mUsersHelper = new UsersHelper(this);
|
||||||
|
connect(mUsersHelper, &UsersHelper::onGotUsersInfo, this, &ConversationsListWidget::onGotUsersInfo);
|
||||||
}
|
}
|
||||||
|
|
||||||
ConversationsListWidget::~ConversationsListWidget()
|
ConversationsListWidget::~ConversationsListWidget()
|
||||||
@ -19,15 +27,26 @@ void ConversationsListWidget::refresh()
|
|||||||
mConversationsList->getList();
|
mConversationsList->getList();
|
||||||
}
|
}
|
||||||
|
|
||||||
void ConversationsListWidget::onGotConversationsList(bool success, const QList<Conversation> &list)
|
void ConversationsListWidget::onGotConversationsList(bool success, const ConversationsList &list)
|
||||||
{
|
{
|
||||||
qWarning("Got conversations list (or failure).");
|
qWarning("Got conversations list callback.");
|
||||||
|
|
||||||
if(!success)
|
if(!success){
|
||||||
qWarning("Failure.");
|
QMessageBox::warning(this, tr("Error"), tr("Could not get the list of conversations!"));
|
||||||
else {
|
return;
|
||||||
for(Conversation conv : list){
|
|
||||||
qWarning("Conv %d : %s", conv.iD(), conv.name().toStdString().c_str());
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Get the list of users
|
||||||
|
mUsersHelper->getList(list.getAllMembersId());
|
||||||
|
}
|
||||||
|
|
||||||
|
void ConversationsListWidget::onGotUsersInfo(bool success, const QList<User> &users)
|
||||||
|
{
|
||||||
|
if(!success){
|
||||||
|
QMessageBox::warning(this, tr("Error"), tr("Could not get information about the members of the conversations!"));
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
qDebug("Got the list of members of the conversations.");
|
||||||
|
//TODO : use ConversationItemWidget
|
||||||
}
|
}
|
||||||
|
@ -3,9 +3,11 @@
|
|||||||
|
|
||||||
#include <QWidget>
|
#include <QWidget>
|
||||||
|
|
||||||
#include "../data/conversation.h"
|
#include "../data/conversationslist.h"
|
||||||
|
#include "../data/user.h"
|
||||||
|
|
||||||
class ConversationsListHelper;
|
class ConversationsListHelper;
|
||||||
|
class UsersHelper;
|
||||||
|
|
||||||
class ConversationsListWidget : public QWidget
|
class ConversationsListWidget : public QWidget
|
||||||
{
|
{
|
||||||
@ -28,10 +30,22 @@ private slots:
|
|||||||
* @param success TRUE for a success / FALSE else
|
* @param success TRUE for a success / FALSE else
|
||||||
* @param list The list of conversation (empty list in case of failure)
|
* @param list The list of conversation (empty list in case of failure)
|
||||||
*/
|
*/
|
||||||
void onGotConversationsList(bool success, const QList<Conversation> &list);
|
void onGotConversationsList(bool success, const ConversationsList &list);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This slot is triggered once we have information about the users
|
||||||
|
*
|
||||||
|
* @param success TRUE in case of success / FALSE else
|
||||||
|
* @param users The list of suers (empty list in case of failure)
|
||||||
|
*/
|
||||||
|
void onGotUsersInfo(bool success, const QList<User> &users);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ConversationsListHelper *mConversationsList;
|
ConversationsListHelper *mConversationsList;
|
||||||
|
UsersHelper *mUsersHelper;
|
||||||
|
|
||||||
|
//Current conversation in cache
|
||||||
|
ConversationsList mCurrList;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // CONVERSATIONSLISTWIDGET_H
|
#endif // CONVERSATIONSLISTWIDGET_H
|
||||||
|
Loading…
Reference in New Issue
Block a user