From 9299205379acd47084f1d8d09a31e995882359e9 Mon Sep 17 00:00:00 2001 From: Sebastian Wolf Date: Wed, 6 Jan 2021 10:42:12 +0100 Subject: [PATCH] Show pinned chat icon in list --- qml/components/ChatListViewItem.qml | 1 + qml/components/PhotoTextsListItem.qml | 19 +++++++++++++++++ qml/pages/AboutPage.qml | 2 +- rpm/harbour-fernschreiber.spec | 4 ++-- rpm/harbour-fernschreiber.yaml | 4 ++-- src/chatlistmodel.cpp | 30 +++++++++++++++++++++++++++ src/chatlistmodel.h | 2 ++ src/tdlibreceiver.cpp | 8 +++++-- src/tdlibreceiver.h | 1 + src/tdlibwrapper.cpp | 3 ++- src/tdlibwrapper.h | 1 + 11 files changed, 67 insertions(+), 8 deletions(-) diff --git a/qml/components/ChatListViewItem.qml b/qml/components/ChatListViewItem.qml index b01c487..4090989 100644 --- a/qml/components/ChatListViewItem.qml +++ b/qml/components/ChatListViewItem.qml @@ -25,6 +25,7 @@ PhotoTextsListItem { unreadCount: unread_count isSecret: ( chat_type === TelegramAPI.ChatTypeSecret ) isMarkedAsUnread: is_marked_as_unread + isPinned: is_pinned openMenuOnPressAndHold: true//chat_id != overviewPage.ownUserId diff --git a/qml/components/PhotoTextsListItem.qml b/qml/components/PhotoTextsListItem.qml index a728053..248cd50 100644 --- a/qml/components/PhotoTextsListItem.qml +++ b/qml/components/PhotoTextsListItem.qml @@ -14,6 +14,7 @@ ListItem { property bool isSecret: false property bool isVerified: false property bool isMarkedAsUnread: false + property bool isPinned: false property alias pictureThumbnail: pictureThumbnail contentHeight: mainRow.height + separator.height + 2 * Theme.paddingMedium @@ -49,6 +50,24 @@ ListItem { height: parent.width } + Rectangle { + id: chatPinnedBackground + color: Theme.overlayBackgroundColor + width: Theme.fontSizeExtraLarge + height: Theme.fontSizeExtraLarge + anchors.top: parent.top + radius: parent.width / 2 + visible: chatListViewItem.isPinned + } + + Image { + source: "image://theme/icon-s-favorite" + height: Theme.fontSizeMedium + width: Theme.fontSizeMedium + anchors.centerIn: chatPinnedBackground + visible: chatListViewItem.isPinned + } + Rectangle { id: chatSecretBackground color: Theme.overlayBackgroundColor diff --git a/qml/pages/AboutPage.qml b/qml/pages/AboutPage.qml index 0ef2397..59a3a4d 100644 --- a/qml/pages/AboutPage.qml +++ b/qml/pages/AboutPage.qml @@ -58,7 +58,7 @@ Page { } Label { - text: "Fernschreiber 0.6" + text: "Fernschreiber 0.6.1" horizontalAlignment: Text.AlignHCenter font.pixelSize: Theme.fontSizeExtraLarge anchors { diff --git a/rpm/harbour-fernschreiber.spec b/rpm/harbour-fernschreiber.spec index 06ce70a..08b197b 100644 --- a/rpm/harbour-fernschreiber.spec +++ b/rpm/harbour-fernschreiber.spec @@ -11,8 +11,8 @@ Name: harbour-fernschreiber # << macros Summary: Fernschreiber is a Telegram client for Sailfish OS -Version: 0.6 -Release: 66 +Version: 0.6.1 +Release: 1 Group: Qt/Qt License: LICENSE URL: http://werkwolf.eu/ diff --git a/rpm/harbour-fernschreiber.yaml b/rpm/harbour-fernschreiber.yaml index 88ed463..7c49528 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.6 -Release: 66 +Version: 0.6.1 +Release: 1 # 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 a3b9d23..3c7bd56 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -48,6 +48,7 @@ namespace { const QString IS_CHANNEL("is_channel"); const QString IS_VERIFIED("is_verified"); const QString IS_MARKED_AS_UNREAD("is_marked_as_unread"); + const QString IS_PINNED("is_pinned"); const QString PINNED_MESSAGE_ID("pinned_message_id"); const QString _TYPE("@type"); const QString SECRET_CHAT_ID("secret_chat_id"); @@ -77,6 +78,7 @@ public: bool isChannel() const; bool isHidden() const; bool isMarkedAsUnread() const; + bool isPinned() const; bool updateUnreadCount(int unreadCount); bool updateLastReadInboxMessageId(qlonglong messageId); QVector updateLastMessage(const QVariantMap &message); @@ -272,6 +274,11 @@ bool ChatListModel::ChatData::isMarkedAsUnread() const return chatData.value(IS_MARKED_AS_UNREAD).toBool(); } +bool ChatListModel::ChatData::isPinned() const +{ + return chatData.value(IS_PINNED).toBool(); +} + bool ChatListModel::ChatData::updateUnreadCount(int count) { const int prevUnreadCount(unreadCount()); @@ -364,6 +371,7 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) : showHiddenChats(false connect(tdLibWrapper, SIGNAL(secretChatReceived(qlonglong, QVariantMap)), this, SLOT(handleSecretChatUpdated(qlonglong, QVariantMap))); connect(tdLibWrapper, SIGNAL(chatTitleUpdated(QString, QString)), this, SLOT(handleChatTitleUpdated(QString, QString))); connect(tdLibWrapper, SIGNAL(chatIsMarkedAsUnreadUpdated(qlonglong, bool)), this, SLOT(handleChatIsMarkedAsUnreadUpdated(qlonglong, bool))); + connect(tdLibWrapper, SIGNAL(chatPinnedUpdated(qlonglong, bool)), this, SLOT(handleChatPinnedUpdated(qlonglong, bool))); connect(tdLibWrapper, SIGNAL(chatDraftMessageUpdated(qlonglong, QVariantMap, QString)), this, SLOT(handleChatDraftMessageUpdated(qlonglong, QVariantMap, QString))); // Don't start the timer until we have at least one chat @@ -399,6 +407,7 @@ QHash ChatListModel::roleNames() const roles.insert(ChatListModel::RoleIsVerified, "is_verified"); roles.insert(ChatListModel::RoleIsChannel, "is_channel"); roles.insert(ChatListModel::RoleIsMarkedAsUnread, "is_marked_as_unread"); + roles.insert(ChatListModel::RoleIsPinned, "is_pinned"); roles.insert(ChatListModel::RoleFilter, "filter"); roles.insert(ChatListModel::RoleDraftMessageDate, "draft_message_date"); roles.insert(ChatListModel::RoleDraftMessageText, "draft_message_text"); @@ -432,6 +441,7 @@ QVariant ChatListModel::data(const QModelIndex &index, int role) const case ChatListModel::RoleIsVerified: return data->verified; case ChatListModel::RoleIsChannel: return data->isChannel(); case ChatListModel::RoleIsMarkedAsUnread: return data->isMarkedAsUnread(); + case ChatListModel::RoleIsPinned: return data->isPinned(); case ChatListModel::RoleFilter: return QString(data->title() + " " + data->senderMessageText()).trimmed(); case ChatListModel::RoleDraftMessageText: return data->draftMessageText(); case ChatListModel::RoleDraftMessageDate: return data->draftMessageDate(); @@ -850,6 +860,26 @@ void ChatListModel::handleChatTitleUpdated(const QString &chatId, const QString } } +void ChatListModel::handleChatPinnedUpdated(qlonglong chatId, bool chatIsPinned) +{ + if (chatIndexMap.contains(chatId)) { + LOG("Updating chat is pinned for" << chatId << chatIsPinned); + const int chatIndex = chatIndexMap.value(chatId); + ChatData *chat = chatList.at(chatIndex); + chat->chatData.insert(IS_PINNED, chatIsPinned); + QVector changedRoles; + changedRoles.append(ChatListModel::RoleIsPinned); + const QModelIndex modelIndex(index(chatIndex)); + emit dataChanged(modelIndex, modelIndex, changedRoles); + } else { + ChatData *chat = hiddenChats.value(chatId); + if (chat) { + LOG("Updating chat is pinned for hidden chat" << chatId); + chat->chatData.insert(IS_PINNED, chatIsPinned); + } + } +} + void ChatListModel::handleChatIsMarkedAsUnreadUpdated(qlonglong chatId, bool chatIsMarkedAsUnread) { if (chatIndexMap.contains(chatId)) { diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index 51b8ce0..f70b64a 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -47,6 +47,7 @@ public: RoleIsVerified, RoleIsChannel, RoleIsMarkedAsUnread, + RoleIsPinned, RoleFilter, RoleDraftMessageText, RoleDraftMessageDate @@ -79,6 +80,7 @@ private slots: void handleGroupUpdated(qlonglong groupId); void handleSecretChatUpdated(qlonglong secretChatId, const QVariantMap &secretChat); void handleChatTitleUpdated(const QString &chatId, const QString &title); + void handleChatPinnedUpdated(qlonglong chatId, bool chatIsPinned); void handleChatIsMarkedAsUnreadUpdated(qlonglong chatId, bool chatIsMarkedAsUnread); void handleChatDraftMessageUpdated(qlonglong chatId, const QVariantMap &draftMessage, const QString &order); void handleRelativeTimeRefreshTimer(); diff --git a/src/tdlibreceiver.cpp b/src/tdlibreceiver.cpp index a367937..d05e395 100644 --- a/src/tdlibreceiver.cpp +++ b/src/tdlibreceiver.cpp @@ -38,6 +38,7 @@ namespace { const QString POSITIONS("positions"); const QString PHOTO("photo"); const QString ORDER("order"); + const QString IS_PINNED("is_pinned"); const QString BASIC_GROUP("basic_group"); const QString SUPERGROUP("supergroup"); const QString LAST_MESSAGE("last_message"); @@ -287,9 +288,12 @@ void TDLibReceiver::processUpdateChatOrder(const QVariantMap &receivedInformatio void TDLibReceiver::processUpdateChatPosition(const QVariantMap &receivedInformation) { const QString chat_id(receivedInformation.value(CHAT_ID).toString()); - const QString order(receivedInformation.value(POSITION).toMap().value(ORDER).toString()); - LOG("Chat position updated for ID" << chat_id << "new order" << order); + QVariantMap positionMap = receivedInformation.value(POSITION).toMap(); + const QString order(positionMap.value(ORDER).toString()); + bool is_pinned = positionMap.value(IS_PINNED).toBool(); + LOG("Chat position updated for ID" << chat_id << "new order" << order << "is pinned" << is_pinned); emit chatOrderUpdated(chat_id, order); + emit chatPinnedUpdated(chat_id.toLongLong(), is_pinned); } void TDLibReceiver::processUpdateChatReadInbox(const QVariantMap &receivedInformation) diff --git a/src/tdlibreceiver.h b/src/tdlibreceiver.h index 311610b..7eb8b99 100644 --- a/src/tdlibreceiver.h +++ b/src/tdlibreceiver.h @@ -49,6 +49,7 @@ signals: void unreadChatCountUpdated(const QVariantMap &chatCountInformation); void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage); void chatOrderUpdated(const QString &chatId, const QString &order); + 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 basicGroupUpdated(qlonglong groupId, const QVariantMap &groupInformation); diff --git a/src/tdlibwrapper.cpp b/src/tdlibwrapper.cpp index 3ef9049..6d2a9a3 100644 --- a/src/tdlibwrapper.cpp +++ b/src/tdlibwrapper.cpp @@ -120,6 +120,7 @@ TDLibWrapper::TDLibWrapper(AppSettings *appSettings, MceInterface *mceInterface, connect(this->tdLibReceiver, SIGNAL(chatPermissionsUpdated(QString, QVariantMap)), this, SIGNAL(chatPermissionsUpdated(QString, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(chatPhotoUpdated(qlonglong, QVariantMap)), this, SIGNAL(chatPhotoUpdated(qlonglong, QVariantMap))); connect(this->tdLibReceiver, SIGNAL(chatTitleUpdated(QString, QString)), this, SIGNAL(chatTitleUpdated(QString, QString))); + connect(this->tdLibReceiver, SIGNAL(chatPinnedUpdated(qlonglong, bool)), this, SIGNAL(chatPinnedUpdated(qlonglong, bool))); connect(this->tdLibReceiver, SIGNAL(chatPinnedMessageUpdated(qlonglong, qlonglong)), this, SIGNAL(chatPinnedMessageUpdated(qlonglong, qlonglong))); connect(this->tdLibReceiver, SIGNAL(messageIsPinnedUpdated(qlonglong, qlonglong, bool)), this, SLOT(handleMessageIsPinnedUpdated(qlonglong, qlonglong, bool))); connect(this->tdLibReceiver, SIGNAL(usersReceived(QString, QVariantList, int)), this, SIGNAL(usersReceived(QString, QVariantList, int))); @@ -1467,7 +1468,7 @@ void TDLibWrapper::setInitialParameters() QSettings hardwareSettings("/etc/hw-release", QSettings::NativeFormat); initialParameters.insert("device_model", hardwareSettings.value("NAME", "Unknown Mobile Device").toString()); initialParameters.insert("system_version", QSysInfo::prettyProductName()); - initialParameters.insert("application_version", "0.6"); + initialParameters.insert("application_version", "0.6.1"); initialParameters.insert("enable_storage_optimizer", appSettings->storageOptimizer()); // initialParameters.insert("use_test_dc", true); requestObject.insert("parameters", initialParameters); diff --git a/src/tdlibwrapper.h b/src/tdlibwrapper.h index efb0003..c777c60 100644 --- a/src/tdlibwrapper.h +++ b/src/tdlibwrapper.h @@ -210,6 +210,7 @@ signals: void unreadChatCountUpdated(const QVariantMap &chatCountInformation); void chatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage); void chatOrderUpdated(const QString &chatId, const QString &order); + 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 userUpdated(const QString &userId, const QVariantMap &userInformation);