mirror of
https://github.com/qTox/qTox.git
synced 2024-03-22 14:00:36 +08:00
refactor: Rewrite update status
This commit is contained in:
parent
bb08d628fb
commit
8937f87f87
|
@ -621,6 +621,48 @@ bool ContentDialog::containsGroup(int groupId) const
|
|||
return groupWidgets.contains(groupId);
|
||||
}
|
||||
|
||||
void ContentDialog::updateFriendStatus(int friendId, Status status)
|
||||
{
|
||||
auto widget = qobject_cast<FriendWidget*>(friendWidgets.value(friendId));
|
||||
addFriendWidget(widget, status);
|
||||
}
|
||||
|
||||
void ContentDialog::updateFriendStatusLight(int friendId)
|
||||
{
|
||||
auto widget = friendWidgets.value(friendId);
|
||||
if (widget != nullptr) {
|
||||
widget->updateStatusLight();
|
||||
}
|
||||
}
|
||||
|
||||
void ContentDialog::updateGroupStatusLight(int groupId)
|
||||
{
|
||||
auto widget = groupWidgets.value(groupId);
|
||||
if (widget != nullptr) {
|
||||
widget->updateStatusLight();
|
||||
}
|
||||
}
|
||||
|
||||
bool ContentDialog::isFriendWidgetActive(int friendId)
|
||||
{
|
||||
auto widget = friendWidgets.value(friendId);
|
||||
if (widget == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return widget->isActive();
|
||||
}
|
||||
|
||||
bool ContentDialog::isGroupWidgetActive(int groupId)
|
||||
{
|
||||
auto widget = friendWidgets.value(groupId);
|
||||
if (widget == nullptr) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return widget->isActive();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update friend widget name and position.
|
||||
* @param friendId Friend Id.
|
||||
|
|
|
@ -80,6 +80,13 @@ public:
|
|||
bool containsFriend(int friendId) const;
|
||||
bool containsGroup(int groupId) const;
|
||||
|
||||
void updateFriendStatus(int friendId, Status status);
|
||||
void updateFriendStatusLight(int friendId);
|
||||
void updateGroupStatusLight(int groupId);
|
||||
|
||||
bool isFriendWidgetActive(int friendId);
|
||||
bool isGroupWidgetActive(int groupId);
|
||||
|
||||
signals:
|
||||
void friendDialogShown(const Friend* f);
|
||||
void groupDialogShown(Group* g);
|
||||
|
|
|
@ -144,16 +144,18 @@ ContentDialog* ContentDialogManager::focusDialog(int id, const QHash<int, Conten
|
|||
|
||||
void ContentDialogManager::updateFriendStatus(int friendId)
|
||||
{
|
||||
updateStatus(friendId, friendList);
|
||||
ContentDialog* contentDialog = getFriendDialog(friendId);
|
||||
if (contentDialog) {
|
||||
auto iter = friendList.find(friendId).value();
|
||||
GenericChatroomWidget* widget = std::get<1>(iter);
|
||||
FriendWidget* friendWidget = static_cast<FriendWidget*>(widget);
|
||||
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
contentDialog->addFriendWidget(friendWidget, f->getStatus());
|
||||
auto dialog = friendDialogs.value(friendId);
|
||||
if (dialog == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
dialog->updateFriendStatusLight(friendId);
|
||||
if (dialog->isFriendWidgetActive(friendId)) {
|
||||
dialog->updateTitleAndStatusIcon();
|
||||
}
|
||||
|
||||
Friend* f = FriendList::findFriend(friendId);
|
||||
dialog->updateFriendStatus(friendId, f->getStatus());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -173,7 +175,15 @@ void ContentDialogManager::updateFriendStatusMessage(int friendId, const QString
|
|||
|
||||
void ContentDialogManager::updateGroupStatus(int groupId)
|
||||
{
|
||||
updateStatus(groupId, groupList);
|
||||
auto dialog = friendDialogs.value(groupId);
|
||||
if (dialog == nullptr) {
|
||||
return;
|
||||
}
|
||||
|
||||
dialog->updateGroupStatusLight(groupId);
|
||||
if (dialog->isGroupWidgetActive(groupId)) {
|
||||
dialog->updateTitleAndStatusIcon();
|
||||
}
|
||||
}
|
||||
|
||||
bool ContentDialogManager::isFriendWidgetActive(int friendId)
|
||||
|
@ -214,27 +224,6 @@ ContentDialog* ContentDialogManager::getGroupDialog(int groupId) const
|
|||
return groupDialogs.value(groupId);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Update widget status and dialog title for current user.
|
||||
* @param id User Id.
|
||||
* @param list List with contact info.
|
||||
*/
|
||||
void ContentDialogManager::updateStatus(int id, const QHash<int, ContactInfo>& list)
|
||||
{
|
||||
auto iter = list.find(id);
|
||||
if (iter == list.end()) {
|
||||
return;
|
||||
}
|
||||
|
||||
GenericChatroomWidget* chatroomWidget = std::get<1>(*iter);
|
||||
chatroomWidget->updateStatusLight();
|
||||
|
||||
if (chatroomWidget->isActive()) {
|
||||
ContentDialog* dialog = std::get<0>(*iter);
|
||||
dialog->updateTitleAndStatusIcon();
|
||||
}
|
||||
}
|
||||
|
||||
ContentDialogManager* ContentDialogManager::getInstance()
|
||||
{
|
||||
if (instance == nullptr) {
|
||||
|
|
Loading…
Reference in New Issue
Block a user