From 660fe527f2caf2cc00f2584a6d7db9664aa35ee5 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Fri, 1 Dec 2023 00:23:23 +0100 Subject: [PATCH] Handle event updateChatAvailableReactions --- rpm/harbour-fernschreiber.spec | 2 +- src/chatlistmodel.cpp | 30 ++++++++++++++++++++++++++++++ src/chatlistmodel.h | 2 ++ src/tdlibreceiver.cpp | 10 ++++++++++ src/tdlibreceiver.h | 2 ++ src/tdlibwrapper.cpp | 18 ++++++++++++++++++ src/tdlibwrapper.h | 2 ++ 7 files changed, 65 insertions(+), 1 deletion(-) diff --git a/rpm/harbour-fernschreiber.spec b/rpm/harbour-fernschreiber.spec index 8923dbb..b62eedb 100644 --- a/rpm/harbour-fernschreiber.spec +++ b/rpm/harbour-fernschreiber.spec @@ -12,7 +12,7 @@ Name: harbour-fernschreiber Summary: Fernschreiber is a Telegram client for Aurora OS Version: 0.17 -Release: 10 +Release: 11 Group: Qt/Qt License: LICENSE URL: http://werkwolf.eu/ diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index 0b5d46d..1319938 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -44,6 +44,7 @@ namespace { const QString UNREAD_COUNT("unread_count"); const QString UNREAD_MENTION_COUNT("unread_mention_count"); const QString UNREAD_REACTION_COUNT("unread_reaction_count"); + const QString AVAILABLE_REACTIONS("available_reactions"); const QString NOTIFICATION_SETTINGS("notification_settings"); const QString LAST_READ_INBOX_MESSAGE_ID("last_read_inbox_message_id"); const QString LAST_READ_OUTBOX_MESSAGE_ID("last_read_outbox_message_id"); @@ -70,6 +71,7 @@ public: int unreadCount() const; int unreadMentionCount() const; int unreadReactionCount() const; + QVariant availableReactions() const; QVariant photoSmall() const; qlonglong lastReadInboxMessageId() const; qlonglong senderUserId() const; @@ -168,6 +170,11 @@ int ChatListModel::ChatData::unreadMentionCount() const return chatData.value(UNREAD_MENTION_COUNT).toInt(); } +QVariant ChatListModel::ChatData::availableReactions() const +{ + return chatData.value(AVAILABLE_REACTIONS); +} + int ChatListModel::ChatData::unreadReactionCount() const { return chatData.value(UNREAD_REACTION_COUNT).toInt(); @@ -400,6 +407,7 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper, AppSettings *appSetting connect(tdLibWrapper, SIGNAL(chatDraftMessageUpdated(qlonglong, QVariantMap, QString)), this, SLOT(handleChatDraftMessageUpdated(qlonglong, QVariantMap, QString))); connect(tdLibWrapper, SIGNAL(chatUnreadMentionCountUpdated(qlonglong, int)), this, SLOT(handleChatUnreadMentionCountUpdated(qlonglong, int))); connect(tdLibWrapper, SIGNAL(chatUnreadReactionCountUpdated(qlonglong, int)), this, SLOT(handleChatUnreadReactionCountUpdated(qlonglong, int))); + connect(tdLibWrapper, SIGNAL(chatAvailableReactionsUpdated(qlonglong, QString)), this, SLOT(handleChatAvailableReactionsUpdated(qlonglong, QString))); // Don't start the timer until we have at least one chat relativeTimeRefreshTimer = new QTimer(this); @@ -436,6 +444,7 @@ QHash ChatListModel::roleNames() const roles.insert(ChatListModel::RoleUnreadCount, "unread_count"); roles.insert(ChatListModel::RoleUnreadMentionCount, "unread_mention_count"); roles.insert(ChatListModel::RoleUnreadReactionCount, "unread_reaction_count"); + roles.insert(ChatListModel::RoleAvailableReactions, "available_reactions"); roles.insert(ChatListModel::RoleLastReadInboxMessageId, "last_read_inbox_message_id"); roles.insert(ChatListModel::RoleLastMessageSenderId, "last_message_sender_id"); roles.insert(ChatListModel::RoleLastMessageDate, "last_message_date"); @@ -472,6 +481,7 @@ QVariant ChatListModel::data(const QModelIndex &index, int role) const case ChatListModel::RolePhotoSmall: return data->photoSmall(); case ChatListModel::RoleUnreadCount: return data->unreadCount(); case ChatListModel::RoleUnreadMentionCount: return data->unreadMentionCount(); + case ChatListModel::RoleAvailableReactions: return data->availableReactions(); case ChatListModel::RoleUnreadReactionCount: return data->unreadReactionCount(); case ChatListModel::RoleLastReadInboxMessageId: return data->lastReadInboxMessageId(); case ChatListModel::RoleLastMessageSenderId: return data->senderUserId(); @@ -1036,6 +1046,26 @@ void ChatListModel::handleChatUnreadReactionCountUpdated(qlonglong chatId, int u } } +void ChatListModel::handleChatAvailableReactionsUpdated(qlonglong chatId, const QVariantMap availableReactions) +{ + if (chatIndexMap.contains(chatId)) { + LOG("Updating available reaction type for" << chatId << availableReactions); + const int chatIndex = chatIndexMap.value(chatId); + ChatData *chat = chatList.at(chatIndex); + chat->chatData.insert(AVAILABLE_REACTIONS, availableReactions); + QVector changedRoles; + changedRoles.append(ChatListModel::RoleAvailableReactions); + const QModelIndex modelIndex(index(chatIndex)); + emit dataChanged(modelIndex, modelIndex, changedRoles); + } else { + ChatData *chat = hiddenChats.value(chatId); + if (chat) { + LOG("Updating available reaction type for hidden chat" << chatId << availableReactions); + chat->chatData.insert(AVAILABLE_REACTIONS, availableReactions); + } + } +} + void ChatListModel::handleRelativeTimeRefreshTimer() { LOG("Refreshing timestamps"); diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index 9bcc837..af875df 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -42,6 +42,7 @@ public: RoleUnreadCount, RoleUnreadMentionCount, RoleUnreadReactionCount, + RoleAvailableReactions, RoleLastReadInboxMessageId, RoleLastMessageSenderId, RoleLastMessageDate, @@ -93,6 +94,7 @@ private slots: void handleChatDraftMessageUpdated(qlonglong chatId, const QVariantMap &draftMessage, const QString &order); void handleChatUnreadMentionCountUpdated(qlonglong chatId, int unreadMentionCount); void handleChatUnreadReactionCountUpdated(qlonglong chatId, int unreadReactionCount); + void handleChatAvailableReactionsUpdated(qlonglong chatId, const QVariantMap availableReactions); void handleRelativeTimeRefreshTimer(); signals: diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index c93b549..44034c7 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -46,6 +46,7 @@ namespace { const QString UNREAD_COUNT("unread_count"); const QString UNREAD_MENTION_COUNT("unread_mention_count"); const QString UNREAD_REACTION_COUNT("unread_reaction_count"); + const QString AVAILABLE_REACTIONS("available_reactions"); const QString TEXT("text"); const QString LAST_READ_INBOX_MESSAGE_ID("last_read_inbox_message_id"); const QString LAST_READ_OUTBOX_MESSAGE_ID("last_read_outbox_message_id"); @@ -123,6 +124,7 @@ TDLibReceiver::TDLibReceiver(void *tdLibClient, QObject *parent) : QThread(paren handlers.insert("updateChatPosition", &TDLibReceiver::processUpdateChatPosition); handlers.insert("updateChatReadInbox", &TDLibReceiver::processUpdateChatReadInbox); handlers.insert("updateChatReadOutbox", &TDLibReceiver::processUpdateChatReadOutbox); + handlers.insert("updateChatAvailableReactions", &TDLibReceiver::processUpdateChatAvailableReactions); handlers.insert("updateBasicGroup", &TDLibReceiver::processUpdateBasicGroup); handlers.insert("updateSupergroup", &TDLibReceiver::processUpdateSuperGroup); handlers.insert("updateChatOnlineMemberCount", &TDLibReceiver::processChatOnlineMemberCountUpdated); @@ -363,6 +365,14 @@ void TDLibReceiver::processUpdateChatReadOutbox(const QVariantMap &receivedInfor emit chatReadOutboxUpdated(chat_id, last_read_outbox_message_id); } +void TDLibReceiver::processUpdateChatAvailableReactions(const QVariantMap &receivedInformation) +{ + const qlonglong chat_id(receivedInformation.value(CHAT_ID).toLongLong()); + const QVariantMap available_reactions(receivedInformation.value(AVAILABLE_REACTIONS).toMap()); + LOG("Available reactions updated for" << chat_id << "new information:" << available_reactions); + emit chatAvailableReactionsUpdated(chat_id, available_reactions); +} + void TDLibReceiver::processUpdateBasicGroup(const QVariantMap &receivedInformation) { const QVariantMap basicGroup(receivedInformation.value(BASIC_GROUP).toMap()); diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h index dda2cd0..33771b6 100644 --- a/src/tdlibreceiver.h +++ b/src/tdlibreceiver.h @@ -52,6 +52,7 @@ signals: void chatPinnedUpdated(qlonglong chatId, bool isPinned); void chatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, int unreadCount); void chatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId); + void chatAvailableReactionsUpdated(const qlonglong &chatId, const QVariantMap &availableReactions); void basicGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation); void superGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation); void chatOnlineMemberCountUpdated(const QString &chatId, int onlineMemberCount); @@ -136,6 +137,7 @@ private: void processUpdateChatPosition(const QVariantMap &receivedInformation); void processUpdateChatReadInbox(const QVariantMap &receivedInformation); void processUpdateChatReadOutbox(const QVariantMap &receivedInformation); + void processUpdateChatAvailableReactions(const QVariantMap &receivedInformation); void processUpdateBasicGroup(const QVariantMap &receivedInformation); void processUpdateSuperGroup(const QVariantMap &receivedInformation); void processChatOnlineMemberCountUpdated(const QVariantMap &receivedInformation); diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 7e56268..7a95e2a 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -137,6 +137,7 @@ void TDLibWrapper::initializeTDLibReceiver() { connect(this->tdLibReceiver, SIGNAL(chatOrderUpdated(QString, QString)), this, SIGNAL(chatOrderUpdated(QString, QString))); connect(this->tdLibReceiver, SIGNAL(chatReadInboxUpdated(QString, QString, int)), this, SIGNAL(chatReadInboxUpdated(QString, QString, int))); connect(this->tdLibReceiver, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SIGNAL(chatReadOutboxUpdated(QString, QString))); + connect(this->tdLibReceiver, SIGNAL(chatAvailableReactionsUpdated(qlonglong, QVariantMap)), this, SLOT(handleAvailableReactionsUpdated(qlonglong, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(basicGroupUpdated(qlonglong, QVariantMap)), this, SLOT(handleBasicGroupUpdated(qlonglong, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(superGroupUpdated(qlonglong, QVariantMap)), this, SLOT(handleSuperGroupUpdated(qlonglong, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(chatOnlineMemberCountUpdated(QString, int)), this, SIGNAL(chatOnlineMemberCountUpdated(QString, int))); @@ -1607,12 +1608,15 @@ QVariantMap TDLibWrapper::getChat(const QString &chatId) QStringList TDLibWrapper::getChatReactions(const QString &chatId) { + LOG("Obtaining chat reactions for chat" << chatId); const QVariant available_reactions(chats.value(chatId).toMap().value(CHAT_AVAILABLE_REACTIONS)); const QVariantMap map(available_reactions.toMap()); const QString reactions_type(map.value(_TYPE).toString()); if (reactions_type == CHAT_AVAILABLE_REACTIONS_ALL) { + LOG("Chat uses all available reactions, currently available number" << activeEmojiReactions.size()); return activeEmojiReactions; } else if (reactions_type == CHAT_AVAILABLE_REACTIONS_SOME) { + LOG("Chat uses reduced set of reactions"); const QVariantList reactions(map.value(REACTIONS).toList()); const int n = reactions.count(); QStringList emojis; @@ -1634,10 +1638,13 @@ QStringList TDLibWrapper::getChatReactions(const QString &chatId) } } } + LOG("Found emojis for this chat" << emojis.size()); return emojis; } else if (reactions_type.isEmpty()) { + LOG("No chat reaction type specified, using all reactions"); return available_reactions.toStringList(); } else { + LOG("Unknown chat reaction type" << reactions_type); return QStringList(); } } @@ -1907,6 +1914,17 @@ void TDLibWrapper::handleUnreadChatCountUpdated(const QVariantMap &chatCountInfo } } +void TDLibWrapper::handleAvailableReactionsUpdated(qlonglong chatId, const QVariantMap &availableReactions) +{ + LOG("Updating available reactions for chat" << chatId << availableReactions); + QString chatIdString = QString::number(chatId); + QVariantMap chatInformation = this->getChat(chatIdString); + chatInformation.insert(CHAT_AVAILABLE_REACTIONS, availableReactions); + this->chats.insert(chatIdString, chatInformation); + emit chatAvailableReactionsUpdated(chatId, availableReactions); + +} + void TDLibWrapper::handleBasicGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation) { emit basicGroupUpdated(updateGroup(groupId, groupInformation, &basicGroups)->groupId); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index 8217804..b03ae10 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -279,6 +279,7 @@ signals: void chatPinnedUpdated(qlonglong chatId, bool isPinned); void chatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, int unreadCount); void chatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId); + void chatAvailableReactionsUpdated(const qlonglong &chatId, const QVariantMap &availableReactions); void userUpdated(const QString &userId, const QVariantMap &userInformation); void ownUserUpdated(const QVariantMap &userInformation); void basicGroupUpdated(qlonglong groupId); @@ -352,6 +353,7 @@ public slots: void handleChatReceived(const QVariantMap &chatInformation); void handleUnreadMessageCountUpdated(const QVariantMap &messageCountInformation); void handleUnreadChatCountUpdated(const QVariantMap &chatCountInformation); + void handleAvailableReactionsUpdated(qlonglong chatId, const QVariantMap &availableReactions); void handleBasicGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation); void handleSuperGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation); void handleStickerSets(const QVariantList &stickerSets);