mirror of
https://gitlab.com/comunic/comunicterm
synced 2024-12-25 04:58:56 +00:00
Get the list of conversations
This commit is contained in:
parent
72e37b6242
commit
6a8a0d2c6d
@ -14,7 +14,10 @@ SOURCES += \
|
||||
helpers/accounthelper.cpp \
|
||||
helpers/userhelper.cpp \
|
||||
entities/user.cpp \
|
||||
mainmenu.cpp
|
||||
mainmenu.cpp \
|
||||
conversations_screen.cpp \
|
||||
helpers/conversationshelper.cpp \
|
||||
entities/conversation.cpp
|
||||
|
||||
HEADERS += \
|
||||
config.h \
|
||||
@ -25,4 +28,7 @@ HEADERS += \
|
||||
helpers/accounthelper.h \
|
||||
helpers/userhelper.h \
|
||||
entities/user.h \
|
||||
mainmenu.h
|
||||
mainmenu.h \
|
||||
conversations_screen.h \
|
||||
helpers/conversationshelper.h \
|
||||
entities/conversation.h
|
||||
|
22
conversations_screen.cpp
Normal file
22
conversations_screen.cpp
Normal 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
9
conversations_screen.h
Normal file
@ -0,0 +1,9 @@
|
||||
/**
|
||||
* Conversations screen
|
||||
*
|
||||
* @author Pierre HUBERT
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
void showConversationsScreen();
|
76
entities/conversation.cpp
Normal file
76
entities/conversation.cpp
Normal 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
47
entities/conversation.h
Normal 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;
|
||||
};
|
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();
|
||||
};
|
@ -10,6 +10,7 @@
|
||||
|
||||
#include "loginscreen.h"
|
||||
#include "mainmenu.h"
|
||||
#include "conversations_screen.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
@ -120,8 +121,7 @@ while(true) {
|
||||
|
||||
// Open user conversations
|
||||
if(o++ == action) {
|
||||
cerr << "TODO : implement conversations" << endl;
|
||||
exit(-1);
|
||||
showConversationsScreen();
|
||||
}
|
||||
|
||||
// Logout
|
||||
|
Loading…
Reference in New Issue
Block a user