mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-22 03:00:46 +03:00
Specify call type on timeline
This commit is contained in:
parent
d51e34e66a
commit
aec24efbe2
6 changed files with 35 additions and 3 deletions
|
@ -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"/>
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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>
|
||||
|
@ -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)
|
||||
{
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -170,6 +170,7 @@ public:
|
|||
RoomId,
|
||||
RoomName,
|
||||
RoomTopic,
|
||||
CallType,
|
||||
Dump,
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue