From 1ffcfb48cacd576b1f8113f4962edcffb8beb6e7 Mon Sep 17 00:00:00 2001 From: jgibbon <99138+jgibbon@users.noreply.github.com> Date: Sat, 18 Nov 2023 22:24:27 +0100 Subject: [PATCH] Add specific unread info for higher counts of unread messages (#516) --- qml/components/PhotoTextsListItem.qml | 3 ++- qml/js/functions.js | 8 ++++++++ qml/pages/ChatPage.qml | 6 +++--- 3 files changed, 13 insertions(+), 4 deletions(-) diff --git a/qml/components/PhotoTextsListItem.qml b/qml/components/PhotoTextsListItem.qml index 62f431a..dadb1bd 100644 --- a/qml/components/PhotoTextsListItem.qml +++ b/qml/components/PhotoTextsListItem.qml @@ -1,6 +1,7 @@ import QtQuick 2.6 import Sailfish.Silica 1.0 import WerkWolf.Fernschreiber 1.0 +import "../js/functions.js" as Functions ListItem { id: chatListViewItem @@ -103,7 +104,7 @@ ListItem { anchors.centerIn: chatUnreadMessagesCountBackground visible: chatListViewItem.unreadCount > 0 opacity: isMuted ? Theme.opacityHigh : 1.0 - text: chatListViewItem.unreadCount > 99 ? "99+" : chatListViewItem.unreadCount + text: Functions.formatUnreadCount(chatListViewItem.unreadCount) } Rectangle { diff --git a/qml/js/functions.js b/qml/js/functions.js index dd6093d..7299b0d 100644 --- a/qml/js/functions.js +++ b/qml/js/functions.js @@ -27,6 +27,14 @@ function setGlobals(globals) { tdLibWrapper = globals.tdLibWrapper; appNotification = globals.appNotification; } +function formatUnreadCount(value) { + if(value < 1000) { + return value; + } else if(value > 9000) { + return '9k+'; + } + return ''+Math.floor(value / 1000)+'k'+((value % 1000)>0 ? '+' : ''); +} function getUserName(userInformation) { return ((userInformation.first_name || "") + " " + (userInformation.last_name || "")).trim(); diff --git a/qml/pages/ChatPage.qml b/qml/pages/ChatPage.qml index e126281..b816fe3 100644 --- a/qml/pages/ChatPage.qml +++ b/qml/pages/ChatPage.qml @@ -620,8 +620,8 @@ Page { onUnreadCountUpdated: { Debug.log("[ChatPage] Unread count updated, new count: ", unreadCount); chatInformation.unread_count = unreadCount; - chatUnreadMessagesItem.visible = ( !chatPage.loading && chatInformation.unread_count > 0 && chatOverviewItem.visible ); - chatUnreadMessagesCount.text = unreadCount > 99 ? "99+" : unreadCount; + chatUnreadMessagesItem.visible = ( !chatPage.loading && unreadCount > 0 && chatOverviewItem.visible ); + chatUnreadMessagesCount.text = Functions.formatUnreadCount(unreadCount) } onLastReadSentMessageUpdated: { Debug.log("[ChatPage] Updating last read sent index, new index: ", lastReadSentIndex); @@ -1430,7 +1430,7 @@ Page { color: Theme.primaryColor anchors.centerIn: chatUnreadMessagesCountBackground visible: chatUnreadMessagesItem.visible - text: chatInformation.unread_count > 99 ? "99+" : chatInformation.unread_count + text: Functions.formatUnreadCount(chatInformation.unread_count) } MouseArea { anchors.fill: parent