Skip to content
Snippets Groups Projects
Commit 1dd1a19b authored by Nicolas Werner's avatar Nicolas Werner
Browse files

Update roomlist on new messages

parent aee29c6e
No related branches found
No related tags found
No related merge requests found
......@@ -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<T> &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<int>(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<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
&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<QString>
......
......@@ -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<QString, QColor> userColors;
QString currentId;
TimelineViewManager *manager_;
};
template<class T>
......
......@@ -40,7 +40,8 @@ void
TimelineViewManager::addRoom(const QString &room_id)
{
if (!models.contains(room_id))
models.insert(room_id, QSharedPointer<TimelineModel>(new TimelineModel(room_id)));
models.insert(room_id,
QSharedPointer<TimelineModel>(new TimelineModel(this, room_id)));
}
void
......
......@@ -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:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment