From 1dd1a19b06861e2ab0fc282af143e792080bbbdb Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 3 Oct 2019 18:07:01 +0200 Subject: [PATCH] Update roomlist on new messages --- src/timeline2/TimelineModel.cpp | 24 +++++++++++++++++++++++- src/timeline2/TimelineModel.h | 7 ++++++- src/timeline2/TimelineViewManager.cpp | 3 ++- src/timeline2/TimelineViewManager.h | 2 +- 4 files changed, 32 insertions(+), 4 deletions(-) diff --git a/src/timeline2/TimelineModel.cpp b/src/timeline2/TimelineModel.cpp index f9a8358f..db9ce555 100644 --- a/src/timeline2/TimelineModel.cpp +++ b/src/timeline2/TimelineModel.cpp @@ -9,6 +9,7 @@ #include "Logging.h" #include "MainWindow.h" #include "Olm.h" +#include "TimelineViewManager.h" #include "Utils.h" #include "dialogs/RawMessage.h" @@ -282,9 +283,10 @@ eventPropHeight(const mtx::events::RoomEvent &e) } } -TimelineModel::TimelineModel(QString room_id, QObject *parent) +TimelineModel::TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent) : QAbstractListModel(parent) , room_id_(room_id) + , manager_(manager) { connect( this, &TimelineModel::oldMessagesRetrieved, this, &TimelineModel::addBackwardsEvents); @@ -481,6 +483,26 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) static_cast(this->eventOrder.size() + ids.size() - 1)); this->eventOrder.insert(this->eventOrder.end(), ids.begin(), ids.end()); endInsertRows(); + + for (auto id = ids.rbegin(); id != ids.rend(); id++) { + auto event = events.value(*id); + if (auto e = boost::get>( + &event)) { + event = decryptEvent(*e).event; + } + + auto type = boost::apply_visitor( + [](const auto &e) -> mtx::events::EventType { return e.type; }, event); + if (type == mtx::events::EventType::RoomMessage || + type == mtx::events::EventType::Sticker) { + auto description = utils::getMessageDescription( + event, + QString::fromStdString(http::client()->user_id().to_string()), + room_id_); + emit manager_->updateRoomsLastMessage(room_id_, description); + break; + } + } } std::vector diff --git a/src/timeline2/TimelineModel.h b/src/timeline2/TimelineModel.h index ffe5aecb..9b861010 100644 --- a/src/timeline2/TimelineModel.h +++ b/src/timeline2/TimelineModel.h @@ -108,6 +108,8 @@ struct DecryptionResult bool isDecrypted = false; }; +class TimelineViewManager; + class TimelineModel : public QAbstractListModel { Q_OBJECT @@ -115,7 +117,7 @@ class TimelineModel : public QAbstractListModel int currentIndex READ currentIndex WRITE setCurrentIndex NOTIFY currentIndexChanged) public: - explicit TimelineModel(QString room_id, QObject *parent = 0); + explicit TimelineModel(TimelineViewManager *manager, QString room_id, QObject *parent = 0); enum Roles { @@ -145,6 +147,7 @@ public: Q_INVOKABLE QString displayName(QString id) const; Q_INVOKABLE QString avatarUrl(QString id) const; Q_INVOKABLE QString formatDateSeparator(QDate date) const; + Q_INVOKABLE QString escapeEmoji(QString str) const; Q_INVOKABLE void viewRawMessage(QString id) const; Q_INVOKABLE void replyAction(QString id); @@ -204,6 +207,8 @@ private: QHash userColors; QString currentId; + + TimelineViewManager *manager_; }; template diff --git a/src/timeline2/TimelineViewManager.cpp b/src/timeline2/TimelineViewManager.cpp index 4ec089fa..74e851c4 100644 --- a/src/timeline2/TimelineViewManager.cpp +++ b/src/timeline2/TimelineViewManager.cpp @@ -40,7 +40,8 @@ void TimelineViewManager::addRoom(const QString &room_id) { if (!models.contains(room_id)) - models.insert(room_id, QSharedPointer(new TimelineModel(room_id))); + models.insert(room_id, + QSharedPointer(new TimelineModel(this, room_id))); } void diff --git a/src/timeline2/TimelineViewManager.h b/src/timeline2/TimelineViewManager.h index 38d68f16..a8fcf7ce 100644 --- a/src/timeline2/TimelineViewManager.h +++ b/src/timeline2/TimelineViewManager.h @@ -61,7 +61,7 @@ public: signals: void clearRoomMessageCount(QString roomid); - void updateRoomsLastMessage(const QString &user, const DescInfo &info); + void updateRoomsLastMessage(QString roomid, const DescInfo &info); void activeTimelineChanged(TimelineModel *timeline); public slots: