From c52a544e5135d6c0d28967352b53decc7df21804 Mon Sep 17 00:00:00 2001 From: "Sebastian J. Wolf" Date: Sat, 12 Sep 2020 23:22:33 +0200 Subject: [PATCH] Better notification texts --- qml/js/functions.js | 20 ++-- rpm/harbour-fernschreiber.spec | 2 +- rpm/harbour-fernschreiber.yaml | 2 +- src/notificationmanager.cpp | 57 ++++++++++- translations/harbour-fernschreiber-de.ts | 124 +++++++++++++++-------- translations/harbour-fernschreiber.ts | 118 ++++++++++++++------- 6 files changed, 232 insertions(+), 91 deletions(-) diff --git a/qml/js/functions.js b/qml/js/functions.js index 235462f..9610f65 100644 --- a/qml/js/functions.js +++ b/qml/js/functions.js @@ -38,58 +38,58 @@ function getMessageText(message, simple) { if (message.content.caption.text !== "") { return simple ? qsTr("Picture: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) } else { - return simple ? qsTr("shared a picture") : ""; + return simple ? qsTr("sent a picture") : ""; } } if (message.content['@type'] === 'messageVideo') { if (message.content.caption.text !== "") { return simple ? qsTr("Video: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) } else { - return simple ? qsTr("shared a video") : ""; + return simple ? qsTr("sent a video") : ""; } } if (message.content['@type'] === 'messageAnimation') { if (message.content.caption.text !== "") { return simple ? qsTr("Animation: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) } else { - return simple ? qsTr("shared an animation") : ""; + return simple ? qsTr("sent an animation") : ""; } } if (message.content['@type'] === 'messageAudio') { if (message.content.caption.text !== "") { return simple ? qsTr("Audio: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) } else { - return simple ? qsTr("shared an audio") : ""; + return simple ? qsTr("sent an audio") : ""; } } if (message.content['@type'] === 'messageVoiceNote') { if (message.content.caption.text !== "") { return simple ? qsTr("Voice Note: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) } else { - return simple ? qsTr("shared a voice note") : ""; + return simple ? qsTr("sent a voice note") : ""; } } if (message.content['@type'] === 'messageDocument') { if (message.content.document.file_name !== "") { return simple ? qsTr("Document: %1").arg(message.content.document.file_name) : message.content.document.file_name } else { - return simple ? qsTr("shared a document") : ""; + return simple ? qsTr("sent a document") : ""; } } if (message.content['@type'] === 'messageLocation') { - return qsTr("shared their location"); + return qsTr("sent a location"); } if (message.content['@type'] === 'messageContactRegistered') { return qsTr("has registered with Telegram"); } if (message.content['@type'] === 'messageChatJoinByLink') { - return qsTr("joined this chat."); + return qsTr("joined this chat"); } if (message.content['@type'] === 'messageChatAddMembers') { - return qsTr("was added to this chat."); + return qsTr("was added to this chat"); } if (message.content['@type'] === 'messageChatDeleteMember') { - return qsTr("left this chat."); + return qsTr("left this chat"); } return qsTr("Unsupported message: %1").arg(message.content['@type'].substring(7)); } diff --git a/rpm/harbour-fernschreiber.spec b/rpm/harbour-fernschreiber.spec index 1cc5925..82745a2 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.1 -Release: 2 +Release: 3 Group: Qt/Qt License: LICENSE URL: http://werkwolf.eu/ diff --git a/rpm/harbour-fernschreiber.yaml b/rpm/harbour-fernschreiber.yaml index 0b965f8..790dd04 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.1 -Release: 2 +Release: 3 # 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/notificationmanager.cpp b/src/notificationmanager.cpp index e306d38..102938e 100644 --- a/src/notificationmanager.cpp +++ b/src/notificationmanager.cpp @@ -23,6 +23,7 @@ #include #include #include +#include NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent) { @@ -119,16 +120,32 @@ QVariantMap NotificationManager::sendNotification(const QString &chatId, const Q qDebug() << "[NotificationManager] Sending notification" << notificationInformation.value("id").toString(); QVariantMap chatInformation = this->chatMap.value(chatId).toMap(); + QString chatType = chatInformation.value("type").toMap().value("@type").toString(); + bool addAuthor = false; + if (chatType == "chatTypeBasicGroup" || ( chatType == "chatTypeSupergroup" && !chatInformation.value("type").toMap().value("@is_channel").toBool() )) { + addAuthor = true; + } QVariantMap updatedNotificationInformation = notificationInformation; QUrl appIconUrl = SailfishApp::pathTo("images/fernschreiber-notification.png"); + QVariantMap messageMap = notificationInformation.value("type").toMap().value("message").toMap(); Notification nemoNotification; nemoNotification.setAppName("Fernschreiber"); nemoNotification.setAppIcon(appIconUrl.toLocalFile()); nemoNotification.setSummary(chatInformation.value("title").toString()); nemoNotification.setCategory("x-nemo.messaging.im"); + nemoNotification.setTimestamp(QDateTime::fromMSecsSinceEpoch(messageMap.value("date").toLongLong() * 1000)); if (activeNotifications.isEmpty()) { - nemoNotification.setBody(this->getNotificationText(notificationInformation.value("type").toMap().value("message").toMap().value("content").toMap())); + QString notificationBody; + if (addAuthor) { + QVariantMap authorInformation = tdLibWrapper->getUserInformation(messageMap.value("sender_user_id").toString()); + QString firstName = authorInformation.value("first_name").toString(); + QString lastName = authorInformation.value("last_name").toString(); + QString fullName = firstName + " " + lastName; + notificationBody = notificationBody + fullName.trimmed() + ": "; + } + notificationBody = notificationBody + this->getNotificationText(messageMap.value("content").toMap()); + nemoNotification.setBody(notificationBody); } else { nemoNotification.setReplacesId(activeNotifications.first().toMap().value("replaces_id").toUInt()); nemoNotification.setBody(tr("%1 unread messages").arg(activeNotifications.size() + 1)); @@ -150,5 +167,41 @@ void NotificationManager::removeNotification(const QVariantMap ¬ificationInfo QString NotificationManager::getNotificationText(const QVariantMap ¬ificationContent) { qDebug() << "[NotificationManager] Getting notification text from content" << notificationContent; - return notificationContent.value("text").toMap().value("text").toString(); + + QString contentType = notificationContent.value("@type").toString(); + + if (contentType == "messageText") { + return notificationContent.value("text").toMap().value("text").toString(); + } + if (contentType == "messagePhoto") { + return tr("sent a picture"); + } + if (contentType == "messageVideo") { + return tr("sent a video"); + } + if (contentType == "messageAnimation") { + return tr("sent an animation"); + } + if (contentType == "messageVoiceNote") { + return tr("sent a voice note"); + } + if (contentType == "messageDocument") { + return tr("sent a document"); + } + if (contentType == "messageLocation") { + return tr("sent a location"); + } + if (contentType == "messageContactRegistered") { + return tr("has registered with Telegram"); + } + if (contentType == "messageChatJoinByLink") { + return tr("joined this chat"); + } + if (contentType == "messageChatAddMembers") { + return tr("was added to this chat"); + } + if (contentType == "messageChatDeleteMember") { + return tr("left this chat"); + } + return tr("Unsupported message: %1").arg(contentType.mid(7)); } diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index 1213017..05a055e 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -41,7 +41,7 @@ This project uses the Telegram Database Library (TDLib). Thanks for making it available under the conditions of the Boost Software License 1.0! - Dieses Projekt nutzt die Telegram Database Library (TDLib). Vielen Dank dafür, dass sie unter den Bedingungen der Boost Software License 1.0 verfügbar gemacht wurde! + Dieses Projekt nutzt die Telegram Database Library (TDLib). Vielen Dank dafür, dass sie unter den Bedingungen der Boost Software License 1.0 verfügbar gemacht wurde! Open Telegram Database Library on GitHub @@ -273,7 +273,51 @@ NotificationManager %1 unread messages - + %1 ungelesene Nachrichten + + + sent a picture + hat ein Bild geschickt + + + sent a video + hat ein Video geschickt + + + sent an animation + hat eine Animation geschickt + + + sent a voice note + hat eine Sprachnachricht geschickt + + + sent a document + hat ein Dokument geschickt + + + sent a location + hat einen Ort geschickt + + + has registered with Telegram + hat sich bei Telegram angemeldet + + + joined this chat + ist diesem Chat beigetreten + + + was added to this chat + wurde diesem Chat hinzugefügt + + + left this chat + hat diesen Chat verlassen + + + Unsupported message: %1 + Nicht unterstützte Nachricht: %1 @@ -348,18 +392,6 @@ Sticker: %1 Sticker: %1 - - was added to this chat. - wurde diesem Chat hinzugefügt. - - - joined this chat. - ist diesem Chat beigetreten. - - - left this chat. - hat diesen Chat verlassen. - Audio: %1 Audio: %1 @@ -368,34 +400,10 @@ Voice Note: %1 Sprachnachricht: %1 - - shared a picture - hat ein Bild geteilt - - - shared a video - hat ein Video geteilt - - - shared an audio - hat ein Audio geteilt - - - shared a voice note - hat eine Sprachnachricht geteilt - - - shared their location - hat die Position geteilt - Animation: %1 Animation: %1 - - shared an animation - hat eine Animation geteilt - Unsupported message: %1 Nicht unterstützte Nachricht: %1 @@ -405,8 +413,44 @@ Dokument: %1 - shared a document - hat ein Dokument geteilt + sent a picture + hat ein Bild geschickt + + + sent a video + hat ein Video geschickt + + + sent an animation + hat eine Animation geschickt + + + sent an audio + hat eine Audiodatei geschickt + + + sent a voice note + hat eine Sprachnachricht geschickt + + + sent a document + hat ein Dokument geschickt + + + sent a location + hat einen Ort geschickt + + + joined this chat + ist diesem Chat beigetreten + + + was added to this chat + wurde diesem Chat hinzugefügt + + + left this chat + hat diesen Chat verlassen diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 52cae7e..f847d9a 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -275,6 +275,50 @@ %1 unread messages + + sent a picture + + + + sent a video + + + + sent an animation + + + + sent a voice note + + + + sent a document + + + + sent a location + + + + has registered with Telegram + + + + joined this chat + + + + was added to this chat + + + + left this chat + + + + Unsupported message: %1 + + OverviewPage @@ -348,18 +392,6 @@ Sticker: %1 - - was added to this chat. - - - - joined this chat. - - - - left this chat. - - Audio: %1 @@ -368,34 +400,10 @@ Voice Note: %1 - - shared a picture - - - - shared a video - - - - shared an audio - - - - shared a voice note - - - - shared their location - - Animation: %1 - - shared an animation - - Unsupported message: %1 @@ -405,7 +413,43 @@ - shared a document + sent a picture + + + + sent a video + + + + sent an animation + + + + sent an audio + + + + sent a voice note + + + + sent a document + + + + sent a location + + + + joined this chat + + + + was added to this chat + + + + left this chat