mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: update displayed user name from the friend model
This commit is contained in:
parent
a910d57824
commit
1f8c9a2e2f
|
@ -52,7 +52,8 @@ void Group::updatePeer(int peerId, QString name)
|
|||
toxids[peerPk] = name;
|
||||
|
||||
Friend* f = FriendList::findFriend(peerKey);
|
||||
if (f != nullptr && f->hasAlias()) {
|
||||
if (f != nullptr) {
|
||||
// use the displayed name from the friends list
|
||||
peers[peerId] = f->getDisplayedName();
|
||||
toxids[peerPk] = f->getDisplayedName();
|
||||
} else {
|
||||
|
|
|
@ -167,6 +167,7 @@ FriendWidget* ContentDialog::addFriend(const Friend* frnd, GenericChatForm* form
|
|||
friendLayout->addFriendWidget(friendWidget, frnd->getStatus());
|
||||
friendChatForms[friendId] = form;
|
||||
|
||||
// TODO(sudden6): move this connection to the Friend::displayedNameChanged signal
|
||||
connect(frnd, &Friend::aliasChanged, this, &ContentDialog::updateFriendWidget);
|
||||
connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, &ContentDialog::activate);
|
||||
connect(friendWidget, &FriendWidget::newWindowOpened, this, &ContentDialog::openNewDialog);
|
||||
|
@ -745,7 +746,6 @@ void ContentDialog::updateFriendWidget(uint32_t friendId, QString alias)
|
|||
Friend* f = FriendList::findFriend(friendId);
|
||||
GenericChatroomWidget* widget = std::get<1>(friendList.find(friendId).value());
|
||||
FriendWidget* friendWidget = static_cast<FriendWidget*>(widget);
|
||||
friendWidget->setName(alias);
|
||||
|
||||
Status status = f->getStatus();
|
||||
friendLayout->addFriendWidget(friendWidget, status);
|
||||
|
|
|
@ -195,6 +195,9 @@ ChatForm::ChatForm(Friend* chatFriend, History* history)
|
|||
isTyping = false;
|
||||
});
|
||||
|
||||
// reflect name changes in the header
|
||||
// TODO(sudden6): check if this creates a cycle when the alias is changed
|
||||
connect(f, &Friend::displayedNameChanged, this, &ChatForm::setName);
|
||||
connect(headWidget, &ChatFormHeader::nameChanged, this, [=](const QString& newName) {
|
||||
f->setAlias(newName);
|
||||
});
|
||||
|
|
|
@ -70,9 +70,12 @@ FriendWidget::FriendWidget(const Friend* f, bool compact)
|
|||
avatar->setPixmap(QPixmap(":/img/contact.svg"));
|
||||
statusPic.setPixmap(QPixmap(":/img/status/offline.svg"));
|
||||
statusPic.setMargin(3);
|
||||
nameLabel->setText(f->getDisplayedName());
|
||||
setName(f->getDisplayedName());
|
||||
nameLabel->setTextFormat(Qt::PlainText);
|
||||
connect(nameLabel, &CroppingLabel::editFinished, this, &FriendWidget::setAlias);
|
||||
// update on changes of the displayed name
|
||||
connect(f, &Friend::displayedNameChanged, this, &FriendWidget::setName);
|
||||
// update alias when edited
|
||||
connect(nameLabel, &CroppingLabel::editFinished, f, &Friend::setAlias);
|
||||
statusMessageLabel->setTextFormat(Qt::PlainText);
|
||||
}
|
||||
|
||||
|
@ -466,11 +469,3 @@ void FriendWidget::mouseMoveEvent(QMouseEvent* ev)
|
|||
drag->exec(Qt::CopyAction | Qt::MoveAction);
|
||||
}
|
||||
}
|
||||
|
||||
void FriendWidget::setAlias(const QString& _alias)
|
||||
{
|
||||
QString alias = _alias.left(tox_max_name_length());
|
||||
// Hack to avoid edit const Friend. TODO: Repalce on emit
|
||||
Friend* f = FriendList::findFriend(frnd->getId());
|
||||
f->setAlias(alias);
|
||||
}
|
||||
|
|
|
@ -47,7 +47,6 @@ signals:
|
|||
public slots:
|
||||
void onAvatarChange(uint32_t friendId, const QPixmap& pic);
|
||||
void onAvatarRemoved(uint32_t friendId);
|
||||
void setAlias(const QString& alias);
|
||||
void onContextMenuCalled(QContextMenuEvent* event);
|
||||
|
||||
protected:
|
||||
|
|
|
@ -998,7 +998,7 @@ void Widget::addFriend(uint32_t friendId, const ToxPk& friendPk)
|
|||
contactListWidget->addFriendWidget(widget, Status::Offline, s.getFriendCircleID(friendPk));
|
||||
|
||||
connect(newfriend, &Friend::aliasChanged, this, &Widget::onFriendAliasChanged);
|
||||
connect(newfriend, &Friend::nameChanged, this, &Widget::onFriendAliasChanged);
|
||||
connect(newfriend, &Friend::displayedNameChanged, this, &Widget::onFriendDisplayedNameChanged);
|
||||
|
||||
connect(friendForm, &ChatForm::incomingNotification, this, &Widget::incomingNotification);
|
||||
connect(friendForm, &ChatForm::outgoingNotification, this, &Widget::outgoingNotification);
|
||||
|
@ -1083,6 +1083,16 @@ void Widget::onFriendStatusMessageChanged(int friendId, const QString& message)
|
|||
ContentDialog::updateFriendStatusMessage(friendId, message);
|
||||
}
|
||||
|
||||
void Widget::onFriendDisplayedNameChanged(const QString& displayed)
|
||||
{
|
||||
Friend* f = qobject_cast<Friend*>(sender());
|
||||
FriendWidget* friendWidget = friendWidgets[f->getId()];
|
||||
|
||||
if (friendWidget->isActive()) {
|
||||
GUI::setWindowTitle(displayed);
|
||||
}
|
||||
}
|
||||
|
||||
void Widget::onFriendUsernameChanged(int friendId, const QString& username)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
|
@ -1097,27 +1107,16 @@ void Widget::onFriendUsernameChanged(int friendId, const QString& username)
|
|||
|
||||
void Widget::onFriendAliasChanged(uint32_t friendId, const QString& alias)
|
||||
{
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
FriendWidget* friendWidget = friendWidgets[friendId];
|
||||
|
||||
friendWidget->setName(alias);
|
||||
|
||||
if (friendWidget->isActive()) {
|
||||
GUI::setWindowTitle(alias);
|
||||
}
|
||||
Friend* f = qobject_cast<Friend*>(sender());
|
||||
|
||||
// TODO(sudden6): don't update the contact list here, make it update itself
|
||||
FriendWidget* friendWidget = friendWidgets[f->getId()];
|
||||
Status status = f->getStatus();
|
||||
contactListWidget->moveWidget(friendWidget, status);
|
||||
FilterCriteria criteria = getFilterCriteria();
|
||||
bool filter = status == Status::Offline ? filterOffline(criteria) : filterOnline(criteria);
|
||||
friendWidget->searchName(ui->searchContactText->text(), filter);
|
||||
|
||||
ChatForm* friendForm = chatForms[friendId];
|
||||
friendForm->setName(alias);
|
||||
for (Group* g : GroupList::getAllGroups()) {
|
||||
g->regeneratePeerList();
|
||||
}
|
||||
|
||||
const ToxPk& pk = f->getPublicKey();
|
||||
Settings& s = Settings::getInstance();
|
||||
s.setFriendAlias(pk, alias);
|
||||
|
|
|
@ -157,6 +157,7 @@ public slots:
|
|||
void addFriendFailed(const ToxPk& userId, const QString& errorInfo = QString());
|
||||
void onFriendStatusChanged(int friendId, Status status);
|
||||
void onFriendStatusMessageChanged(int friendId, const QString& message);
|
||||
void onFriendDisplayedNameChanged(const QString& displayed);
|
||||
void onFriendUsernameChanged(int friendId, const QString& username);
|
||||
void onFriendAliasChanged(uint32_t friendId, const QString& alias);
|
||||
void onFriendMessageReceived(int friendId, const QString& message, bool isAction);
|
||||
|
|
Loading…
Reference in New Issue
Block a user