Specify call type on timeline

master
trilene 4 years ago
parent d51e34e66a
commit aec24efbe2
  1. 4
      resources/langs/nheko_en.ts
  2. 2
      resources/qml/delegates/MessageDelegate.qml
  3. 24
      src/EventAccessors.cpp
  4. 3
      src/EventAccessors.h
  5. 4
      src/timeline/TimelineModel.cpp
  6. 1
      src/timeline/TimelineModel.h

@ -406,8 +406,8 @@ Example: https://server.my:8787</translation>
</message> </message>
<message> <message>
<location line="+6"/> <location line="+6"/>
<source>%1 placed a voice call.</source> <source>%1 placed a %2 call.</source>
<translation>%1 placed a voice call.</translation> <translation>%1 placed a %2 call.</translation>
</message> </message>
<message> <message>
<location line="+6"/> <location line="+6"/>

@ -93,7 +93,7 @@ Item {
DelegateChoice { DelegateChoice {
roleValue: MtxEvent.CallInvite roleValue: MtxEvent.CallInvite
NoticeMessage { 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 { DelegateChoice {

@ -1,5 +1,7 @@
#include "EventAccessors.h" #include "EventAccessors.h"
#include <algorithm>
#include <cctype>
#include <type_traits> #include <type_traits>
namespace { 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 struct EventBody
{ {
template<class C> template<class C>
@ -325,6 +343,12 @@ mtx::accessors::room_topic(const mtx::events::collections::TimelineEvents &event
return std::visit(EventRoomTopic{}, 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 std::string
mtx::accessors::body(const mtx::events::collections::TimelineEvents &event) mtx::accessors::body(const mtx::events::collections::TimelineEvents &event)
{ {

@ -30,6 +30,9 @@ room_name(const mtx::events::collections::TimelineEvents &event);
std::string std::string
room_topic(const mtx::events::collections::TimelineEvents &event); room_topic(const mtx::events::collections::TimelineEvents &event);
std::string
call_type(const mtx::events::collections::TimelineEvents &event);
std::string std::string
body(const mtx::events::collections::TimelineEvents &event); body(const mtx::events::collections::TimelineEvents &event);

@ -282,6 +282,7 @@ TimelineModel::roleNames() const
{RoomId, "roomId"}, {RoomId, "roomId"},
{RoomName, "roomName"}, {RoomName, "roomName"},
{RoomTopic, "roomTopic"}, {RoomTopic, "roomTopic"},
{CallType, "callType"},
{Dump, "dump"}, {Dump, "dump"},
}; };
} }
@ -435,6 +436,8 @@ TimelineModel::data(const QString &id, int role) const
return QVariant(QString::fromStdString(room_name(event))); return QVariant(QString::fromStdString(room_name(event)));
case RoomTopic: case RoomTopic:
return QVariant(QString::fromStdString(room_topic(event))); return QVariant(QString::fromStdString(room_topic(event)));
case CallType:
return QVariant(QString::fromStdString(call_type(event)));
case Dump: { case Dump: {
QVariantMap m; QVariantMap m;
auto names = roleNames(); 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[ReplyTo], data(id, static_cast<int>(ReplyTo)));
m.insert(names[RoomName], data(id, static_cast<int>(RoomName))); m.insert(names[RoomName], data(id, static_cast<int>(RoomName)));
m.insert(names[RoomTopic], data(id, static_cast<int>(RoomTopic))); m.insert(names[RoomTopic], data(id, static_cast<int>(RoomTopic)));
m.insert(names[CallType], data(id, static_cast<int>(CallType)));
return QVariant(m); return QVariant(m);
} }

@ -170,6 +170,7 @@ public:
RoomId, RoomId,
RoomName, RoomName,
RoomTopic, RoomTopic,
CallType,
Dump, Dump,
}; };

Loading…
Cancel
Save