1
0
mirror of https://gitlab.com/comunic/comunicterm synced 2025-09-19 22:08:50 +00:00

Get the list of conversations

This commit is contained in:
2020-01-12 20:24:35 +01:00
parent 72e37b6242
commit 6a8a0d2c6d
8 changed files with 230 additions and 4 deletions

View 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;
}

View 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();
};