mirror of
				https://gitlab.com/comunic/comunicmessages
				synced 2025-11-04 12:14:05 +00:00 
			
		
		
		
	Display the list of conversations.
This commit is contained in:
		@@ -3,6 +3,7 @@
 | 
			
		||||
 | 
			
		||||
#include "conversationslisthelper.h"
 | 
			
		||||
#include "apihelper.h"
 | 
			
		||||
#include "accounthelper.h"
 | 
			
		||||
#include "../data/apirequest.h"
 | 
			
		||||
#include "../data/conversationslist.h"
 | 
			
		||||
 | 
			
		||||
@@ -20,6 +21,31 @@ void ConversationsListHelper::getList()
 | 
			
		||||
    mAPIHelper->execute(request);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
QString ConversationsListHelper::getConversationDisplayName(const Conversation &conv, const UsersList &usersInfo)
 | 
			
		||||
{
 | 
			
		||||
    //Check if the conversation has already a name
 | 
			
		||||
    if(conv.name().length() > 0)
 | 
			
		||||
        return conv.name();
 | 
			
		||||
 | 
			
		||||
    QString name;
 | 
			
		||||
 | 
			
		||||
    int i = 0;
 | 
			
		||||
    for(int j = 0; j < conv.members().length() && i < 3; j++){
 | 
			
		||||
 | 
			
		||||
        //We bypass the current user name
 | 
			
		||||
        if(conv.members().at(j) == AccountHelper::getUserID())
 | 
			
		||||
            continue;
 | 
			
		||||
 | 
			
		||||
        if(name.length() > 0)
 | 
			
		||||
            name += ", ";
 | 
			
		||||
        name += usersInfo.get(conv.members().at(j)).displayName();
 | 
			
		||||
 | 
			
		||||
        i++;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return name;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void ConversationsListHelper::getConvListCallback(int code, const QJsonDocument &document)
 | 
			
		||||
{
 | 
			
		||||
    //Delete the request
 | 
			
		||||
@@ -49,8 +75,8 @@ Conversation ConversationsListHelper::GetConversationFromJson(const QJsonObject
 | 
			
		||||
    conv.setIDowner(obj.value("ID_owner").toInt());
 | 
			
		||||
    conv.setLastActive(obj.value("last_active").toInt());
 | 
			
		||||
    conv.setName(obj.value("name").toString());
 | 
			
		||||
    conv.setFollowing(obj.value("following").toBool());
 | 
			
		||||
    conv.setSawLastMessage(obj.value("saw_last_message").toBool());
 | 
			
		||||
    conv.setFollowing(obj.value("following").toInt() == 1);
 | 
			
		||||
    conv.setSawLastMessage(obj.value("saw_last_message").toInt() == 1);
 | 
			
		||||
 | 
			
		||||
    //Process the list of members of the conversation
 | 
			
		||||
    QJsonArray members_arr = obj.value("members").toArray();
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@
 | 
			
		||||
#include <QObject>
 | 
			
		||||
 | 
			
		||||
#include "../data/conversation.h"
 | 
			
		||||
#include "../data/userslist.h"
 | 
			
		||||
 | 
			
		||||
class QJsonObject;
 | 
			
		||||
 | 
			
		||||
@@ -29,6 +30,15 @@ public:
 | 
			
		||||
     */
 | 
			
		||||
    void getList();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get and return the display name of a conversation
 | 
			
		||||
     *
 | 
			
		||||
     * @param conv Information about the target conversation
 | 
			
		||||
     * @param usersInfo Information about related users
 | 
			
		||||
     * @return The name of the conversation
 | 
			
		||||
     */
 | 
			
		||||
    static QString getConversationDisplayName(const Conversation &conv, const UsersList &usersInfo);
 | 
			
		||||
 | 
			
		||||
signals:
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
 
 | 
			
		||||
@@ -31,12 +31,12 @@ void UsersHelper::getUsersInformationFinished(int code, const QJsonDocument &doc
 | 
			
		||||
 | 
			
		||||
    //Check for error
 | 
			
		||||
    if(code != 200){
 | 
			
		||||
        emit onGotUsersInfo(false, QList<User>());
 | 
			
		||||
        emit onGotUsersInfo(false, UsersList());
 | 
			
		||||
        return;
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    //Parse the list of object
 | 
			
		||||
    QList<User> list;
 | 
			
		||||
    UsersList list;
 | 
			
		||||
    QJsonObject obj = document.object();
 | 
			
		||||
    for(QString id : obj.keys())
 | 
			
		||||
        list.append(ParseJSONToUser(obj.value(id).toObject()));
 | 
			
		||||
 
 | 
			
		||||
@@ -12,6 +12,7 @@
 | 
			
		||||
#include <QObject>
 | 
			
		||||
 | 
			
		||||
#include "../data/user.h"
 | 
			
		||||
#include "../data/userslist.h"
 | 
			
		||||
 | 
			
		||||
class QJsonObject;
 | 
			
		||||
 | 
			
		||||
@@ -38,7 +39,7 @@ signals:
 | 
			
		||||
     * @param success TRUE for a success / FALSE else
 | 
			
		||||
     * @param list Information about the users
 | 
			
		||||
     */
 | 
			
		||||
    void onGotUsersInfo(bool success, const QList<User> &list);
 | 
			
		||||
    void onGotUsersInfo(bool success, const UsersList &list);
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user