1
0
mirror of https://gitlab.com/comunic/comunicterm synced 2024-11-16 10:31:06 +00:00

Get the list of conversations

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

View File

@ -14,7 +14,10 @@ SOURCES += \
helpers/accounthelper.cpp \ helpers/accounthelper.cpp \
helpers/userhelper.cpp \ helpers/userhelper.cpp \
entities/user.cpp \ entities/user.cpp \
mainmenu.cpp mainmenu.cpp \
conversations_screen.cpp \
helpers/conversationshelper.cpp \
entities/conversation.cpp
HEADERS += \ HEADERS += \
config.h \ config.h \
@ -25,4 +28,7 @@ HEADERS += \
helpers/accounthelper.h \ helpers/accounthelper.h \
helpers/userhelper.h \ helpers/userhelper.h \
entities/user.h \ entities/user.h \
mainmenu.h mainmenu.h \
conversations_screen.h \
helpers/conversationshelper.h \
entities/conversation.h

22
conversations_screen.cpp Normal file
View File

@ -0,0 +1,22 @@
#include <iostream>
#include "conversations_screen.h"
#include "helpers/conversationshelper.h"
#include "entities/conversation.h"
using namespace std;
void showConversationsScreen()
{
auto list = ConversationsHelper::GetList();
for(auto c : list)
cout << "Conv: " << c.name() << endl;
cout << "done" << endl;
string s;
cin >> s;
}

9
conversations_screen.h Normal file
View File

@ -0,0 +1,9 @@
/**
* Conversations screen
*
* @author Pierre HUBERT
*/
#pragma once
void showConversationsScreen();

76
entities/conversation.cpp Normal file
View File

@ -0,0 +1,76 @@
#include "conversation.h"
Conversation::Conversation()
{
}
int Conversation::iD() const
{
return mID;
}
void Conversation::setID(int iD)
{
mID = iD;
}
int Conversation::iD_Owner() const
{
return mID_Owner;
}
void Conversation::setID_Owner(int iD_Owner)
{
mID_Owner = iD_Owner;
}
int Conversation::lastActive() const
{
return mLastActive;
}
void Conversation::setLastActive(int lastActive)
{
mLastActive = lastActive;
}
std::string Conversation::name() const
{
return mName;
}
void Conversation::setName(const std::string &name)
{
mName = name;
}
bool Conversation::following() const
{
return mFollowing;
}
void Conversation::setFollowing(bool following)
{
mFollowing = following;
}
bool Conversation::sawLastMessage() const
{
return mSawLastMessage;
}
void Conversation::setSawLastMessage(bool sawLastMessage)
{
mSawLastMessage = sawLastMessage;
}
std::vector<int> Conversation::members() const
{
return mMembers;
}
void Conversation::setMembers(const std::vector<int> &members)
{
mMembers = members;
}

47
entities/conversation.h Normal file
View File

@ -0,0 +1,47 @@
/**
* Information about a conversation
*
* @author Pierre HUBERT
*/
#pragma once
#include <string>
#include <vector>
class Conversation
{
public:
Conversation();
int iD() const;
void setID(int iD);
int iD_Owner() const;
void setID_Owner(int iD_Owner);
int lastActive() const;
void setLastActive(int lastActive);
std::string name() const;
void setName(const std::string &name);
bool following() const;
void setFollowing(bool following);
bool sawLastMessage() const;
void setSawLastMessage(bool sawLastMessage);
std::vector<int> members() const;
void setMembers(const std::vector<int> &members);
private:
int mID;
int mID_Owner;
int mLastActive;
std::string mName;
bool mFollowing;
bool mSawLastMessage;
std::vector<int> mMembers;
};

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

View File

@ -10,6 +10,7 @@
#include "loginscreen.h" #include "loginscreen.h"
#include "mainmenu.h" #include "mainmenu.h"
#include "conversations_screen.h"
using namespace std; using namespace std;
@ -120,8 +121,7 @@ while(true) {
// Open user conversations // Open user conversations
if(o++ == action) { if(o++ == action) {
cerr << "TODO : implement conversations" << endl; showConversationsScreen();
exit(-1);
} }
// Logout // Logout