From 640b0ee4057a0993a515d7db7c875d314aab9bdf Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Thu, 3 Sep 2020 17:01:58 +0200 Subject: Port top bar to Qml Also fixes some resize issues with stupid workarounds to our resize logic. This really needs to be cleaned up at some point! --- src/timeline/TimelineModel.cpp | 64 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'src/timeline/TimelineModel.cpp') diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index b6c2d4bb..f596a587 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -517,6 +517,25 @@ TimelineModel::fetchMore(const QModelIndex &) events.fetchMore(); } +void +TimelineModel::syncState(const mtx::responses::State &s) +{ + using namespace mtx::events; + + for (const auto &e : s.events) { + if (std::holds_alternative>(e)) + emit roomAvatarUrlChanged(); + else if (std::holds_alternative>(e)) + emit roomNameChanged(); + else if (std::holds_alternative>(e)) + emit roomTopicChanged(); + else if (std::holds_alternative>(e)) { + emit roomAvatarUrlChanged(); + emit roomNameChanged(); + } + } +} + void TimelineModel::addEvents(const mtx::responses::Timeline &timeline) { @@ -526,6 +545,7 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) events.handleSync(timeline); using namespace mtx::events; + for (auto e : timeline.events) { if (auto encryptedEvent = std::get_if>(&e)) { MegolmSessionIndex index; @@ -549,6 +569,16 @@ TimelineModel::addEvents(const mtx::responses::Timeline &timeline) emit newCallEvent(event); }, e); + else if (std::holds_alternative>(e)) + emit roomAvatarUrlChanged(); + else if (std::holds_alternative>(e)) + emit roomNameChanged(); + else if (std::holds_alternative>(e)) + emit roomTopicChanged(); + else if (std::holds_alternative>(e)) { + emit roomAvatarUrlChanged(); + emit roomNameChanged(); + } } updateLastMessage(); } @@ -1594,3 +1624,37 @@ TimelineModel::formatMemberEvent(QString id) return rendered; } + +QString +TimelineModel::roomName() const +{ + auto info = cache::getRoomInfo({room_id_.toStdString()}); + + if (!info.count(room_id_)) + return ""; + else + return QString::fromStdString(info[room_id_].name); +} + +QString +TimelineModel::roomAvatarUrl() const +{ + auto info = cache::getRoomInfo({room_id_.toStdString()}); + + if (!info.count(room_id_)) + return ""; + else + return QString::fromStdString(info[room_id_].avatar_url); +} + +QString +TimelineModel::roomTopic() const +{ + auto info = cache::getRoomInfo({room_id_.toStdString()}); + + if (!info.count(room_id_)) + return ""; + else + return utils::replaceEmoji(utils::linkifyMessage( + utils::escapeBlacklistedHtml(QString::fromStdString(info[room_id_].topic)))); +} -- cgit 1.5.1