1
0
mirror of https://gitlab.com/comunic/comunicterm synced 2025-06-19 16:45:17 +00:00

Can process & return the real name of conversations

This commit is contained in:
2020-01-12 21:15:51 +01:00
parent 6a8a0d2c6d
commit 14d960713c
11 changed files with 113 additions and 11 deletions

View File

@ -1,5 +1,11 @@
#include <iostream>
#include "conversation.h"
#include "../helpers/accounthelper.h"
using namespace std;
Conversation::Conversation()
{
@ -35,6 +41,34 @@ void Conversation::setLastActive(int 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
{
return mName;
@ -45,6 +79,11 @@ void Conversation::setName(const std::string &name)
mName = name;
}
bool Conversation::hasName() const
{
return mName.size() > 0;
}
bool Conversation::following() const
{
return mFollowing;

View File

@ -10,6 +10,8 @@
#include <string>
#include <vector>
#include "user.h"
class Conversation
{
public:
@ -24,8 +26,10 @@ public:
int lastActive() const;
void setLastActive(int lastActive);
std::string name(UsersList users);
std::string name() const;
void setName(const std::string &name);
bool hasName() const;
bool following() const;
void setFollowing(bool following);
@ -41,6 +45,7 @@ private:
int mID_Owner;
int mLastActive;
std::string mName;
std::string mComputedName = "";
bool mFollowing;
bool mSawLastMessage;
std::vector<int> mMembers;

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

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

View File

@ -7,7 +7,7 @@
#pragma once
#include <string>
#include <map>
class User
{
@ -31,3 +31,5 @@ private:
std::string mFirstName;
std::string mLastName;
};
typedef std::map<int, User> UsersList;