diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index a3056dc..cc23235 100644 --- a/harbour-fernschreiber.pro +++ b/harbour-fernschreiber.pro @@ -23,6 +23,7 @@ SOURCES += src/harbour-fernschreiber.cpp \ src/chatmodel.cpp \ src/dbusadaptor.cpp \ src/dbusinterface.cpp \ + src/fernschreiberutils.cpp \ src/notificationmanager.cpp \ src/processlauncher.cpp \ src/tdlibreceiver.cpp \ @@ -100,6 +101,7 @@ HEADERS += \ src/chatmodel.h \ src/dbusadaptor.h \ src/dbusinterface.h \ + src/fernschreiberutils.h \ src/notificationmanager.h \ src/processlauncher.h \ src/tdlibreceiver.h \ diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index 1371f77..16d783d 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -18,6 +18,7 @@ */ #include "chatlistmodel.h" +#include "fernschreiberutils.h" #include #define LOG(x) qDebug() << "[ChatListModel]" << x @@ -61,7 +62,7 @@ public: RoleIsChannel }; - ChatData(const QVariantMap &data); + ChatData(const QVariantMap &data, const QVariantMap &userInformation); int compareTo(const ChatData *chat) const; bool setOrder(const QString &order); @@ -82,13 +83,15 @@ public: QVariantMap chatData; QString chatId; qlonglong order; + QVariantMap userInformation; }; -ChatListModel::ChatData::ChatData(const QVariantMap &data) : +ChatListModel::ChatData::ChatData(const QVariantMap &data, const QVariantMap &userInformation) : chatData(data), chatId(data.value(ID).toString()), order(data.value(ORDER).toLongLong()) { + this->userInformation = userInformation; } int ChatListModel::ChatData::compareTo(const ChatData *other) const @@ -148,8 +151,7 @@ qlonglong ChatListModel::ChatData::senderMessageDate() const QString ChatListModel::ChatData::senderMessageText() const { - const QVariantMap content(lastMessage(CONTENT).toMap()); - return (content.value(TYPE).toString() == TYPE_MESSAGE_TEXT) ? content.value(TEXT).toMap().value(TEXT).toString() : QString(); + return FernschreiberUtils::getMessageShortText(lastMessage(CONTENT).toMap(), this->userInformation.value(ID).toLongLong() == senderUserId()); } bool ChatListModel::ChatData::isChannel() const @@ -307,7 +309,7 @@ int ChatListModel::updateChatOrder(int chatIndex) void ChatListModel::handleChatDiscovered(const QString &chatId, const QVariantMap &chatToBeAdded) { - ChatData *chat = new ChatData(chatToBeAdded); + ChatData *chat = new ChatData(chatToBeAdded, tdLibWrapper->getUserInformation()); const int n = chatList.size(); int chatIndex; for (chatIndex = 0; chatIndex < n && chat->compareTo(chatList.at(chatIndex)) >= 0; chatIndex++); diff --git a/src/fernschreiberutils.cpp b/src/fernschreiberutils.cpp new file mode 100644 index 0000000..2a9ed3d --- /dev/null +++ b/src/fernschreiberutils.cpp @@ -0,0 +1,55 @@ +#include "fernschreiberutils.h" + +#include +#include + +FernschreiberUtils::FernschreiberUtils(QObject *parent) : QObject(parent) +{ + +} + +QString FernschreiberUtils::getMessageShortText(const QVariantMap &messageContent, const bool &myself) +{ + QString contentType = messageContent.value("@type").toString(); + + if (contentType == "messageText") { + return messageContent.value("text").toMap().value("text").toString(); + } + if (contentType == "messageSticker") { + return tr("Sticker: %1").arg(messageContent.value("sticker").toMap().value("emoji").toString()); + } + if (contentType == "messagePhoto") { + return myself ? tr("sent a picture", "myself") : tr("sent a picture"); + } + if (contentType == "messageVideo") { + return myself ? tr("sent a video", "myself") : tr("sent a video"); + } + if (contentType == "messageAnimation") { + return myself ? tr("sent an animation", "myself") : tr("sent an animation"); + } + if (contentType == "messageVoiceNote") { + return myself ? tr("sent a voice note", "myself") : tr("sent a voice note"); + } + if (contentType == "messageDocument") { + return myself ? tr("sent a document", "myself") : tr("sent a document"); + } + if (contentType == "messageLocation") { + return myself ? tr("sent a location", "myself") : tr("sent a location"); + } + if (contentType == "messageVenue") { + return myself ? tr("sent a venue", "myself") : tr("sent a venue"); + } + if (contentType == "messageContactRegistered") { + return myself ? tr("have registered with Telegram", "myself") : tr("has registered with Telegram"); + } + if (contentType == "messageChatJoinByLink") { + return myself ? tr("joined this chat", "myself") : tr("joined this chat"); + } + if (contentType == "messageChatAddMembers") { + return myself ? tr("were added to this chat", "myself") : tr("was added to this chat"); + } + if (contentType == "messageChatDeleteMember") { + return myself ? tr("left this chat", "myself") : tr("left this chat"); + } + return tr("Unsupported message: %1").arg(contentType.mid(7)); +} diff --git a/src/fernschreiberutils.h b/src/fernschreiberutils.h new file mode 100644 index 0000000..10858f1 --- /dev/null +++ b/src/fernschreiberutils.h @@ -0,0 +1,19 @@ +#ifndef FERNSCHREIBERUTILS_H +#define FERNSCHREIBERUTILS_H + +#include + +class FernschreiberUtils : public QObject +{ + Q_OBJECT +public: + explicit FernschreiberUtils(QObject *parent = nullptr); + + static QString getMessageShortText(const QVariantMap &messageContent, const bool &myself); + +signals: + +public slots: +}; + +#endif // FERNSCHREIBERUTILS_H diff --git a/src/notificationmanager.cpp b/src/notificationmanager.cpp index 61f16f0..f6ca9f3 100644 --- a/src/notificationmanager.cpp +++ b/src/notificationmanager.cpp @@ -18,6 +18,7 @@ */ #include "notificationmanager.h" +#include "fernschreiberutils.h" #include #include #include @@ -219,42 +220,7 @@ QString NotificationManager::getNotificationText(const QVariantMap ¬ification { 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(); - } - 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)); + return FernschreiberUtils::getMessageShortText(notificationContent, false); } void NotificationManager::controlLedNotification(const bool &enabled) diff --git a/translations/harbour-fernschreiber-de.ts b/translations/harbour-fernschreiber-de.ts index d7b3c66..ece55d8 100644 --- a/translations/harbour-fernschreiber-de.ts +++ b/translations/harbour-fernschreiber-de.ts @@ -228,6 +228,116 @@ Dokument öffnen + + FernschreiberUtils + + sent a picture + myself + haben ein Bild geschickt + + + sent a picture + hat ein Bild geschickt + + + sent a video + myself + haben ein Video geschickt + + + sent a video + hat ein Video geschickt + + + sent an animation + myself + haben eine Animation geschickt + + + sent an animation + hat eine Animation geschickt + + + sent a voice note + hat eine Sprachnachricht geschickt + + + sent a document + myself + haben ein Dokument geschickt + + + sent a document + hat ein Dokument geschickt + + + sent a location + myself + haben einen Standort geschickt + + + sent a location + hat einen Standort geschickt + + + have registered with Telegram + myself + haben sich bei Telegram angemeldet + + + has registered with Telegram + hat sich bei Telegram angemeldet + + + joined this chat + myself + sind diesem Chat beigetreten + + + joined this chat + ist diesem Chat beigetreten + + + were added to this chat + myself + wurden diesem Chat hinzugefügt + + + was added to this chat + wurde diesem Chat hinzugefügt + + + left this chat + myself + haben diesen Chat verlassen + + + left this chat + hat diesen Chat verlassen + + + Unsupported message: %1 + Nicht unterstützte Nachricht: %1 + + + Sticker: %1 + Sticker: %1 + + + sent a voice note + myself + haben eine Sprachnachricht geschickt + + + sent a venue + myself + haben einen Ort geschickt + + + sent a venue + hat einen Ort geschickt + + ImagePage @@ -297,7 +407,7 @@ LocationPreview Install Pure Maps to inspect this location. - Installieren Sie Pure Maps, um diesen Ort zu erkunden + Installieren Sie Pure Maps, um diesen Ort zu erkunden. @@ -306,50 +416,6 @@ %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 - OverviewPage diff --git a/translations/harbour-fernschreiber-es.ts b/translations/harbour-fernschreiber-es.ts index b8575e4..23a9cd8 100644 --- a/translations/harbour-fernschreiber-es.ts +++ b/translations/harbour-fernschreiber-es.ts @@ -228,6 +228,116 @@ Abrir Documento + + FernschreiberUtils + + sent a picture + myself + envió una imagen + + + sent a picture + envió una imagen + + + sent a video + myself + envió un video + + + sent a video + envió un video + + + sent an animation + myself + envió una animación + + + sent an animation + envió una animación + + + sent a voice note + envió una nota de voz + + + sent a document + myself + envió un documento + + + sent a document + envió un documento + + + sent a location + myself + envió una ubicación + + + sent a location + envió una ubicación + + + have registered with Telegram + myself + + + + has registered with Telegram + te has registrado en Telegram + + + joined this chat + myself + se unió a esta charla + + + joined this chat + se unió a esta charla + + + were added to this chat + myself + + + + was added to this chat + se añadió a esta charla + + + left this chat + myself + dejó esta charla + + + left this chat + dejó esta charla + + + Unsupported message: %1 + Mensaje no soportado: %1 + + + Sticker: %1 + Pegatina: %1 + + + sent a voice note + myself + envió una nota de voz + + + sent a venue + myself + + + + sent a venue + + + ImagePage @@ -306,50 +416,6 @@ %1 unread messages %1 mensajes no leídos - - sent a picture - envió una imagen - - - sent a video - envió un video - - - sent an animation - envió una animación - - - sent a voice note - envió una nota de voz - - - sent a document - envió un documento - - - sent a location - envió una ubicación - - - has registered with Telegram - te has registrado en Telegram - - - joined this chat - se unió a esta charla - - - was added to this chat - se añadió a esta charla - - - left this chat - dejó esta charla - - - Unsupported message: %1 - Mensaje no soportado: %1 - OverviewPage diff --git a/translations/harbour-fernschreiber-hu.ts b/translations/harbour-fernschreiber-hu.ts index 3111587..55a1644 100644 --- a/translations/harbour-fernschreiber-hu.ts +++ b/translations/harbour-fernschreiber-hu.ts @@ -228,6 +228,116 @@ Dokumentum megyitása + + FernschreiberUtils + + sent a picture + myself + képet küldött + + + sent a picture + képet küldött + + + sent a video + myself + videót küldött + + + sent a video + videót küldött + + + sent an animation + myself + animációt küldött + + + sent an animation + animációt küldött + + + sent a voice note + hangüzenetet küldött + + + sent a document + myself + dokumentumot küldött + + + sent a document + dokumentumot küldött + + + sent a location + myself + helyzetmeghatározó információt küldött + + + sent a location + helyzetmeghatározó információt küldött + + + have registered with Telegram + myself + + + + has registered with Telegram + regisztrált a Telegram-al + + + joined this chat + myself + csatlakozott a csevegéshez + + + joined this chat + csatlakozott a csevegéshez + + + were added to this chat + myself + + + + was added to this chat + hozzáadva a csevegéshez + + + left this chat + myself + kilépett a csevegésből + + + left this chat + kilépett a csevegésből + + + Unsupported message: %1 + Nem támogatott üzenet: %1 + + + Sticker: %1 + Matrica: %1 + + + sent a voice note + myself + hangüzenetet küldött + + + sent a venue + myself + + + + sent a venue + + + ImagePage @@ -306,50 +416,6 @@ %1 unread messages %1 olvasatlan üzenet - - sent a picture - képet küldött - - - sent a video - videót küldött - - - sent an animation - animációt küldött - - - sent a voice note - hangüzenetet küldött - - - sent a document - dokumentumok küldött - - - sent a location - helyzetmeghatározó információt küldött - - - has registered with Telegram - regisztrált a Telegram-al - - - joined this chat - csatlakozott a csevegéshez - - - was added to this chat - hozzáadva a csevegéshez - - - left this chat - kilépett a csevegésből - - - Unsupported message: %1 - Nem támogatott üzenet: %1 - OverviewPage @@ -554,7 +620,7 @@ sent a document myself - + dokumentumot küldött sent a location diff --git a/translations/harbour-fernschreiber-pl.ts b/translations/harbour-fernschreiber-pl.ts index 22cf990..675e1b7 100644 --- a/translations/harbour-fernschreiber-pl.ts +++ b/translations/harbour-fernschreiber-pl.ts @@ -228,6 +228,116 @@ Otwórz dokument + + FernschreiberUtils + + sent a picture + myself + wyślij obraz + + + sent a picture + wyślij obraz + + + sent a video + myself + wyślij film + + + sent a video + wyślij film + + + sent an animation + myself + wyślij animację + + + sent an animation + wyślij animację + + + sent a voice note + wyślij notatke głosową + + + sent a document + myself + wyślij dokument + + + sent a document + wyślij dokument + + + sent a location + myself + wyślij lokalizację + + + sent a location + wyślij lokalizację + + + have registered with Telegram + myself + + + + has registered with Telegram + zarejestrował się w Telegramie + + + joined this chat + myself + dołaczył do tego czatu + + + joined this chat + dołaczył do tego czatu + + + were added to this chat + myself + + + + was added to this chat + został dodany do tego czatu + + + left this chat + myself + opuścił ten czat + + + left this chat + opuścił ten czat + + + Unsupported message: %1 + Nieobsługiwana wiadomość: %1 + + + Sticker: %1 + Naklejka: %1 + + + sent a voice note + myself + wyślij notatke głosową + + + sent a venue + myself + + + + sent a venue + + + ImagePage @@ -306,50 +416,6 @@ %1 unread messages %1 nieprzeczytanych wiadomości - - sent a picture - wyślij obraz - - - sent a video - wyślij film - - - sent an animation - wyślij animację - - - sent a voice note - wyślij notatke głosową - - - sent a document - wyślij dokument - - - sent a location - wyślij lokalizację - - - has registered with Telegram - zarejestrował się w Telegramie - - - joined this chat - dołączył do tego czatu - - - was added to this chat - został dodany do tego czatu - - - left this chat - opuścil ten czat - - - Unsupported message: %1 - Nieobsługiwana wiadomość: %1 - OverviewPage @@ -573,7 +639,7 @@ joined this chat myself - + dołaczył do tego czatu were added to this chat @@ -583,7 +649,7 @@ left this chat myself - + opuścił ten czat diff --git a/translations/harbour-fernschreiber-zh_CN.ts b/translations/harbour-fernschreiber-zh_CN.ts index 21263ab..b97501b 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -228,6 +228,116 @@ 打开文档 + + FernschreiberUtils + + sent a picture + myself + 发送照片 + + + sent a picture + 发送照片 + + + sent a video + myself + 发送视频 + + + sent a video + 发送视频 + + + sent an animation + myself + 发送动画 + + + sent an animation + 发送动画 + + + sent a voice note + + + + sent a document + myself + 发送文档 + + + sent a document + 发送文档 + + + sent a location + myself + 发送位置 + + + sent a location + 发送位置 + + + have registered with Telegram + myself + 已注册到 Telegram + + + has registered with Telegram + 已注册到 Telegram + + + joined this chat + myself + + + + joined this chat + + + + were added to this chat + myself + 已经加入到此对话之中 + + + was added to this chat + 已加入到此对话 + + + left this chat + myself + 离开此对话 + + + left this chat + 离开此对话 + + + Unsupported message: %1 + 未读消息: %1 + + + Sticker: %1 + 贴纸: %1 + + + sent a voice note + myself + + + + sent a venue + myself + 发送地点 + + + sent a venue + 发送地点 + + ImagePage @@ -306,50 +416,6 @@ %1 unread messages %1 则未读消息 - - sent a picture - 发送照片 - - - sent a video - 发送视频 - - - sent an animation - 发送动画 - - - sent a voice note - 发送语音 - - - sent a document - 发送文档 - - - sent a location - 发送位置 - - - has registered with Telegram - 已注册到 Telegram - - - joined this chat - 加入此对话 - - - was added to this chat - 已加入此对话 - - - left this chat - 离开此对话 - - - Unsupported message: %1 - 不受支持的消息: %1 - OverviewPage diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index c1ca589..e4b66f3 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -228,6 +228,116 @@ + + FernschreiberUtils + + sent a picture + myself + + + + sent a picture + + + + sent a video + myself + + + + sent a video + + + + sent an animation + myself + + + + sent an animation + + + + sent a voice note + + + + sent a document + myself + + + + sent a document + + + + sent a location + myself + + + + sent a location + + + + have registered with Telegram + myself + + + + has registered with Telegram + + + + joined this chat + myself + + + + joined this chat + + + + were added to this chat + myself + + + + was added to this chat + + + + left this chat + myself + + + + left this chat + + + + Unsupported message: %1 + + + + Sticker: %1 + + + + sent a voice note + myself + + + + sent a venue + myself + + + + sent a venue + + + ImagePage @@ -306,50 +416,6 @@ %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