summary refs log tree commit diff
diff options
context:
space:
mode:
authortrilene <trilene@runbox.com>2020-07-24 13:30:12 -0400
committertrilene <trilene@runbox.com>2020-07-24 13:30:12 -0400
commitaec24efbe2a41c17104ea98ad9e35463b16d5d80 (patch)
tree0211f6786c8dce2618a04789e4f62adef639a7fa
parentCancel sent CallInvite if no response within expiry (diff)
downloadnheko-aec24efbe2a41c17104ea98ad9e35463b16d5d80.tar.xz
Specify call type on timeline
-rw-r--r--resources/langs/nheko_en.ts4
-rw-r--r--resources/qml/delegates/MessageDelegate.qml2
-rw-r--r--src/EventAccessors.cpp24
-rw-r--r--src/EventAccessors.h3
-rw-r--r--src/timeline/TimelineModel.cpp4
-rw-r--r--src/timeline/TimelineModel.h1
6 files changed, 35 insertions, 3 deletions
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</translation> </message> <message> <location line="+6"/> - <source>%1 placed a voice call.</source> - <translation>%1 placed a voice call.</translation> + <source>%1 placed a %2 call.</source> + <translation>%1 placed a %2 call.</translation> </message> <message> <location line="+6"/> 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 <algorithm> +#include <cctype> #include <type_traits> namespace { @@ -65,6 +67,22 @@ struct EventRoomTopic } }; +struct CallType +{ + template<class T> + std::string operator()(const T &e) + { + if constexpr (std::is_same_v<mtx::events::RoomEvent<mtx::events::msg::CallInvite>, 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<class C> @@ -326,6 +344,12 @@ mtx::accessors::room_topic(const mtx::events::collections::TimelineEvents &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) { return std::visit(EventBody{}, event); diff --git a/src/EventAccessors.h b/src/EventAccessors.h
index a7577d86..fa70f3eb 100644 --- a/src/EventAccessors.h +++ b/src/EventAccessors.h
@@ -31,6 +31,9 @@ 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); std::string 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<int>(ReplyTo))); m.insert(names[RoomName], data(id, static_cast<int>(RoomName))); m.insert(names[RoomTopic], data(id, static_cast<int>(RoomTopic))); + m.insert(names[CallType], data(id, static_cast<int>(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, };