Skip to content

Commit

Permalink
Handle event updateChatAvailableReactions
Browse files Browse the repository at this point in the history
  • Loading branch information
Wunderfitz committed Nov 30, 2023
1 parent 80ecf50 commit 07fdabc
Show file tree
Hide file tree
Showing 8 changed files with 66 additions and 2 deletions.
2 changes: 1 addition & 1 deletion rpm/harbour-fernschreiber.spec
Original file line number Diff line number Diff line change
Expand Up @@ -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/
Expand Down
2 changes: 1 addition & 1 deletion rpm/harbour-fernschreiber.yaml
Original file line number Diff line number Diff line change
@@ -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
Expand Down
30 changes: 30 additions & 0 deletions src/chatlistmodel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand All @@ -70,6 +71,7 @@ class ChatListModel::ChatData
int unreadCount() const;
int unreadMentionCount() const;
int unreadReactionCount() const;
QVariant availableReactions() const;
QVariant photoSmall() const;
qlonglong lastReadInboxMessageId() const;
qlonglong senderUserId() const;
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -436,6 +444,7 @@ QHash<int,QByteArray> 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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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<int> 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");
Expand Down
2 changes: 2 additions & 0 deletions src/chatlistmodel.h
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ class ChatListModel : public QAbstractListModel
RoleUnreadCount,
RoleUnreadMentionCount,
RoleUnreadReactionCount,
RoleAvailableReactions,
RoleLastReadInboxMessageId,
RoleLastMessageSenderId,
RoleLastMessageDate,
Expand Down Expand Up @@ -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:
Expand Down
10 changes: 10 additions & 0 deletions src/tdlibreceiver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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");
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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());
Expand Down
2 changes: 2 additions & 0 deletions src/tdlibreceiver.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ class TDLibReceiver : public QThread
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);
Expand Down Expand Up @@ -136,6 +137,7 @@ class TDLibReceiver : public QThread
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);
Expand Down
18 changes: 18 additions & 0 deletions src/tdlibwrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)));
Expand Down Expand Up @@ -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;
Expand All @@ -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();
}
}
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions src/tdlibwrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ class TDLibWrapper : public QObject
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);
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 07fdabc

Please sign in to comment.