mirror of
				https://gitlab.com/comunic/comunicterm
				synced 2025-11-04 12:14:04 +00:00 
			
		
		
		
	Get the list of conversations
This commit is contained in:
		
							
								
								
									
										44
									
								
								helpers/conversationshelper.cpp
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										44
									
								
								helpers/conversationshelper.cpp
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,44 @@
 | 
			
		||||
#include <string>
 | 
			
		||||
 | 
			
		||||
#include "conversationshelper.h"
 | 
			
		||||
#include "../api_request.h"
 | 
			
		||||
#include "../entities/conversation.h"
 | 
			
		||||
 | 
			
		||||
using namespace std;
 | 
			
		||||
 | 
			
		||||
ConversationsHelper::ConversationsHelper()
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
vector<Conversation> ConversationsHelper::GetList()
 | 
			
		||||
{
 | 
			
		||||
    const auto response = ApiRequest("conversations/getList").exec();
 | 
			
		||||
 | 
			
		||||
    if(response.code() != 200)
 | 
			
		||||
        throw runtime_error("Get conversations list failed! (code: " + to_string(response.code()));
 | 
			
		||||
 | 
			
		||||
    vector<Conversation> list;
 | 
			
		||||
 | 
			
		||||
    for(auto el : response.array()) {
 | 
			
		||||
        auto obj = el.as_object();
 | 
			
		||||
 | 
			
		||||
        Conversation conv;
 | 
			
		||||
        conv.setID(el["ID"].as_integer());
 | 
			
		||||
        conv.setID_Owner(el["ID_owner"].as_integer());
 | 
			
		||||
        conv.setLastActive(el["last_active"].as_integer());
 | 
			
		||||
        conv.setName(el["name"].is_boolean() ? "" : el["name"].as_string());
 | 
			
		||||
        conv.setFollowing(el["following"].as_integer() == 1);
 | 
			
		||||
        conv.setSawLastMessage(el["saw_last_message"].as_integer() == 1);
 | 
			
		||||
 | 
			
		||||
        vector<int> members;
 | 
			
		||||
        for(auto m : el["members"].as_array())
 | 
			
		||||
            members.push_back(stoi(m.as_string()));
 | 
			
		||||
        conv.setMembers(members);
 | 
			
		||||
 | 
			
		||||
        list.push_back(conv);
 | 
			
		||||
 | 
			
		||||
    }
 | 
			
		||||
 | 
			
		||||
    return list;
 | 
			
		||||
}
 | 
			
		||||
							
								
								
									
										22
									
								
								helpers/conversationshelper.h
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										22
									
								
								helpers/conversationshelper.h
									
									
									
									
									
										Normal file
									
								
							@@ -0,0 +1,22 @@
 | 
			
		||||
/**
 | 
			
		||||
 * Conversations helper
 | 
			
		||||
 *
 | 
			
		||||
 * @author Pierre HUBERT
 | 
			
		||||
 */
 | 
			
		||||
 | 
			
		||||
#pragma once
 | 
			
		||||
 | 
			
		||||
#include <vector>
 | 
			
		||||
 | 
			
		||||
class Conversation;
 | 
			
		||||
 | 
			
		||||
class ConversationsHelper
 | 
			
		||||
{
 | 
			
		||||
public:
 | 
			
		||||
    ConversationsHelper();
 | 
			
		||||
 | 
			
		||||
    /**
 | 
			
		||||
     * Get the list of conversations of the current user
 | 
			
		||||
     */
 | 
			
		||||
    static std::vector<Conversation> GetList();
 | 
			
		||||
};
 | 
			
		||||
		Reference in New Issue
	
	Block a user