Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(ui): re-sort friends list on friend rename
Browse files Browse the repository at this point in the history
Fix #5387
  • Loading branch information
anthonybilinski committed Oct 12, 2018
1 parent 2ecfbf7 commit aa7542f
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 0 deletions.
26 changes: 26 additions & 0 deletions src/widget/friendlistwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,7 @@ void FriendListWidget::addFriendWidget(FriendWidget* w, Status s, int circleInde
moveWidget(w, s, true);
else
circleWidget->addFriendWidget(w, s);
connect(w, &FriendWidget::friendWidgetRenamed, this, &FriendListWidget::onFriendWidgetRenamed);
}

void FriendListWidget::removeGroupWidget(GroupWidget* w)
Expand Down Expand Up @@ -395,6 +396,31 @@ void FriendListWidget::renameCircleWidget(CircleWidget* circleWidget, const QStr
circleLayout->addSortedWidget(circleWidget);
}

void FriendListWidget::onFriendWidgetRenamed(FriendWidget* friendWidget)
{
const Friend* contact = friendWidget->getFriend();
auto status = contact->getStatus();
if (mode == Activity) {
QDate activityDate = getDateFriend(contact);
int time = static_cast<int>(getTime(activityDate));
QWidget* widget = activityLayout->itemAt(time)->widget();
CategoryWidget* categoryWidget = qobject_cast<CategoryWidget*>(widget);
categoryWidget->removeFriendWidget(friendWidget, status);
categoryWidget->addFriendWidget(friendWidget, status);
} else {
int id = Settings::getInstance().getFriendCircleID(contact->getPublicKey());
CircleWidget* circleWidget = CircleWidget::getFromID(id);
if (circleWidget != nullptr) {
circleWidget->removeFriendWidget(friendWidget, status);
circleWidget->addFriendWidget(friendWidget, status);
Widget::getInstance()->searchCircle(circleWidget);
} else {
listLayout->removeFriendWidget(friendWidget, status);
listLayout->addFriendWidget(friendWidget, status);
}
}
}

void FriendListWidget::onGroupchatPositionChanged(bool top)
{
groupsOnTop = top;
Expand Down
1 change: 1 addition & 0 deletions src/widget/friendlistwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ class FriendListWidget : public QWidget
public slots:
void renameGroupWidget(GroupWidget* groupWidget, const QString& newName);
void renameCircleWidget(CircleWidget* circleWidget, const QString& newName);
void onFriendWidgetRenamed(FriendWidget* friendWidget);
void onGroupchatPositionChanged(bool top);
void moveWidget(FriendWidget* w, Status s, bool add = false);

Expand Down
1 change: 1 addition & 0 deletions src/widget/friendwidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ FriendWidget::FriendWidget(std::shared_ptr<FriendChatroom> chatroom, bool compac
connect(nameLabel, &CroppingLabel::editFinished, frnd, &Friend::setAlias);
// update on changes of the displayed name
connect(frnd, &Friend::displayedNameChanged, nameLabel, &CroppingLabel::setText);
connect(frnd, &Friend::displayedNameChanged, [this](const QString /* &newName */){emit friendWidgetRenamed(this);});
connect(chatroom.get(), &FriendChatroom::activeChanged, this, &FriendWidget::setActive);
statusMessageLabel->setTextFormat(Qt::PlainText);
}
Expand Down
1 change: 1 addition & 0 deletions src/widget/friendwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class FriendWidget : public GenericChatroomWidget
void copyFriendIdToClipboard(int friendId);
void contextMenuCalled(QContextMenuEvent* event);
void friendHistoryRemoved();
void friendWidgetRenamed(FriendWidget* friendWidget);

public slots:
void onAvatarSet(const ToxPk& friendPk, const QPixmap& pic);
Expand Down

0 comments on commit aa7542f

Please sign in to comment.