Better notification texts

This commit is contained in:
Sebastian J. Wolf 2020-09-12 23:22:33 +02:00
parent 7dd8e07a39
commit c52a544e51
6 changed files with 232 additions and 91 deletions

View file

@ -38,58 +38,58 @@ function getMessageText(message, simple) {
if (message.content.caption.text !== "") { if (message.content.caption.text !== "") {
return simple ? qsTr("Picture: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) return simple ? qsTr("Picture: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption)
} else { } else {
return simple ? qsTr("shared a picture") : ""; return simple ? qsTr("sent a picture") : "";
} }
} }
if (message.content['@type'] === 'messageVideo') { if (message.content['@type'] === 'messageVideo') {
if (message.content.caption.text !== "") { if (message.content.caption.text !== "") {
return simple ? qsTr("Video: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) return simple ? qsTr("Video: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption)
} else { } else {
return simple ? qsTr("shared a video") : ""; return simple ? qsTr("sent a video") : "";
} }
} }
if (message.content['@type'] === 'messageAnimation') { if (message.content['@type'] === 'messageAnimation') {
if (message.content.caption.text !== "") { if (message.content.caption.text !== "") {
return simple ? qsTr("Animation: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) return simple ? qsTr("Animation: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption)
} else { } else {
return simple ? qsTr("shared an animation") : ""; return simple ? qsTr("sent an animation") : "";
} }
} }
if (message.content['@type'] === 'messageAudio') { if (message.content['@type'] === 'messageAudio') {
if (message.content.caption.text !== "") { if (message.content.caption.text !== "") {
return simple ? qsTr("Audio: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) return simple ? qsTr("Audio: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption)
} else { } else {
return simple ? qsTr("shared an audio") : ""; return simple ? qsTr("sent an audio") : "";
} }
} }
if (message.content['@type'] === 'messageVoiceNote') { if (message.content['@type'] === 'messageVoiceNote') {
if (message.content.caption.text !== "") { if (message.content.caption.text !== "") {
return simple ? qsTr("Voice Note: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption) return simple ? qsTr("Voice Note: %1").arg(message.content.caption.text) : enhanceMessageText(message.content.caption)
} else { } else {
return simple ? qsTr("shared a voice note") : ""; return simple ? qsTr("sent a voice note") : "";
} }
} }
if (message.content['@type'] === 'messageDocument') { if (message.content['@type'] === 'messageDocument') {
if (message.content.document.file_name !== "") { if (message.content.document.file_name !== "") {
return simple ? qsTr("Document: %1").arg(message.content.document.file_name) : message.content.document.file_name return simple ? qsTr("Document: %1").arg(message.content.document.file_name) : message.content.document.file_name
} else { } else {
return simple ? qsTr("shared a document") : ""; return simple ? qsTr("sent a document") : "";
} }
} }
if (message.content['@type'] === 'messageLocation') { if (message.content['@type'] === 'messageLocation') {
return qsTr("shared their location"); return qsTr("sent a location");
} }
if (message.content['@type'] === 'messageContactRegistered') { if (message.content['@type'] === 'messageContactRegistered') {
return qsTr("has registered with Telegram"); return qsTr("has registered with Telegram");
} }
if (message.content['@type'] === 'messageChatJoinByLink') { if (message.content['@type'] === 'messageChatJoinByLink') {
return qsTr("joined this chat."); return qsTr("joined this chat");
} }
if (message.content['@type'] === 'messageChatAddMembers') { if (message.content['@type'] === 'messageChatAddMembers') {
return qsTr("was added to this chat."); return qsTr("was added to this chat");
} }
if (message.content['@type'] === 'messageChatDeleteMember') { 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)); return qsTr("Unsupported message: %1").arg(message.content['@type'].substring(7));
} }

View file

@ -12,7 +12,7 @@ Name: harbour-fernschreiber
Summary: Fernschreiber is a Telegram client for Sailfish OS Summary: Fernschreiber is a Telegram client for Sailfish OS
Version: 0.1 Version: 0.1
Release: 2 Release: 3
Group: Qt/Qt Group: Qt/Qt
License: LICENSE License: LICENSE
URL: http://werkwolf.eu/ URL: http://werkwolf.eu/

View file

@ -1,7 +1,7 @@
Name: harbour-fernschreiber Name: harbour-fernschreiber
Summary: Fernschreiber is a Telegram client for Sailfish OS Summary: Fernschreiber is a Telegram client for Sailfish OS
Version: 0.1 Version: 0.1
Release: 2 Release: 3
# The contents of the Group field should be one of the groups listed here: # The contents of the Group field should be one of the groups listed here:
# https://github.com/mer-tools/spectacle/blob/master/data/GROUPS # https://github.com/mer-tools/spectacle/blob/master/data/GROUPS
Group: Qt/Qt Group: Qt/Qt

View file

@ -23,6 +23,7 @@
#include <QDebug> #include <QDebug>
#include <QListIterator> #include <QListIterator>
#include <QUrl> #include <QUrl>
#include <QDateTime>
NotificationManager::NotificationManager(TDLibWrapper *tdLibWrapper, QObject *parent) : QObject(parent) 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(); qDebug() << "[NotificationManager] Sending notification" << notificationInformation.value("id").toString();
QVariantMap chatInformation = this->chatMap.value(chatId).toMap(); 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; QVariantMap updatedNotificationInformation = notificationInformation;
QUrl appIconUrl = SailfishApp::pathTo("images/fernschreiber-notification.png"); QUrl appIconUrl = SailfishApp::pathTo("images/fernschreiber-notification.png");
QVariantMap messageMap = notificationInformation.value("type").toMap().value("message").toMap();
Notification nemoNotification; Notification nemoNotification;
nemoNotification.setAppName("Fernschreiber"); nemoNotification.setAppName("Fernschreiber");
nemoNotification.setAppIcon(appIconUrl.toLocalFile()); nemoNotification.setAppIcon(appIconUrl.toLocalFile());
nemoNotification.setSummary(chatInformation.value("title").toString()); nemoNotification.setSummary(chatInformation.value("title").toString());
nemoNotification.setCategory("x-nemo.messaging.im"); nemoNotification.setCategory("x-nemo.messaging.im");
nemoNotification.setTimestamp(QDateTime::fromMSecsSinceEpoch(messageMap.value("date").toLongLong() * 1000));
if (activeNotifications.isEmpty()) { 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 { } else {
nemoNotification.setReplacesId(activeNotifications.first().toMap().value("replaces_id").toUInt()); nemoNotification.setReplacesId(activeNotifications.first().toMap().value("replaces_id").toUInt());
nemoNotification.setBody(tr("%1 unread messages").arg(activeNotifications.size() + 1)); nemoNotification.setBody(tr("%1 unread messages").arg(activeNotifications.size() + 1));
@ -150,5 +167,41 @@ void NotificationManager::removeNotification(const QVariantMap &notificationInfo
QString NotificationManager::getNotificationText(const QVariantMap &notificationContent) QString NotificationManager::getNotificationText(const QVariantMap &notificationContent)
{ {
qDebug() << "[NotificationManager] Getting notification text from content" << notificationContent; qDebug() << "[NotificationManager] Getting notification text from content" << notificationContent;
QString contentType = notificationContent.value("@type").toString();
if (contentType == "messageText") {
return notificationContent.value("text").toMap().value("text").toString(); 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));
}

View file

@ -273,7 +273,51 @@
<name>NotificationManager</name> <name>NotificationManager</name>
<message> <message>
<source>%1 unread messages</source> <source>%1 unread messages</source>
<translation type="unfinished"></translation> <translation>%1 ungelesene Nachrichten</translation>
</message>
<message>
<source>sent a picture</source>
<translation>hat ein Bild geschickt</translation>
</message>
<message>
<source>sent a video</source>
<translation>hat ein Video geschickt</translation>
</message>
<message>
<source>sent an animation</source>
<translation>hat eine Animation geschickt</translation>
</message>
<message>
<source>sent a voice note</source>
<translation>hat eine Sprachnachricht geschickt</translation>
</message>
<message>
<source>sent a document</source>
<translation>hat ein Dokument geschickt</translation>
</message>
<message>
<source>sent a location</source>
<translation>hat einen Ort geschickt</translation>
</message>
<message>
<source>has registered with Telegram</source>
<translation>hat sich bei Telegram angemeldet</translation>
</message>
<message>
<source>joined this chat</source>
<translation>ist diesem Chat beigetreten</translation>
</message>
<message>
<source>was added to this chat</source>
<translation>wurde diesem Chat hinzugefügt</translation>
</message>
<message>
<source>left this chat</source>
<translation>hat diesen Chat verlassen</translation>
</message>
<message>
<source>Unsupported message: %1</source>
<translation>Nicht unterstützte Nachricht: %1</translation>
</message> </message>
</context> </context>
<context> <context>
@ -348,18 +392,6 @@
<source>Sticker: %1</source> <source>Sticker: %1</source>
<translation>Sticker: %1</translation> <translation>Sticker: %1</translation>
</message> </message>
<message>
<source>was added to this chat.</source>
<translation>wurde diesem Chat hinzugefügt.</translation>
</message>
<message>
<source>joined this chat.</source>
<translation>ist diesem Chat beigetreten.</translation>
</message>
<message>
<source>left this chat.</source>
<translation>hat diesen Chat verlassen.</translation>
</message>
<message> <message>
<source>Audio: %1</source> <source>Audio: %1</source>
<translation>Audio: %1</translation> <translation>Audio: %1</translation>
@ -368,34 +400,10 @@
<source>Voice Note: %1</source> <source>Voice Note: %1</source>
<translation>Sprachnachricht: %1</translation> <translation>Sprachnachricht: %1</translation>
</message> </message>
<message>
<source>shared a picture</source>
<translation>hat ein Bild geteilt</translation>
</message>
<message>
<source>shared a video</source>
<translation>hat ein Video geteilt</translation>
</message>
<message>
<source>shared an audio</source>
<translation>hat ein Audio geteilt</translation>
</message>
<message>
<source>shared a voice note</source>
<translation>hat eine Sprachnachricht geteilt</translation>
</message>
<message>
<source>shared their location</source>
<translation>hat die Position geteilt</translation>
</message>
<message> <message>
<source>Animation: %1</source> <source>Animation: %1</source>
<translation>Animation: %1</translation> <translation>Animation: %1</translation>
</message> </message>
<message>
<source>shared an animation</source>
<translation>hat eine Animation geteilt</translation>
</message>
<message> <message>
<source>Unsupported message: %1</source> <source>Unsupported message: %1</source>
<translation>Nicht unterstützte Nachricht: %1</translation> <translation>Nicht unterstützte Nachricht: %1</translation>
@ -405,8 +413,44 @@
<translation>Dokument: %1</translation> <translation>Dokument: %1</translation>
</message> </message>
<message> <message>
<source>shared a document</source> <source>sent a picture</source>
<translation>hat ein Dokument geteilt</translation> <translation>hat ein Bild geschickt</translation>
</message>
<message>
<source>sent a video</source>
<translation>hat ein Video geschickt</translation>
</message>
<message>
<source>sent an animation</source>
<translation>hat eine Animation geschickt</translation>
</message>
<message>
<source>sent an audio</source>
<translation>hat eine Audiodatei geschickt</translation>
</message>
<message>
<source>sent a voice note</source>
<translation>hat eine Sprachnachricht geschickt</translation>
</message>
<message>
<source>sent a document</source>
<translation>hat ein Dokument geschickt</translation>
</message>
<message>
<source>sent a location</source>
<translation>hat einen Ort geschickt</translation>
</message>
<message>
<source>joined this chat</source>
<translation>ist diesem Chat beigetreten</translation>
</message>
<message>
<source>was added to this chat</source>
<translation>wurde diesem Chat hinzugefügt</translation>
</message>
<message>
<source>left this chat</source>
<translation>hat diesen Chat verlassen</translation>
</message> </message>
</context> </context>
</TS> </TS>

View file

@ -275,6 +275,50 @@
<source>%1 unread messages</source> <source>%1 unread messages</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>sent a picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent a video</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent an animation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent a voice note</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent a document</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent a location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>has registered with Telegram</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>joined this chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>was added to this chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>left this chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>Unsupported message: %1</source>
<translation type="unfinished"></translation>
</message>
</context> </context>
<context> <context>
<name>OverviewPage</name> <name>OverviewPage</name>
@ -348,18 +392,6 @@
<source>Sticker: %1</source> <source>Sticker: %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>was added to this chat.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>joined this chat.</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>left this chat.</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Audio: %1</source> <source>Audio: %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -368,34 +400,10 @@
<source>Voice Note: %1</source> <source>Voice Note: %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>shared a picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>shared a video</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>shared an audio</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>shared a voice note</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>shared their location</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Animation: %1</source> <source>Animation: %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message>
<source>shared an animation</source>
<translation type="unfinished"></translation>
</message>
<message> <message>
<source>Unsupported message: %1</source> <source>Unsupported message: %1</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
@ -405,7 +413,43 @@
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
<message> <message>
<source>shared a document</source> <source>sent a picture</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent a video</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent an animation</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent an audio</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent a voice note</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent a document</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>sent a location</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>joined this chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>was added to this chat</source>
<translation type="unfinished"></translation>
</message>
<message>
<source>left this chat</source>
<translation type="unfinished"></translation> <translation type="unfinished"></translation>
</message> </message>
</context> </context>