1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

refactor(model): Add getDisplayedName(ToxPk) to Chat

To allow resolving the author's name in a group through Chat
This commit is contained in:
Anthony Bilinski 2022-03-09 17:26:07 -08:00
parent e4fefccff8
commit b320397558
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
5 changed files with 18 additions and 0 deletions

View File

@ -23,6 +23,7 @@
#include <QObject>
#include <QString>
class ToxPk;
class Chat : public QObject
{
Q_OBJECT
@ -31,6 +32,7 @@ public:
virtual void setName(const QString& name) = 0;
virtual QString getDisplayedName() const = 0;
virtual QString getDisplayedName(const ToxPk& contact) const = 0;
virtual uint32_t getId() const = 0;
virtual const ChatId& getPersistentId() const = 0;
virtual void setEventFlag(bool flag) = 0;

View File

@ -24,7 +24,9 @@
#include "src/widget/form/chatform.h"
#include <QDebug>
#include <memory>
#include <cassert>
Friend::Friend(uint32_t friendId_, const ToxPk& friendPk_, const QString& userAlias_, const QString& userName_)
: userName{userName_}
@ -118,6 +120,13 @@ QString Friend::getDisplayedName() const
return userAlias;
}
QString Friend::getDisplayedName(const ToxPk& contact) const
{
std::ignore = contact;
assert(contact == friendPk);
return getDisplayedName();
}
bool Friend::hasAlias() const
{
return !userAlias.isEmpty();

View File

@ -39,6 +39,7 @@ public:
void setName(const QString& name) override;
void setAlias(const QString& alias);
QString getDisplayedName() const override;
QString getDisplayedName(const ToxPk& contact) const override;
bool hasAlias() const;
QString getUserName() const;
void setStatusMessage(const QString& message);

View File

@ -83,6 +83,11 @@ QString Group::getDisplayedName() const
return getName();
}
QString Group::getDisplayedName(const ToxPk& contact) const
{
return resolveToxPk(contact);
}
void Group::regeneratePeerList()
{
// NOTE: there's a bit of a race here. Core emits a signal for both groupPeerlistChanged and

View File

@ -59,6 +59,7 @@ public:
void setTitle(const QString& author, const QString& newTitle);
QString getName() const;
QString getDisplayedName() const override;
QString getDisplayedName(const ToxPk& contact) const override;
QString resolveToxPk(const ToxPk& id) const;
void setSelfName(const QString& name);
QString getSelfName() const;