Browse Source

refactor(model): Rename Chat::getDisplayedName to getSelfDisplayedName

To add an API for groups resolving a peer's pk to display name
reviewable/pr6561/r2
Anthony Bilinski 4 years ago
parent
commit
50558b20df
No known key found for this signature in database
GPG Key ID: 2AA8E0DA1B31FB3C
  1. 2
      src/friendlist.cpp
  2. 2
      src/model/about/aboutfriend.cpp
  3. 2
      src/model/chat.h
  4. 4
      src/model/chathistory.cpp
  5. 12
      src/model/friend.cpp
  6. 2
      src/model/friend.h
  7. 2
      src/model/group.cpp
  8. 2
      src/model/group.h
  9. 12
      src/model/notificationgenerator.cpp
  10. 2
      src/model/sessionchatlog.cpp
  11. 14
      src/widget/form/chatform.cpp
  12. 2
      src/widget/form/filesform.cpp
  13. 2
      src/widget/form/genericchatform.cpp
  14. 4
      src/widget/friendwidget.cpp
  15. 2
      src/widget/tool/removefrienddialog.cpp

2
src/friendlist.cpp

@ -85,7 +85,7 @@ QString FriendList::decideNickname(const ToxPk& friendPk, const QString& origNam @@ -85,7 +85,7 @@ QString FriendList::decideNickname(const ToxPk& friendPk, const QString& origNam
{
Friend* f = FriendList::findFriend(friendPk);
if (f != nullptr) {
return f->getDisplayedName();
return f->getSelfDisplayedName();
} else if (!origName.isEmpty()) {
return origName;
} else {

2
src/model/about/aboutfriend.cpp

@ -49,7 +49,7 @@ AboutFriend::AboutFriend(const Friend* f_, IFriendSettings* const settings_) @@ -49,7 +49,7 @@ AboutFriend::AboutFriend(const Friend* f_, IFriendSettings* const settings_)
QString AboutFriend::getName() const
{
return f->getDisplayedName();
return f->getSelfDisplayedName();
}
QString AboutFriend::getStatusMessage() const

2
src/model/chat.h

@ -30,7 +30,7 @@ public: @@ -30,7 +30,7 @@ public:
virtual ~Chat() = 0;
virtual void setName(const QString& name) = 0;
virtual QString getDisplayedName() const = 0;
virtual QString getSelfDisplayedName() const = 0;
virtual uint32_t getId() const = 0;
virtual const ChatId& getPersistentId() const = 0;
virtual void setEventFlag(bool flag) = 0;

4
src/model/chathistory.cpp

@ -223,7 +223,7 @@ void ChatHistory::onFileUpdated(const ToxPk& sender, const ToxFile& file) @@ -223,7 +223,7 @@ void ChatHistory::onFileUpdated(const ToxPk& sender, const ToxFile& file)
switch (file.status) {
case ToxFile::INITIALIZING: {
auto selfPk = coreIdHandler.getSelfPublicKey();
QString username(selfPk == sender ? coreIdHandler.getUsername() : f.getDisplayedName());
QString username(selfPk == sender ? coreIdHandler.getUsername() : f.getSelfDisplayedName());
// Note: There is some implcit coupling between history and the current
// chat log. Both rely on generating a new id based on the state of
@ -267,7 +267,7 @@ void ChatHistory::onMessageReceived(const ToxPk& sender, const Message& message) @@ -267,7 +267,7 @@ void ChatHistory::onMessageReceived(const ToxPk& sender, const Message& message)
{
if (canUseHistory()) {
auto friendPk = f.getPublicKey();
auto displayName = f.getDisplayedName();
auto displayName = f.getSelfDisplayedName();
auto content = message.content;
if (message.isAction) {
content = ChatForm::ACTION_PREFIX + content;

12
src/model/friend.cpp

@ -52,7 +52,7 @@ void Friend::setName(const QString& _name) @@ -52,7 +52,7 @@ void Friend::setName(const QString& _name)
}
// save old displayed name to be able to compare for changes
const auto oldDisplayed = getDisplayedName();
const auto oldDisplayed = getSelfDisplayedName();
if (userName == userAlias) {
userAlias.clear(); // Because userAlias was set on name change before (issue #5013)
// we clear alias if equal to old name so that name change is visible.
@ -63,7 +63,7 @@ void Friend::setName(const QString& _name) @@ -63,7 +63,7 @@ void Friend::setName(const QString& _name)
emit nameChanged(friendPk, name);
}
const auto newDisplayed = getDisplayedName();
const auto newDisplayed = getSelfDisplayedName();
if (oldDisplayed != newDisplayed) {
emit displayedNameChanged(newDisplayed);
}
@ -81,10 +81,10 @@ void Friend::setAlias(const QString& alias) @@ -81,10 +81,10 @@ void Friend::setAlias(const QString& alias)
emit aliasChanged(friendPk, alias);
// save old displayed name to be able to compare for changes
const auto oldDisplayed = getDisplayedName();
const auto oldDisplayed = getSelfDisplayedName();
userAlias = alias;
const auto newDisplayed = getDisplayedName();
const auto newDisplayed = getSelfDisplayedName();
if (oldDisplayed != newDisplayed) {
emit displayedNameChanged(newDisplayed);
}
@ -104,12 +104,12 @@ QString Friend::getStatusMessage() const @@ -104,12 +104,12 @@ QString Friend::getStatusMessage() const
}
/**
* @brief Friend::getDisplayedName Gets the name that should be displayed for a user
* @brief Friend::getSelfDisplayedName Gets the name that should be displayed for a user
* @return a QString containing either alias, username or public key
* @note This function and corresponding signal should be preferred over getting
* the name or alias directly.
*/
QString Friend::getDisplayedName() const
QString Friend::getSelfDisplayedName() const
{
if (userAlias.isEmpty()) {
return userName;

2
src/model/friend.h

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

2
src/model/group.cpp

@ -76,7 +76,7 @@ QString Group::getName() const @@ -76,7 +76,7 @@ QString Group::getName() const
return title;
}
QString Group::getDisplayedName() const
QString Group::getSelfDisplayedName() const
{
return getName();
}

2
src/model/group.h

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

12
src/model/notificationgenerator.cpp

@ -60,11 +60,11 @@ namespace @@ -60,11 +60,11 @@ namespace
//: e.g. 2 messages from Bob
return QObject::tr("%1 message(s) from %2")
.arg(numNotifications[contact])
.arg(contact->getDisplayedName());
.arg(contact->getSelfDisplayedName());
}
else
{
return contact->getDisplayedName();
return contact->getSelfDisplayedName();
}
}
@ -116,11 +116,11 @@ namespace @@ -116,11 +116,11 @@ namespace
displayNames.reserve(numChats);
for (auto it = friendNotifications.begin(); it != friendNotifications.end(); ++it) {
displayNames.push_back(it.key()->getDisplayedName());
displayNames.push_back(it.key()->getSelfDisplayedName());
}
for (auto it = groupNotifications.begin(); it != groupNotifications.end(); ++it) {
displayNames.push_back(it.key()->getDisplayedName());
displayNames.push_back(it.key()->getSelfDisplayedName());
}
assert(displayNames.size() > 0);
@ -223,7 +223,7 @@ NotificationData NotificationGenerator::fileTransferNotification(const Friend* f @@ -223,7 +223,7 @@ NotificationData NotificationGenerator::fileTransferNotification(const Friend* f
else
{
//: e.g. Bob - file transfer
ret.title = tr("%1 - file transfer").arg(f->getDisplayedName());
ret.title = tr("%1 - file transfer").arg(f->getSelfDisplayedName());
ret.message = filename + " (" + getHumanReadableSize(fileSize) + ")";
}
@ -241,7 +241,7 @@ NotificationData NotificationGenerator::groupInvitationNotification(const Friend @@ -241,7 +241,7 @@ NotificationData NotificationGenerator::groupInvitationNotification(const Friend
return ret;
}
ret.title = tr("%1 invites you to join a group.").arg(from->getDisplayedName());
ret.title = tr("%1 invites you to join a group.").arg(from->getSelfDisplayedName());
ret.message = "";
ret.pixmap = getSenderAvatar(profile, from->getPublicKey());

2
src/model/sessionchatlog.cpp

@ -111,7 +111,7 @@ QString resolveToxPk(const ToxPk& pk) @@ -111,7 +111,7 @@ QString resolveToxPk(const ToxPk& pk)
{
Friend* f = FriendList::findFriend(pk);
if (f) {
return f->getDisplayedName();
return f->getSelfDisplayedName();
}
for (Group* it : GroupList::getAllGroups()) {

14
src/widget/form/chatform.cpp

@ -118,7 +118,7 @@ ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_, @@ -118,7 +118,7 @@ ChatForm::ChatForm(Profile& profile, Friend* chatFriend, IChatLog& chatLog_,
, cameraSource{cameraSource_}
, settings{settings_}
{
setName(f->getDisplayedName());
setName(f->getSelfDisplayedName());
headWidget->setAvatar(QPixmap(":/img/contact_dark.svg"));
@ -315,7 +315,7 @@ void ChatForm::onAvInvite(uint32_t friendId, bool video) @@ -315,7 +315,7 @@ void ChatForm::onAvInvite(uint32_t friendId, bool video)
return;
}
QString displayedName = f->getDisplayedName();
QString displayedName = f->getSelfDisplayedName();
SystemMessage systemMessage;
systemMessage.messageType = SystemMessageType::incomingCall;
@ -378,7 +378,7 @@ void ChatForm::showOutgoingCall(bool video) @@ -378,7 +378,7 @@ void ChatForm::showOutgoingCall(bool video)
{
headWidget->showOutgoingCall(video);
addSystemInfoMessage(QDateTime::currentDateTime(), SystemMessageType::outgoingCall,
{f->getDisplayedName()});
{f->getSelfDisplayedName()});
emit outgoingNotification();
emit updateFriendActivity(*f);
}
@ -474,7 +474,7 @@ void ChatForm::onFriendStatusChanged(const ToxPk& friendPk, Status::Status statu @@ -474,7 +474,7 @@ void ChatForm::onFriendStatusChanged(const ToxPk& friendPk, Status::Status statu
if (settings.getStatusChangeNotificationEnabled()) {
QString fStatus = Status::getTitle(status);
addSystemInfoMessage(QDateTime::currentDateTime(), SystemMessageType::peerStateChange,
{f->getDisplayedName(), fStatus});
{f->getSelfDisplayedName(), fStatus});
}
}
@ -516,7 +516,7 @@ std::unique_ptr<NetCamView> ChatForm::createNetcam() @@ -516,7 +516,7 @@ std::unique_ptr<NetCamView> ChatForm::createNetcam()
new NetCamView(f->getPublicKey(), cameraSource, settings, this));
CoreAV* av = core.getAv();
VideoSource* source = av->getVideoSourceFromCall(friendId);
view->show(source, f->getDisplayedName());
view->show(source, f->getSelfDisplayedName());
connect(view.get(), &NetCamView::videoCallEnd, this, &ChatForm::onVideoCallTriggered);
connect(view.get(), &NetCamView::volMuteToggle, this, &ChatForm::onVolMuteToggle);
connect(view.get(), &NetCamView::micMuteToggle, this, &ChatForm::onMicMuteToggle);
@ -690,7 +690,7 @@ void ChatForm::stopCounter(bool error) @@ -690,7 +690,7 @@ void ChatForm::stopCounter(bool error)
return;
}
QString dhms = secondsToDHMS(timeElapsed.elapsed() / 1000);
QString name = f->getDisplayedName();
QString name = f->getSelfDisplayedName();
auto messageType = error ? SystemMessageType::unexpectedCallEnd : SystemMessageType::callEnd;
// TODO: add notification once notifications are implemented
@ -711,7 +711,7 @@ void ChatForm::onUpdateTime() @@ -711,7 +711,7 @@ void ChatForm::onUpdateTime()
void ChatForm::setFriendTyping(bool isTyping_)
{
chatWidget->setTypingNotificationVisible(isTyping_);
QString name = f->getDisplayedName();
QString name = f->getSelfDisplayedName();
chatWidget->setTypingNotificationName(name);
}

2
src/widget/form/filesform.cpp

@ -274,7 +274,7 @@ namespace FileTransferList @@ -274,7 +274,7 @@ namespace FileTransferList
return "Unknown";
}
return f->getDisplayedName();
return f->getSelfDisplayedName();
}
case Column::progress:
return files[row].progress.getProgress() * 100.0;

2
src/widget/form/genericchatform.cpp

@ -99,7 +99,7 @@ QString GenericChatForm::resolveToxPk(const ToxPk& pk) @@ -99,7 +99,7 @@ QString GenericChatForm::resolveToxPk(const ToxPk& pk)
{
Friend* f = FriendList::findFriend(pk);
if (f) {
return f->getDisplayedName();
return f->getSelfDisplayedName();
}
for (Group* it : GroupList::getAllGroups()) {

4
src/widget/friendwidget.cpp

@ -67,7 +67,7 @@ FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom_, bool compa @@ -67,7 +67,7 @@ FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom_, bool compa
statusPic.setMargin(3);
auto frnd = chatroom->getFriend();
nameLabel->setText(frnd->getDisplayedName());
nameLabel->setText(frnd->getSelfDisplayedName());
// update alias when edited
connect(nameLabel, &CroppingLabel::editFinished, frnd, &Friend::setAlias);
// update on changes of the displayed name
@ -451,7 +451,7 @@ void FriendWidget::mouseMoveEvent(QMouseEvent* ev) @@ -451,7 +451,7 @@ void FriendWidget::mouseMoveEvent(QMouseEvent* ev)
if (distance > QApplication::startDragDistance()) {
QMimeData* mdata = new QMimeData;
const Friend* frnd = getFriend();
mdata->setText(frnd->getDisplayedName());
mdata->setText(frnd->getSelfDisplayedName());
mdata->setData("toxPk", frnd->getPublicKey().getByteArray());
QDrag* drag = new QDrag(this);

2
src/widget/tool/removefrienddialog.cpp

@ -27,7 +27,7 @@ RemoveFriendDialog::RemoveFriendDialog(QWidget* parent, const Friend* f) @@ -27,7 +27,7 @@ RemoveFriendDialog::RemoveFriendDialog(QWidget* parent, const Friend* f)
setWindowFlags(windowFlags() & ~Qt::WindowContextHelpButtonHint);
setAttribute(Qt::WA_QuitOnClose, false);
ui.setupUi(this);
QString name = f->getDisplayedName().toHtmlEscaped();
QString name = f->getSelfDisplayedName().toHtmlEscaped();
QString text = tr("Are you sure you want to remove %1 from your contacts list?")
.arg(QString("<b>%1</b>").arg(name));

Loading…
Cancel
Save