From 07fdabc178ffb399d63fc49a9b3e2e1f0b535a65 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 +- rpm/harbour-fernschreiber.yaml | 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 ++ 8 files changed, 66 insertions(+), 2 deletions(-) diff --git a/rpm/harbour-fernschreiber.spec b/rpm/harbour-fernschreiber.spec index 420a075..5f26d72 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 Sailfish OS Version: 0.17 -Release: 10 +Release: 11 Group: Qt/Qt License: LICENSE URL: http://werkwolf.eu/ diff --git a/rpm/harbour-fernschreiber.yaml b/rpm/harbour-fernschreiber.yaml index 655a6ce..27e4f25 100644 --- a/rpm/harbour-fernschreiber.yaml +++ b/rpm/harbour-fernschreiber.yaml @@ -1,7 +1,7 @@ Name: harbour-fernschreiber Summary: Fernschreiber is a Telegram client for Sailfish OS Version: 0.17 -Release: 10 +Release: 11 # The contents of the Group field should be one of the groups listed here: # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS Group: Qt/Qt 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 6abda99..70dcf65 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))); @@ -1632,12 +1633,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; @@ -1659,10 +1663,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(); } } @@ -1932,6 +1939,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 90ccf53..2487ae5 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -280,6 +280,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); @@ -354,6 +355,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);