FriendWidget* ContentDialog::addFriend(int friendId, QString id) { FriendWidget* friendWidget = new FriendWidget(friendId, id); friendLayout->addFriendWidget(friendWidget, FriendList::findFriend(friendId)->getStatus()); Friend* frnd = friendWidget->getFriend(); const Settings& s = Settings::getInstance(); connect(frnd, &Friend::displayedNameChanged, this, &ContentDialog::updateFriendWidget); connect(&s, &Settings::compactLayoutChanged, friendWidget, &FriendWidget::compactChange); connect(friendWidget, &FriendWidget::chatroomWidgetClicked, this, &ContentDialog::onChatroomWidgetClicked); connect(friendWidget, SIGNAL(chatroomWidgetClicked(GenericChatroomWidget*)), frnd->getChatForm(), SLOT(focusInput())); connect(Core::getInstance(), &Core::friendAvatarChanged, friendWidget, &FriendWidget::onAvatarChange); connect(Core::getInstance(), &Core::friendAvatarRemoved, friendWidget, &FriendWidget::onAvatarRemoved); ContentDialog* lastDialog = getFriendDialog(friendId); if (lastDialog != nullptr) lastDialog->removeFriend(friendId); friendList.insert(friendId, std::make_tuple(this, friendWidget)); onChatroomWidgetClicked(friendWidget, false); return friendWidget; }
void ContentDialog::updateFriendStatus(int friendId) { updateStatus(friendId, friendList); ContentDialog* contentDialog = getFriendDialog(friendId); if (contentDialog != nullptr) { FriendWidget* friendWidget = static_cast<FriendWidget*>(std::get<1>(friendList.find(friendId).value())); contentDialog->friendLayout->addFriendWidget(friendWidget, FriendList::findFriend(friendId)->getStatus()); } }
FriendWidget* ContentDialogManager::addFriendToDialog(ContentDialog* dialog, std::shared_ptr<FriendChatroom> chatroom, GenericChatForm* form) { auto friendWidget = dialog->addFriend(chatroom, form); const auto friendPk = friendWidget->getFriend()->getPublicKey(); ContentDialog* lastDialog = getFriendDialog(friendPk); if (lastDialog) { lastDialog->removeFriend(friendPk); } contactDialogs[friendPk] = dialog; return friendWidget; }