Better notification texts
This commit is contained in:
parent
7dd8e07a39
commit
c52a544e51
6 changed files with 232 additions and 91 deletions
|
@ -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));
|
||||
}
|
||||
|
|
|
@ -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/
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -23,6 +23,7 @@
|
|||
#include <QDebug>
|
||||
#include <QListIterator>
|
||||
#include <QUrl>
|
||||
#include <QDateTime>
|
||||
|
||||
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));
|
||||
}
|
||||
|
|
|
@ -41,7 +41,7 @@
|
|||
</message>
|
||||
<message>
|
||||
<source>This project uses the Telegram Database Library (TDLib). Thanks for making it available under the conditions of the Boost Software License 1.0!</source>
|
||||
<translation>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! </translation>
|
||||
<translation>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!</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Open Telegram Database Library on GitHub</source>
|
||||
|
@ -273,7 +273,51 @@
|
|||
<name>NotificationManager</name>
|
||||
<message>
|
||||
<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>
|
||||
</context>
|
||||
<context>
|
||||
|
@ -348,18 +392,6 @@
|
|||
<source>Sticker: %1</source>
|
||||
<translation>Sticker: %1</translation>
|
||||
</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>
|
||||
<source>Audio: %1</source>
|
||||
<translation>Audio: %1</translation>
|
||||
|
@ -368,34 +400,10 @@
|
|||
<source>Voice Note: %1</source>
|
||||
<translation>Sprachnachricht: %1</translation>
|
||||
</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>
|
||||
<source>Animation: %1</source>
|
||||
<translation>Animation: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>shared an animation</source>
|
||||
<translation>hat eine Animation geteilt</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported message: %1</source>
|
||||
<translation>Nicht unterstützte Nachricht: %1</translation>
|
||||
|
@ -405,8 +413,44 @@
|
|||
<translation>Dokument: %1</translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>shared a document</source>
|
||||
<translation>hat ein Dokument geteilt</translation>
|
||||
<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 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>
|
||||
</context>
|
||||
</TS>
|
||||
|
|
|
@ -275,6 +275,50 @@
|
|||
<source>%1 unread messages</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<name>OverviewPage</name>
|
||||
|
@ -348,18 +392,6 @@
|
|||
<source>Sticker: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<source>Audio: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -368,34 +400,10 @@
|
|||
<source>Voice Note: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
<source>Animation: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>shared an animation</source>
|
||||
<translation type="unfinished"></translation>
|
||||
</message>
|
||||
<message>
|
||||
<source>Unsupported message: %1</source>
|
||||
<translation type="unfinished"></translation>
|
||||
|
@ -405,7 +413,43 @@
|
|||
<translation type="unfinished"></translation>
|
||||
</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>
|
||||
</message>
|
||||
</context>
|
||||
|
|
Loading…
Reference in a new issue