From 7a206441c86cd2aa84cbbbc6be803f03b2f355ab Mon Sep 17 00:00:00 2001 From: trilene Date: Fri, 10 Jul 2020 19:19:48 -0400 Subject: Support voice calls --- resources/qml/delegates/MessageDelegate.qml | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'resources/qml/delegates/MessageDelegate.qml') diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml index 17fe7360..52e628be 100644 --- a/resources/qml/delegates/MessageDelegate.qml +++ b/resources/qml/delegates/MessageDelegate.qml @@ -90,6 +90,24 @@ Item { text: qsTr("%1 created and configured room: %2").arg(model.data.userName).arg(model.data.roomId) } } + DelegateChoice { + roleValue: MtxEvent.CallInvite + NoticeMessage { + text: qsTr("%1 placed a voice call.").arg(model.data.userName) + } + } + DelegateChoice { + roleValue: MtxEvent.CallAnswer + NoticeMessage { + text: qsTr("%1 answered the call.").arg(model.data.userName) + } + } + DelegateChoice { + roleValue: MtxEvent.CallHangUp + NoticeMessage { + text: qsTr("%1 ended the call.").arg(model.data.userName) + } + } DelegateChoice { // TODO: make a more complex formatter for the power levels. roleValue: MtxEvent.PowerLevels -- cgit 1.5.1 From aec24efbe2a41c17104ea98ad9e35463b16d5d80 Mon Sep 17 00:00:00 2001 From: trilene Date: Fri, 24 Jul 2020 13:30:12 -0400 Subject: Specify call type on timeline --- resources/langs/nheko_en.ts | 4 ++-- resources/qml/delegates/MessageDelegate.qml | 2 +- src/EventAccessors.cpp | 24 ++++++++++++++++++++++++ src/EventAccessors.h | 3 +++ src/timeline/TimelineModel.cpp | 4 ++++ src/timeline/TimelineModel.h | 1 + 6 files changed, 35 insertions(+), 3 deletions(-) (limited to 'resources/qml/delegates/MessageDelegate.qml') diff --git a/resources/langs/nheko_en.ts b/resources/langs/nheko_en.ts index 27d739f2..f2bb04f9 100644 --- a/resources/langs/nheko_en.ts +++ b/resources/langs/nheko_en.ts @@ -406,8 +406,8 @@ Example: https://server.my:8787 - %1 placed a voice call. - %1 placed a voice call. + %1 placed a %2 call. + %1 placed a %2 call. diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml index 52e628be..ed18b2e5 100644 --- a/resources/qml/delegates/MessageDelegate.qml +++ b/resources/qml/delegates/MessageDelegate.qml @@ -93,7 +93,7 @@ Item { DelegateChoice { roleValue: MtxEvent.CallInvite NoticeMessage { - text: qsTr("%1 placed a voice call.").arg(model.data.userName) + text: qsTr("%1 placed a %2 call.").arg(model.data.userName).arg(model.data.callType) } } DelegateChoice { diff --git a/src/EventAccessors.cpp b/src/EventAccessors.cpp index 7071819b..043e24a2 100644 --- a/src/EventAccessors.cpp +++ b/src/EventAccessors.cpp @@ -1,5 +1,7 @@ #include "EventAccessors.h" +#include +#include #include namespace { @@ -65,6 +67,22 @@ struct EventRoomTopic } }; +struct CallType +{ + template + std::string operator()(const T &e) + { + if constexpr (std::is_same_v, T>) { + const char video[] = "m=video"; + const std::string &sdp = e.content.sdp; + return std::search(sdp.cbegin(), sdp.cend(), std::cbegin(video), std::cend(video) - 1, + [](unsigned char c1, unsigned char c2) {return std::tolower(c1) == std::tolower(c2);}) + != sdp.cend() ? "video" : "voice"; + } + return std::string(); + } +}; + struct EventBody { template @@ -325,6 +343,12 @@ mtx::accessors::room_topic(const mtx::events::collections::TimelineEvents &event return std::visit(EventRoomTopic{}, event); } +std::string +mtx::accessors::call_type(const mtx::events::collections::TimelineEvents &event) +{ + return std::visit(CallType{}, event); +} + std::string mtx::accessors::body(const mtx::events::collections::TimelineEvents &event) { diff --git a/src/EventAccessors.h b/src/EventAccessors.h index a7577d86..fa70f3eb 100644 --- a/src/EventAccessors.h +++ b/src/EventAccessors.h @@ -30,6 +30,9 @@ room_name(const mtx::events::collections::TimelineEvents &event); std::string room_topic(const mtx::events::collections::TimelineEvents &event); +std::string +call_type(const mtx::events::collections::TimelineEvents &event); + std::string body(const mtx::events::collections::TimelineEvents &event); diff --git a/src/timeline/TimelineModel.cpp b/src/timeline/TimelineModel.cpp index 8d68f24c..e4677f53 100644 --- a/src/timeline/TimelineModel.cpp +++ b/src/timeline/TimelineModel.cpp @@ -282,6 +282,7 @@ TimelineModel::roleNames() const {RoomId, "roomId"}, {RoomName, "roomName"}, {RoomTopic, "roomTopic"}, + {CallType, "callType"}, {Dump, "dump"}, }; } @@ -435,6 +436,8 @@ TimelineModel::data(const QString &id, int role) const return QVariant(QString::fromStdString(room_name(event))); case RoomTopic: return QVariant(QString::fromStdString(room_topic(event))); + case CallType: + return QVariant(QString::fromStdString(call_type(event))); case Dump: { QVariantMap m; auto names = roleNames(); @@ -464,6 +467,7 @@ TimelineModel::data(const QString &id, int role) const m.insert(names[ReplyTo], data(id, static_cast(ReplyTo))); m.insert(names[RoomName], data(id, static_cast(RoomName))); m.insert(names[RoomTopic], data(id, static_cast(RoomTopic))); + m.insert(names[CallType], data(id, static_cast(CallType))); return QVariant(m); } diff --git a/src/timeline/TimelineModel.h b/src/timeline/TimelineModel.h index ed7036c7..95584d36 100644 --- a/src/timeline/TimelineModel.h +++ b/src/timeline/TimelineModel.h @@ -170,6 +170,7 @@ public: RoomId, RoomName, RoomTopic, + CallType, Dump, }; -- cgit 1.5.1 From 7f7108161e87df272aefb9a14aec708ff427839f Mon Sep 17 00:00:00 2001 From: Nicolas Werner Date: Mon, 17 Aug 2020 23:30:36 +0200 Subject: Hide CallCandidates again in new store --- resources/qml/delegates/MessageDelegate.qml | 6 ++++++ src/Cache.cpp | 32 +++++++++++++++++++++++++++-- src/timeline/TimelineModel.cpp | 6 +++++- src/timeline/TimelineModel.h | 2 ++ 4 files changed, 43 insertions(+), 3 deletions(-) (limited to 'resources/qml/delegates/MessageDelegate.qml') diff --git a/resources/qml/delegates/MessageDelegate.qml b/resources/qml/delegates/MessageDelegate.qml index 7b6e0703..56b8040e 100644 --- a/resources/qml/delegates/MessageDelegate.qml +++ b/resources/qml/delegates/MessageDelegate.qml @@ -114,6 +114,12 @@ Item { text: qsTr("%1 ended the call.").arg(model.data.userName) } } + DelegateChoice { + roleValue: MtxEvent.CallCandidates + NoticeMessage { + text: qsTr("Negotiating call...") + } + } DelegateChoice { // TODO: make a more complex formatter for the power levels. roleValue: MtxEvent.PowerLevels 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 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>(&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 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 &) + { + return qml_mtx_events::EventType::CallCandidates; + } // ::EventType::Type operator()(const Event &e) { return // ::EventType::LocationMessage; } }; @@ -1122,7 +1127,6 @@ struct SendMessageVisitor } } - // Do-nothing operator for all unhandled events template void operator()(const mtx::events::Event &) 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 -- cgit 1.5.1