summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
authorNicolas Werner <nicolas.werner@hotmail.de>2020-08-17 23:30:36 +0200
committerNicolas Werner <nicolas.werner@hotmail.de>2020-08-17 23:30:36 +0200
commit7f7108161e87df272aefb9a14aec708ff427839f (patch)
treed8be291e98afb59fc8cbcf1900486d8e8f2bf6cd /src
parentMerge remote-tracking branch 'origin/master' into new-event-store (diff)
downloadnheko-7f7108161e87df272aefb9a14aec708ff427839f.tar.xz
Hide CallCandidates again in new store
Diffstat (limited to 'src')
-rw-r--r--src/Cache.cpp32
-rw-r--r--src/timeline/TimelineModel.cpp6
-rw-r--r--src/timeline/TimelineModel.h2
3 files changed, 37 insertions, 3 deletions
diff --git a/src/Cache.cpp b/src/Cache.cpp

index fd26f63e..e41ad7ca 100644 --- a/src/Cache.cpp +++ b/src/Cache.cpp
@@ -33,6 +33,7 @@ #include "Cache_p.h" #include "EventAccessors.h" #include "Logging.h" +#include "Olm.h" #include "Utils.h" //! Should be changed when a breaking change occurs in the cache format. @@ -93,6 +94,33 @@ namespace { std::unique_ptr<Cache> instance_ = nullptr; } +static bool +isHiddenEvent(mtx::events::collections::TimelineEvents e, const std::string &room_id) +{ + using namespace mtx::events; + if (auto encryptedEvent = std::get_if<EncryptedEvent<msg::Encrypted>>(&e)) { + MegolmSessionIndex index; + index.room_id = room_id; + index.session_id = encryptedEvent->content.session_id; + index.sender_key = encryptedEvent->content.sender_key; + + auto result = olm::decryptEvent(index, *encryptedEvent); + if (!result.error) + e = result.event.value(); + } + + static constexpr std::initializer_list<EventType> hiddenEvents = { + EventType::Reaction, EventType::CallCandidates, EventType::Unsupported}; + + return std::visit( + [](const auto &ev) { + return std::any_of(hiddenEvents.begin(), + hiddenEvents.end(), + [ev](EventType type) { return type == ev.type; }); + }, + e); +} + Cache::Cache(const QString &userId, QObject *parent) : QObject{parent} , env_{nullptr} @@ -2406,7 +2434,7 @@ Cache::saveTimelineMessages(lmdb::txn &txn, lmdb::dbi_put(txn, evToOrderDb, event_id, lmdb::val(&index, sizeof(index))); // TODO(Nico): Allow blacklisting more event types in UI - if (event["type"] != "m.reaction" && event["type"] != "m.dummy") { + if (!isHiddenEvent(e, room_id)) { ++msgIndex; lmdb::cursor_put(msgCursor.handle(), lmdb::val(&msgIndex, sizeof(msgIndex)), @@ -2489,7 +2517,7 @@ Cache::saveOldMessages(const std::string &room_id, const mtx::responses::Message lmdb::dbi_put(txn, evToOrderDb, event_id, lmdb::val(&index, sizeof(index))); // TODO(Nico): Allow blacklisting more event types in UI - if (event["type"] != "m.reaction" && event["type"] != "m.dummy") { + if (!isHiddenEvent(e, room_id)) { --msgIndex; lmdb::dbi_put( txn, order2msgDb, lmdb::val(&msgIndex, sizeof(msgIndex)), event_id); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp
index 9695f850..b6c2d4bb 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp
@@ -136,6 +136,11 @@ struct RoomEventType { return qml_mtx_events::EventType::CallHangUp; } + qml_mtx_events::EventType operator()( + const mtx::events::Event<mtx::events::msg::CallCandidates> &) + { + return qml_mtx_events::EventType::CallCandidates; + } // ::EventType::Type operator()(const Event<mtx::events::msg::Location> &e) { return // ::EventType::LocationMessage; } }; @@ -1122,7 +1127,6 @@ struct SendMessageVisitor } } - // Do-nothing operator for all unhandled events template<typename T> void operator()(const mtx::events::Event<T> &) diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h
index 034ae31a..156606e6 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h
@@ -42,6 +42,8 @@ enum EventType CallAnswer, /// m.call.hangup CallHangUp, + /// m.call.candidates + CallCandidates, /// m.room.canonical_alias CanonicalAlias, /// m.room.create