mirror of
https://gitlab.com/comunic/comunicterm
synced 2024-12-26 05:28:54 +00:00
Can process & return the real name of conversations
This commit is contained in:
parent
6a8a0d2c6d
commit
14d960713c
@ -17,7 +17,8 @@ SOURCES += \
|
|||||||
mainmenu.cpp \
|
mainmenu.cpp \
|
||||||
conversations_screen.cpp \
|
conversations_screen.cpp \
|
||||||
helpers/conversationshelper.cpp \
|
helpers/conversationshelper.cpp \
|
||||||
entities/conversation.cpp
|
entities/conversation.cpp \
|
||||||
|
entities/conversationslist.cpp
|
||||||
|
|
||||||
HEADERS += \
|
HEADERS += \
|
||||||
config.h \
|
config.h \
|
||||||
@ -31,4 +32,5 @@ HEADERS += \
|
|||||||
mainmenu.h \
|
mainmenu.h \
|
||||||
conversations_screen.h \
|
conversations_screen.h \
|
||||||
helpers/conversationshelper.h \
|
helpers/conversationshelper.h \
|
||||||
entities/conversation.h
|
entities/conversation.h \
|
||||||
|
entities/conversationslist.h
|
||||||
|
@ -1,8 +1,10 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
|
#include "helpers/userhelper.h"
|
||||||
#include "conversations_screen.h"
|
#include "conversations_screen.h"
|
||||||
#include "helpers/conversationshelper.h"
|
#include "helpers/conversationshelper.h"
|
||||||
#include "entities/conversation.h"
|
#include "entities/conversation.h"
|
||||||
|
#include "entities/conversationslist.h"
|
||||||
|
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
@ -10,10 +12,12 @@ using namespace std;
|
|||||||
|
|
||||||
void showConversationsScreen()
|
void showConversationsScreen()
|
||||||
{
|
{
|
||||||
|
|
||||||
auto list = ConversationsHelper::GetList();
|
auto list = ConversationsHelper::GetList();
|
||||||
|
auto users = UserHelper::getMultiple(list.usersList());
|
||||||
|
|
||||||
for(auto c : list)
|
for(auto c : list)
|
||||||
cout << "Conv: " << c.name() << endl;
|
cout << "Conv: " << c.name(users) << endl;
|
||||||
|
|
||||||
|
|
||||||
cout << "done" << endl;
|
cout << "done" << endl;
|
||||||
|
@ -1,5 +1,11 @@
|
|||||||
|
#include <iostream>
|
||||||
|
|
||||||
#include "conversation.h"
|
#include "conversation.h"
|
||||||
|
|
||||||
|
#include "../helpers/accounthelper.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
Conversation::Conversation()
|
Conversation::Conversation()
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -35,6 +41,34 @@ void Conversation::setLastActive(int lastActive)
|
|||||||
mLastActive = lastActive;
|
mLastActive = lastActive;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string Conversation::name(UsersList users)
|
||||||
|
{
|
||||||
|
if(hasName())
|
||||||
|
return mName;
|
||||||
|
|
||||||
|
if(mComputedName.size() == 0) {
|
||||||
|
size_t i = 0;
|
||||||
|
for(size_t j = 0; i < 3 && j < mMembers.size(); j++) {
|
||||||
|
auto userID = mMembers[j];
|
||||||
|
|
||||||
|
if(userID == AccountHelper::userID())
|
||||||
|
continue;
|
||||||
|
|
||||||
|
if(mComputedName.length() > 0)
|
||||||
|
mComputedName += ", ";
|
||||||
|
|
||||||
|
mComputedName += users[userID].fullName();
|
||||||
|
i++;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if(i < mMembers.size() - 2)
|
||||||
|
mComputedName += ", ...";
|
||||||
|
}
|
||||||
|
|
||||||
|
return mComputedName;
|
||||||
|
}
|
||||||
|
|
||||||
std::string Conversation::name() const
|
std::string Conversation::name() const
|
||||||
{
|
{
|
||||||
return mName;
|
return mName;
|
||||||
@ -45,6 +79,11 @@ void Conversation::setName(const std::string &name)
|
|||||||
mName = name;
|
mName = name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Conversation::hasName() const
|
||||||
|
{
|
||||||
|
return mName.size() > 0;
|
||||||
|
}
|
||||||
|
|
||||||
bool Conversation::following() const
|
bool Conversation::following() const
|
||||||
{
|
{
|
||||||
return mFollowing;
|
return mFollowing;
|
||||||
|
@ -10,6 +10,8 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
|
#include "user.h"
|
||||||
|
|
||||||
class Conversation
|
class Conversation
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@ -24,8 +26,10 @@ public:
|
|||||||
int lastActive() const;
|
int lastActive() const;
|
||||||
void setLastActive(int lastActive);
|
void setLastActive(int lastActive);
|
||||||
|
|
||||||
|
std::string name(UsersList users);
|
||||||
std::string name() const;
|
std::string name() const;
|
||||||
void setName(const std::string &name);
|
void setName(const std::string &name);
|
||||||
|
bool hasName() const;
|
||||||
|
|
||||||
bool following() const;
|
bool following() const;
|
||||||
void setFollowing(bool following);
|
void setFollowing(bool following);
|
||||||
@ -41,6 +45,7 @@ private:
|
|||||||
int mID_Owner;
|
int mID_Owner;
|
||||||
int mLastActive;
|
int mLastActive;
|
||||||
std::string mName;
|
std::string mName;
|
||||||
|
std::string mComputedName = "";
|
||||||
bool mFollowing;
|
bool mFollowing;
|
||||||
bool mSawLastMessage;
|
bool mSawLastMessage;
|
||||||
std::vector<int> mMembers;
|
std::vector<int> mMembers;
|
||||||
|
22
entities/conversationslist.cpp
Normal file
22
entities/conversationslist.cpp
Normal file
@ -0,0 +1,22 @@
|
|||||||
|
#include "conversationslist.h"
|
||||||
|
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
|
ConversationsList::ConversationsList()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
set<int> ConversationsList::usersList() const
|
||||||
|
{
|
||||||
|
set<int> list;
|
||||||
|
|
||||||
|
for(auto conv : *this) {
|
||||||
|
list.insert(conv.iD_Owner());
|
||||||
|
|
||||||
|
for(auto m : conv.members())
|
||||||
|
list.insert(m);
|
||||||
|
}
|
||||||
|
|
||||||
|
return list;
|
||||||
|
}
|
20
entities/conversationslist.h
Normal file
20
entities/conversationslist.h
Normal file
@ -0,0 +1,20 @@
|
|||||||
|
/**
|
||||||
|
* List of conversations
|
||||||
|
*
|
||||||
|
* @author Pierre HUBERT
|
||||||
|
*/
|
||||||
|
|
||||||
|
#pragma once
|
||||||
|
|
||||||
|
#include <set>
|
||||||
|
|
||||||
|
#include "conversation.h"
|
||||||
|
|
||||||
|
|
||||||
|
class ConversationsList : public std::vector<Conversation>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
ConversationsList();
|
||||||
|
|
||||||
|
std::set<int> usersList() const;
|
||||||
|
};
|
@ -7,7 +7,7 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
#include <string>
|
#include <string>
|
||||||
|
#include <map>
|
||||||
|
|
||||||
class User
|
class User
|
||||||
{
|
{
|
||||||
@ -31,3 +31,5 @@ private:
|
|||||||
std::string mFirstName;
|
std::string mFirstName;
|
||||||
std::string mLastName;
|
std::string mLastName;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
typedef std::map<int, User> UsersList;
|
||||||
|
@ -3,6 +3,7 @@
|
|||||||
#include "conversationshelper.h"
|
#include "conversationshelper.h"
|
||||||
#include "../api_request.h"
|
#include "../api_request.h"
|
||||||
#include "../entities/conversation.h"
|
#include "../entities/conversation.h"
|
||||||
|
#include "../entities/conversationslist.h"
|
||||||
|
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
@ -11,14 +12,14 @@ ConversationsHelper::ConversationsHelper()
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
vector<Conversation> ConversationsHelper::GetList()
|
ConversationsList ConversationsHelper::GetList()
|
||||||
{
|
{
|
||||||
const auto response = ApiRequest("conversations/getList").exec();
|
const auto response = ApiRequest("conversations/getList").exec();
|
||||||
|
|
||||||
if(response.code() != 200)
|
if(response.code() != 200)
|
||||||
throw runtime_error("Get conversations list failed! (code: " + to_string(response.code()));
|
throw runtime_error("Get conversations list failed! (code: " + to_string(response.code()));
|
||||||
|
|
||||||
vector<Conversation> list;
|
ConversationsList list;
|
||||||
|
|
||||||
for(auto el : response.array()) {
|
for(auto el : response.array()) {
|
||||||
auto obj = el.as_object();
|
auto obj = el.as_object();
|
||||||
|
@ -9,6 +9,7 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
class Conversation;
|
class Conversation;
|
||||||
|
class ConversationsList;
|
||||||
|
|
||||||
class ConversationsHelper
|
class ConversationsHelper
|
||||||
{
|
{
|
||||||
@ -18,5 +19,5 @@ public:
|
|||||||
/**
|
/**
|
||||||
* Get the list of conversations of the current user
|
* Get the list of conversations of the current user
|
||||||
*/
|
*/
|
||||||
static std::vector<Conversation> GetList();
|
static ConversationsList GetList();
|
||||||
};
|
};
|
||||||
|
@ -18,9 +18,9 @@ User UserHelper::GetSingle(int id)
|
|||||||
return getMultiple(l)[id];
|
return getMultiple(l)[id];
|
||||||
}
|
}
|
||||||
|
|
||||||
map<int, User> UserHelper::getMultiple(std::vector<int> ids)
|
UsersList UserHelper::getMultiple(std::vector<int> ids)
|
||||||
{
|
{
|
||||||
map<int, User> users;
|
UsersList users;
|
||||||
vector<int> toGet;
|
vector<int> toGet;
|
||||||
|
|
||||||
// Check for missing users in cache
|
// Check for missing users in cache
|
||||||
@ -62,3 +62,8 @@ map<int, User> UserHelper::getMultiple(std::vector<int> ids)
|
|||||||
|
|
||||||
return users;
|
return users;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
UsersList UserHelper::getMultiple(std::set<int> ids)
|
||||||
|
{
|
||||||
|
return getMultiple(vector<int>(ids.begin(), ids.end()));
|
||||||
|
}
|
||||||
|
@ -8,17 +8,18 @@
|
|||||||
|
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
#include <set>
|
||||||
|
|
||||||
#include <entities/user.h>
|
#include <entities/user.h>
|
||||||
|
|
||||||
|
|
||||||
class UserHelper
|
class UserHelper
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
UserHelper();
|
UserHelper();
|
||||||
|
|
||||||
static User GetSingle(int id);
|
static User GetSingle(int id);
|
||||||
static std::map<int, User> getMultiple(std::vector<int> ids);
|
static UsersList getMultiple(std::vector<int> ids);
|
||||||
|
static UsersList getMultiple(std::set<int> ids);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static std::map<int, User> mCache;
|
static std::map<int, User> mCache;
|
||||||
|
Loading…
Reference in New Issue
Block a user