diff --git a/harbour-fernschreiber.pro b/harbour-fernschreiber.pro index 75b4ce3..ae59f9b 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 \ @@ -103,6 +104,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/qml/js/functions.js b/qml/js/functions.js index 893d0f6..2c7ba43 100644 --- a/qml/js/functions.js +++ b/qml/js/functions.js @@ -124,6 +124,7 @@ function enhanceMessageText(formattedText) { var messageText = formattedText.text; messageText = messageText.replace("<", "<"); messageText = messageText.replace(">", ">"); + messageText = messageText.replace("&", "&"); var messageInsertions = []; for (var i = 0; i < formattedText.entities.length; i++) { diff --git a/qml/pages/OverviewPage.qml b/qml/pages/OverviewPage.qml index 3f8d2ff..a4a6e51 100644 --- a/qml/pages/OverviewPage.qml +++ b/qml/pages/OverviewPage.qml @@ -231,8 +231,8 @@ Page { pageStack.push(Qt.resolvedUrl("../pages/ChatPage.qml"), { "chatInformation" : display }); } + showMenuOnPressAndHold: chat_id != overviewPage.ownUserId menu: ContextMenu { - visible: display.id !== overviewPage.ownUserId MenuItem { onClicked: { var newNotificationSettings = display.notification_settings; @@ -241,28 +241,12 @@ Page { } else { newNotificationSettings.mute_for = 6666666; } - tdLibWrapper.setChatNotificationSettings(display.id, newNotificationSettings); + tdLibWrapper.setChatNotificationSettings(chat_id, newNotificationSettings); } text: display.notification_settings.mute_for > 0 ? qsTr("Unmute Chat") : qsTr("Mute Chat") } } - Connections { - target: chatListModel - onChatChanged: { - if (overviewPage.chatListCreated) { - // Force update of all list item elements. dataChanged() doesn't seem to trigger them all :( - chatListPictureThumbnail.photoData = (typeof display.photo !== "undefined") ? display.photo.small : ""; - chatUnreadMessagesCountBackground.visible = display.unread_count > 0; - chatUnreadMessagesCount.text = display.unread_count > 99 ? "99+" : display.unread_count; - chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown"); - chatListLastUserText.text = (typeof display.last_message !== "undefined") ? ( display.last_message.sender_user_id !== overviewPage.ownUserId ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(display.last_message.sender_user_id)), Theme.fontSizeExtraSmall) : qsTr("You") ) : qsTr("Unknown"); - chatListLastMessageText.text = (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getMessageText(display.last_message, true, display.last_message.sender_user_id === overviewPage.ownUserId), Theme.fontSizeExtraSmall) : qsTr("Unknown"); - messageContactTimeElapsedText.text = (typeof display.last_message !== "undefined") ? Functions.getDateTimeElapsed(display.last_message.date) : qsTr("Unknown"); - } - } - } - Column { id: chatListColumn width: parent.width - ( 2 * Theme.horizontalPageMargin ) @@ -291,7 +275,7 @@ Page { ProfileThumbnail { id: chatListPictureThumbnail - photoData: (typeof display.photo !== "undefined") ? display.photo.small : "" + photoData: photo_small replacementStringHint: chatListNameText.text width: parent.width height: parent.width @@ -306,7 +290,7 @@ Page { anchors.right: parent.right anchors.bottom: parent.bottom radius: parent.width / 2 - visible: display.unread_count > 0 + visible: unread_count > 0 } Text { @@ -316,7 +300,7 @@ Page { color: Theme.primaryColor anchors.centerIn: chatUnreadMessagesCountBackground visible: chatUnreadMessagesCountBackground.visible - text: display.unread_count > 99 ? "99+" : display.unread_count + text: unread_count > 99 ? "99+" : unread_count } } } @@ -328,7 +312,7 @@ Page { Text { id: chatListNameText - text: display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown") + text: title ? Emoji.emojify(title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown") textFormat: Text.StyledText font.pixelSize: Theme.fontSizeMedium color: Theme.primaryColor @@ -349,7 +333,7 @@ Page { spacing: Theme.paddingSmall Text { id: chatListLastUserText - text: (typeof display.last_message !== "undefined") ? ( display.last_message.sender_user_id !== overviewPage.ownUserId ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(display.last_message.sender_user_id)), font.pixelSize) : qsTr("You") ) : qsTr("Unknown") + text: is_channel ? "" : ( last_message_sender_id ? ( last_message_sender_id !== overviewPage.ownUserId ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(last_message_sender_id)), font.pixelSize) : qsTr("You") ) : qsTr("Unknown") ) font.pixelSize: Theme.fontSizeExtraSmall color: Theme.highlightColor textFormat: Text.StyledText @@ -363,7 +347,7 @@ Page { } Text { id: chatListLastMessageText - text: (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getMessageText(display.last_message, true, display.last_message.sender_user_id === overviewPage.ownUserId), Theme.fontSizeExtraSmall) : qsTr("Unknown") + text: last_message_text ? Emoji.emojify(last_message_text, Theme.fontSizeExtraSmall) : qsTr("Unknown") font.pixelSize: Theme.fontSizeExtraSmall color: Theme.primaryColor width: parent.width - Theme.paddingMedium - chatListLastUserText.width @@ -379,28 +363,9 @@ Page { } } - Timer { - id: messageContactTimeUpdater - interval: 60000 - running: true - repeat: true - onTriggered: { - if (typeof display.last_message !== "undefined") { - messageContactTimeElapsedText.text = Functions.getDateTimeElapsed(display.last_message.date); - // Force update of all list item elements. dataChanged() doesn't seem to trigger them all :( - chatListPictureThumbnail.photoData = (typeof display.photo !== "undefined") ? display.photo.small : ""; - chatUnreadMessagesCountBackground.visible = display.unread_count > 0; - chatUnreadMessagesCount.text = display.unread_count > 99 ? "99+" : display.unread_count; - chatListNameText.text = display.title !== "" ? Emoji.emojify(display.title, Theme.fontSizeMedium) + ( display.notification_settings.mute_for > 0 ? Emoji.emojify(" 🔇", Theme.fontSizeMedium) : "" ) : qsTr("Unknown"); - chatListLastUserText.text = (typeof display.last_message !== "undefined") ? ( display.last_message.sender_user_id !== overviewPage.ownUserId ? Emoji.emojify(Functions.getUserName(tdLibWrapper.getUserInformation(display.last_message.sender_user_id)), Theme.fontSizeExtraSmall) : qsTr("You") ) : qsTr("Unknown"); - chatListLastMessageText.text = (typeof display.last_message !== "undefined") ? Emoji.emojify(Functions.getMessageText(display.last_message, true, display.last_message.sender_user_id === overviewPage.ownUserId), Theme.fontSizeExtraSmall) : qsTr("Unknown"); - } - } - } - Text { id: messageContactTimeElapsedText - text: (typeof display.last_message !== "undefined") ? Functions.getDateTimeElapsed(display.last_message.date) : qsTr("Unknown") + text: last_message_date ? Functions.getDateTimeElapsed(last_message_date) : qsTr("Unknown") font.pixelSize: Theme.fontSizeTiny color: Theme.secondaryColor } diff --git a/src/chatlistmodel.cpp b/src/chatlistmodel.cpp index 12e18b0..16d783d 100644 --- a/src/chatlistmodel.cpp +++ b/src/chatlistmodel.cpp @@ -18,41 +18,80 @@ */ #include "chatlistmodel.h" -#include +#include "fernschreiberutils.h" #include #define LOG(x) qDebug() << "[ChatListModel]" << x namespace { const QString ID("id"); + const QString DATE("date"); + const QString TEXT("text"); + const QString TITLE("title"); + const QString PHOTO("photo"); + const QString SMALL("small"); const QString ORDER("order"); const QString CHAT_ID("chat_id"); + const QString CONTENT("content"); const QString LAST_MESSAGE("last_message"); + const QString SENDER_USER_ID("sender_user_id"); const QString UNREAD_COUNT("unread_count"); const QString NOTIFICATION_SETTINGS("notification_settings"); const QString LAST_READ_INBOX_MESSAGE_ID("last_read_inbox_message_id"); const QString LAST_READ_OUTBOX_MESSAGE_ID("last_read_outbox_message_id"); + const QString TYPE_MAP("type"); + const QString IS_CHANNEL("is_channel"); + + const QString TYPE("@type"); + const QString TYPE_MESSAGE_TEXT("messageText"); } class ChatListModel::ChatData { public: - ChatData(const QVariantMap &data); + enum Role { + RoleDisplay = Qt::DisplayRole, + RoleChatId, + RoleTitle, + RolePhotoSmall, + RoleUnreadCount, + RoleLastReadInboxMessageId, + RoleLastMessageSenderId, + RoleLastMessageDate, + RoleLastMessageText, + RoleIsChannel + }; + + ChatData(const QVariantMap &data, const QVariantMap &userInformation); int compareTo(const ChatData *chat) const; bool setOrder(const QString &order); + const QVariant lastMessage(const QString &key) const; + QString title() const; + int unreadCount() const; + QVariant photoSmall() const; + qlonglong lastReadInboxMessageId() const; + qlonglong senderUserId() const; + qlonglong senderMessageDate() const; + QString senderMessageText() const; + bool isChannel() const; + bool updateUnreadCount(int unreadCount); + bool updateLastReadInboxMessageId(qlonglong messageId); + QVector updateLastMessage(const QVariantMap &message); 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 @@ -75,6 +114,87 @@ bool ChatListModel::ChatData::setOrder(const QString &newOrder) return false; } +inline const QVariant ChatListModel::ChatData::lastMessage(const QString &key) const +{ + return chatData.value(LAST_MESSAGE).toMap().value(key); +} + +QString ChatListModel::ChatData::title() const +{ + return chatData.value(TITLE).toString(); +} + +int ChatListModel::ChatData::unreadCount() const +{ + return chatData.value(UNREAD_COUNT).toInt(); +} + +QVariant ChatListModel::ChatData::photoSmall() const +{ + return chatData.value(PHOTO).toMap().value(SMALL); +} + +qlonglong ChatListModel::ChatData::lastReadInboxMessageId() const +{ + return chatData.value(LAST_READ_INBOX_MESSAGE_ID).toLongLong(); +} + +qlonglong ChatListModel::ChatData::senderUserId() const +{ + return lastMessage(SENDER_USER_ID).toLongLong(); +} + +qlonglong ChatListModel::ChatData::senderMessageDate() const +{ + return lastMessage(DATE).toLongLong(); +} + +QString ChatListModel::ChatData::senderMessageText() const +{ + return FernschreiberUtils::getMessageShortText(lastMessage(CONTENT).toMap(), this->userInformation.value(ID).toLongLong() == senderUserId()); +} + +bool ChatListModel::ChatData::isChannel() const +{ + return chatData.value(TYPE_MAP).toMap().value(IS_CHANNEL).toBool(); +} + +bool ChatListModel::ChatData::updateUnreadCount(int count) +{ + const int prevUnreadCount(unreadCount()); + chatData.insert(UNREAD_COUNT, count); + return prevUnreadCount != unreadCount(); +} + +bool ChatListModel::ChatData::updateLastReadInboxMessageId(qlonglong messageId) +{ + const qlonglong prevLastReadInboxMessageId(lastReadInboxMessageId()); + chatData.insert(LAST_READ_INBOX_MESSAGE_ID, messageId); + return prevLastReadInboxMessageId != lastReadInboxMessageId(); +} + +QVector ChatListModel::ChatData::updateLastMessage(const QVariantMap &message) +{ + const qlonglong prevSenderUserId(senderUserId()); + const qlonglong prevSenderMessageDate(senderMessageDate()); + const QString prevSenderMessageText(senderMessageText()); + + chatData.insert(LAST_MESSAGE, message); + + QVector changedRoles; + changedRoles.append(RoleDisplay); + if (prevSenderUserId != senderUserId()) { + changedRoles.append(RoleLastMessageSenderId); + } + if (prevSenderMessageDate != senderMessageDate()) { + changedRoles.append(RoleLastMessageDate); + } + if (prevSenderMessageText != senderMessageText()) { + changedRoles.append(RoleLastMessageText); + } + return changedRoles; +} + ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) { this->tdLibWrapper = tdLibWrapper; @@ -85,6 +205,12 @@ ChatListModel::ChatListModel(TDLibWrapper *tdLibWrapper) connect(tdLibWrapper, SIGNAL(chatReadOutboxUpdated(QString, QString)), this, SLOT(handleChatReadOutboxUpdated(QString, QString))); connect(tdLibWrapper, SIGNAL(messageSendSucceeded(QString, QString, QVariantMap)), this, SLOT(handleMessageSendSucceeded(QString, QString, QVariantMap))); connect(tdLibWrapper, SIGNAL(chatNotificationSettingsUpdated(QString, QVariantMap)), this, SLOT(handleChatNotificationSettingsUpdated(QString, QVariantMap))); + + // Don't start the timer until we have at least one chat + relativeTimeRefreshTimer = new QTimer(this); + relativeTimeRefreshTimer->setSingleShot(false); + relativeTimeRefreshTimer->setInterval(30000); + connect(relativeTimeRefreshTimer, SIGNAL(timeout()), SLOT(handleRelativeTimeRefreshTimer())); } ChatListModel::~ChatListModel() @@ -93,6 +219,22 @@ ChatListModel::~ChatListModel() qDeleteAll(chatList); } +QHash ChatListModel::roleNames() const +{ + QHash roles; + roles.insert(ChatData::RoleDisplay, "display"); + roles.insert(ChatData::RoleChatId, "chat_id"); + roles.insert(ChatData::RoleTitle, "title"); + roles.insert(ChatData::RolePhotoSmall, "photo_small"); + roles.insert(ChatData::RoleUnreadCount, "unread_count"); + roles.insert(ChatData::RoleLastReadInboxMessageId, "last_read_inbox_message_id"); + roles.insert(ChatData::RoleLastMessageSenderId, "last_message_sender_id"); + roles.insert(ChatData::RoleLastMessageDate, "last_message_date"); + roles.insert(ChatData::RoleLastMessageText, "last_message_text"); + roles.insert(ChatData::RoleIsChannel, "is_channel"); + return roles; +} + int ChatListModel::rowCount(const QModelIndex &) const { return chatList.size(); @@ -101,8 +243,20 @@ int ChatListModel::rowCount(const QModelIndex &) const QVariant ChatListModel::data(const QModelIndex &index, int role) const { const int row = index.row(); - if (row >= 0 && row < chatList.size() && role == Qt::DisplayRole) { - return chatList.at(row)->chatData; + if (row >= 0 && row < chatList.size()) { + const ChatData *data = chatList.at(row); + switch ((ChatData::Role)role) { + case ChatData::RoleDisplay: return data->chatData; + case ChatData::RoleChatId: return data->chatId; + case ChatData::RoleTitle: return data->title(); + case ChatData::RolePhotoSmall: return data->photoSmall(); + case ChatData::RoleUnreadCount: return data->unreadCount(); + case ChatData::RoleLastReadInboxMessageId: return data->lastReadInboxMessageId(); + case ChatData::RoleLastMessageSenderId: return data->senderUserId(); + case ChatData::RoleLastMessageText: return data->senderMessageText(); + case ChatData::RoleLastMessageDate: return data->senderMessageDate(); + case ChatData::RoleIsChannel: return data->isChannel(); + } } return QVariant(); } @@ -115,7 +269,7 @@ void ChatListModel::redrawModel() int ChatListModel::updateChatOrder(int chatIndex) { - ChatData* chat = chatList.at(chatIndex); + ChatData *chat = chatList.at(chatIndex); const int n = chatList.size(); int newIndex = chatIndex; @@ -155,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++); @@ -168,6 +322,11 @@ void ChatListModel::handleChatDiscovered(const QString &chatId, const QVariantMa chatIndexMap.insert(chatList.at(i)->chatId, i); } endInsertRows(); + + // Start timestamp refresh timer when the first chat is discovered + if (!relativeTimeRefreshTimer->isActive()) { + relativeTimeRefreshTimer->start(); + } } void ChatListModel::handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage) @@ -175,14 +334,12 @@ void ChatListModel::handleChatLastMessageUpdated(const QString &chatId, const QS if (chatIndexMap.contains(chatId)) { int chatIndex = chatIndexMap.value(chatId); LOG("Updating last message for chat" << chatId <<" at index" << chatIndex << "new order" << order); - ChatData* chat = chatList.at(chatIndex); - chat->chatData.insert(LAST_MESSAGE, lastMessage); + ChatData *chat = chatList.at(chatIndex); if (chat->setOrder(order)) { chatIndex = updateChatOrder(chatIndex); } const QModelIndex modelIndex(index(chatIndex)); - emit dataChanged(modelIndex, modelIndex); - emit chatChanged(chatId); + emit dataChanged(modelIndex, modelIndex, chat->updateLastMessage(lastMessage)); } } @@ -192,25 +349,27 @@ void ChatListModel::handleChatOrderUpdated(const QString &chatId, const QString LOG("Updating chat order of" << chatId << "to" << order); int chatIndex = chatIndexMap.value(chatId); if (chatList.at(chatIndex)->setOrder(order)) { - chatIndex = updateChatOrder(chatIndex); + updateChatOrder(chatIndex); } - const QModelIndex modelIndex(index(chatIndex)); - emit dataChanged(modelIndex, modelIndex); - emit chatChanged(chatId); } } -void ChatListModel::handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount) +void ChatListModel::handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, int unreadCount) { if (chatIndexMap.contains(chatId)) { LOG("Updating chat unread count for" << chatId << "unread messages" << unreadCount << ", last read message ID: " << lastReadInboxMessageId); const int chatIndex = chatIndexMap.value(chatId); - ChatData* chat = chatList.at(chatIndex); - chat->chatData.insert(UNREAD_COUNT, unreadCount); - chat->chatData.insert(LAST_READ_INBOX_MESSAGE_ID, lastReadInboxMessageId); + ChatData *chat = chatList.at(chatIndex); + QVector changedRoles; + changedRoles.append(ChatData::RoleDisplay); + if (chat->updateUnreadCount(unreadCount)) { + changedRoles.append(ChatData::RoleUnreadCount); + } + if (chat->updateLastReadInboxMessageId(lastReadInboxMessageId.toLongLong())) { + changedRoles.append(ChatData::RoleLastReadInboxMessageId); + } const QModelIndex modelIndex(index(chatIndex)); - emit dataChanged(modelIndex, modelIndex); - emit chatChanged(chatId); + emit dataChanged(modelIndex, modelIndex, changedRoles); } } @@ -219,11 +378,10 @@ void ChatListModel::handleChatReadOutboxUpdated(const QString &chatId, const QSt if (chatIndexMap.contains(chatId)) { LOG("Updating last read message for" << chatId << "last ID" << lastReadOutboxMessageId); const int chatIndex = chatIndexMap.value(chatId); - ChatData* chat = chatList.at(chatIndex); + ChatData *chat = chatList.at(chatIndex); chat->chatData.insert(LAST_READ_OUTBOX_MESSAGE_ID, lastReadOutboxMessageId); const QModelIndex modelIndex(index(chatIndex)); emit dataChanged(modelIndex, modelIndex); - emit chatChanged(chatId); } } @@ -233,11 +391,8 @@ void ChatListModel::handleMessageSendSucceeded(const QString &messageId, const Q if (chatIndexMap.contains(chatId)) { const int chatIndex = chatIndexMap.value(chatId); LOG("Updating last message for chat" << chatId << "at index" << chatIndex << ", as message was sent, old ID:" << oldMessageId << ", new ID:" << messageId); - ChatData* chat = chatList.at(chatIndex); - chat->chatData.insert(LAST_MESSAGE, message); const QModelIndex modelIndex(index(chatIndex)); - emit dataChanged(modelIndex, modelIndex); - emit chatChanged(chatId); + emit dataChanged(modelIndex, modelIndex, chatList.at(chatIndex)->updateLastMessage(message)); } } @@ -246,10 +401,17 @@ void ChatListModel::handleChatNotificationSettingsUpdated(const QString &chatId, if (chatIndexMap.contains(chatId)) { const int chatIndex = chatIndexMap.value(chatId); LOG("Updating notification settings for chat" << chatId << "at index" << chatIndex); - ChatData* chat = chatList.at(chatIndex); + ChatData *chat = chatList.at(chatIndex); chat->chatData.insert(NOTIFICATION_SETTINGS, chatNotificationSettings); const QModelIndex modelIndex(index(chatIndex)); emit dataChanged(modelIndex, modelIndex); - emit chatChanged(chatId); } } + +void ChatListModel::handleRelativeTimeRefreshTimer() +{ + LOG("Refreshing timestamps"); + QVector roles; + roles.append(ChatData::RoleLastMessageDate); + emit dataChanged(index(0), index(chatList.size() - 1), roles); +} diff --git a/src/chatlistmodel.h b/src/chatlistmodel.h index 00f084c..485b0cc 100644 --- a/src/chatlistmodel.h +++ b/src/chatlistmodel.h @@ -21,8 +21,6 @@ #define CHATLISTMODEL_H #include -#include -#include #include "tdlibwrapper.h" class ChatListModel : public QAbstractListModel @@ -32,22 +30,21 @@ public: ChatListModel(TDLibWrapper *tdLibWrapper); ~ChatListModel() override; + virtual QHash roleNames() const override; virtual int rowCount(const QModelIndex&) const override; virtual QVariant data(const QModelIndex &index, int role) const override; Q_INVOKABLE void redrawModel(); -signals: - void chatChanged(const QString &chatId); - private slots: void handleChatDiscovered(const QString &chatId, const QVariantMap &chatInformation); void handleChatLastMessageUpdated(const QString &chatId, const QString &order, const QVariantMap &lastMessage); void handleChatOrderUpdated(const QString &chatId, const QString &order); - void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, const int &unreadCount); + void handleChatReadInboxUpdated(const QString &chatId, const QString &lastReadInboxMessageId, int unreadCount); void handleChatReadOutboxUpdated(const QString &chatId, const QString &lastReadOutboxMessageId); void handleMessageSendSucceeded(const QString &messageId, const QString &oldMessageId, const QVariantMap &message); void handleChatNotificationSettingsUpdated(const QString &chatId, const QVariantMap &chatNotificationSettings); + void handleRelativeTimeRefreshTimer(); private: int updateChatOrder(int chatIndex); @@ -56,6 +53,7 @@ private: class ChatData; TDLibWrapper *tdLibWrapper; + QTimer *relativeTimeRefreshTimer; QList chatList; QHash chatIndexMap; }; 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 af6833e..7f4886b 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 @@ -313,7 +423,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. @@ -322,50 +432,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 0e88154..7149f39 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 @@ -322,50 +432,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 390aa33..f23ddbf 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 @@ -322,50 +432,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 @@ -574,7 +640,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 4224947..c307df4 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 @@ -322,50 +432,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 @@ -593,7 +659,7 @@ joined this chat myself - + dołaczył do tego czatu were added to this chat @@ -603,7 +669,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 2b99fe8..de0d1b2 100644 --- a/translations/harbour-fernschreiber-zh_CN.ts +++ b/translations/harbour-fernschreiber-zh_CN.ts @@ -73,7 +73,7 @@ By Sebastian J. Wolf and <a href="https://github.com/Wunderfitz/harbour-fernschreiber#contributions">other contributors</a> - + 开发者为 Sebastian J. Wolf 及 <ahref="https://github.com/Wunderfitz/harbour-fernschreiber#contributions">其他贡献者</a> @@ -131,7 +131,7 @@ %1 subscribers - %1 订阅者 + %1 位订阅者 Reply to Message @@ -171,7 +171,7 @@ Uploading... - + 正在上传…… @@ -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 @@ -247,7 +357,7 @@ InReplyToRow You - 你的 + @@ -274,7 +384,7 @@ Loading... - 正在加载 + 正在加载…… Unable to authenticate you with the entered code. @@ -313,58 +423,14 @@ LocationPreview Install Pure Maps to inspect this location. - + 安装 Pure Maps 以插入位置 NotificationManager %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 + %1 则未读消息 @@ -488,7 +554,7 @@ Unsupported message: %1 - 未读消息t: %1 + 未读消息: %1 Document: %1 @@ -544,66 +610,66 @@ sent a venue - + 发送地点 sent a picture myself - 发送照片 + 发送照片 sent a video myself - 发送视频 + 发送视频 sent an animation myself - 发送动画 + 发送动画 sent an audio myself - 发送音频 + 发送音频 sent a voice note myself - + 发送语音 sent a document myself - 发送文档 + 发送文档 sent a location myself - 发送位置 + 发送位置 sent a venue myself - + 发送地点 have registered with Telegram - + 已注册到 Telegram joined this chat myself - + 已加入此对话 were added to this chat myself - + 已经加入到此对话之中 left this chat myself - 离开此对话 + 离开此对话 diff --git a/translations/harbour-fernschreiber.ts b/translations/harbour-fernschreiber.ts index 1912eaa..bbe39e5 100644 --- a/translations/harbour-fernschreiber.ts +++ b/translations/harbour-fernschreiber.ts @@ -228,6 +228,132 @@ + + 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 + + + + Register User + + + + Enter your First Name + + + + Enter your Last Name + + + + User Registration + + + ImagePage @@ -292,22 +418,6 @@ Please enter your password: - - Register User - - - - Enter your First Name - - - - Enter your Last Name - - - - User Registration - - LocationPreview @@ -322,50 +432,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