mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-11-25 12:38:48 +03:00
Add read support for m.emote events (#41)
This commit is contained in:
parent
6797cbc943
commit
a44a4f36af
4 changed files with 73 additions and 2 deletions
|
@ -25,6 +25,7 @@
|
|||
#include "Sync.h"
|
||||
|
||||
#include "Avatar.h"
|
||||
#include "Emote.h"
|
||||
#include "Image.h"
|
||||
#include "MessageEvent.h"
|
||||
#include "Notice.h"
|
||||
|
@ -44,6 +45,9 @@ public:
|
|||
TimelineItem(const events::MessageEvent<msgs::Text> &e,
|
||||
bool with_sender,
|
||||
QWidget *parent = 0);
|
||||
TimelineItem(const events::MessageEvent<msgs::Emote> &e,
|
||||
bool with_sender,
|
||||
QWidget *parent = 0);
|
||||
|
||||
// For local messages.
|
||||
TimelineItem(const QString &userid, QString body, QWidget *parent = 0);
|
||||
|
|
|
@ -28,6 +28,7 @@
|
|||
#include "TimelineItem.h"
|
||||
|
||||
#include "Image.h"
|
||||
#include "Emote.h"
|
||||
#include "Notice.h"
|
||||
#include "RoomInfoListItem.h"
|
||||
#include "Text.h"
|
||||
|
@ -77,6 +78,8 @@ public:
|
|||
bool with_sender);
|
||||
TimelineItem *createTimelineItem(const events::MessageEvent<msgs::Text> &e,
|
||||
bool with_sender);
|
||||
TimelineItem *createTimelineItem(const events::MessageEvent<msgs::Emote> &e,
|
||||
bool with_sender);
|
||||
|
||||
// Add new events at the end of the timeline.
|
||||
int addEvents(const Timeline &timeline);
|
||||
|
|
|
@ -191,6 +191,43 @@ TimelineItem::TimelineItem(const events::MessageEvent<msgs::Notice> &event,
|
|||
mainLayout_->addWidget(body_);
|
||||
}
|
||||
|
||||
/*
|
||||
* Used to display remote emote messages.
|
||||
*/
|
||||
TimelineItem::TimelineItem(const events::MessageEvent<msgs::Emote> &event,
|
||||
bool with_sender,
|
||||
QWidget *parent)
|
||||
: QWidget(parent)
|
||||
{
|
||||
init();
|
||||
|
||||
auto body = event.content().body().trimmed().toHtmlEscaped();
|
||||
auto timestamp = QDateTime::fromMSecsSinceEpoch(event.timestamp());
|
||||
auto displayName = TimelineViewManager::displayName(event.sender());
|
||||
auto emoteMsg = QString("* %1 %2").arg(displayName).arg(body);
|
||||
|
||||
descriptionMsg_ = { "",
|
||||
event.sender(),
|
||||
emoteMsg,
|
||||
descriptiveTime(QDateTime::fromMSecsSinceEpoch(event.timestamp())) };
|
||||
|
||||
generateTimestamp(timestamp);
|
||||
emoteMsg.replace(URL_REGEX, URL_HTML);
|
||||
|
||||
if (with_sender) {
|
||||
generateBody(displayName, emoteMsg);
|
||||
setupAvatarLayout(displayName);
|
||||
mainLayout_->addLayout(headerLayout_);
|
||||
|
||||
AvatarProvider::resolve(event.sender(), this);
|
||||
} else {
|
||||
generateBody(emoteMsg);
|
||||
setupSimpleLayout();
|
||||
}
|
||||
|
||||
mainLayout_->addWidget(body_);
|
||||
}
|
||||
|
||||
/*
|
||||
* Used to display remote text messages.
|
||||
*/
|
||||
|
@ -216,8 +253,6 @@ TimelineItem::TimelineItem(const events::MessageEvent<msgs::Text> &event,
|
|||
body.replace(URL_REGEX, URL_HTML);
|
||||
|
||||
if (with_sender) {
|
||||
auto displayName = TimelineViewManager::displayName(event.sender());
|
||||
|
||||
generateBody(displayName, body);
|
||||
setupAvatarLayout(displayName);
|
||||
|
||||
|
|
|
@ -274,6 +274,28 @@ TimelineView::parseMessageEvent(const QJsonObject &event, TimelineDirection dire
|
|||
updateLastSender(img.sender(), direction);
|
||||
|
||||
return createTimelineItem(img, with_sender);
|
||||
} else if (msg_type == events::MessageEventType::Emote) {
|
||||
events::MessageEvent<msgs::Emote> emote;
|
||||
|
||||
try {
|
||||
emote.deserialize(event);
|
||||
} catch (const DeserializationException &e) {
|
||||
qWarning() << e.what() << event;
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
if (isDuplicate(emote.eventId()))
|
||||
return nullptr;
|
||||
|
||||
eventIds_[emote.eventId()] = true;
|
||||
|
||||
// TODO Check if it's a message waiting for validation
|
||||
|
||||
auto with_sender = isSenderRendered(emote.sender(), direction);
|
||||
|
||||
updateLastSender(emote.sender(), direction);
|
||||
|
||||
return createTimelineItem(emote, with_sender);
|
||||
} else if (msg_type == events::MessageEventType::Unknown) {
|
||||
qWarning() << "Unknown message type" << event;
|
||||
return nullptr;
|
||||
|
@ -403,6 +425,13 @@ TimelineView::createTimelineItem(const events::MessageEvent<msgs::Text> &event,
|
|||
return item;
|
||||
}
|
||||
|
||||
TimelineItem *
|
||||
TimelineView::createTimelineItem(const events::MessageEvent<msgs::Emote> &event, bool with_sender)
|
||||
{
|
||||
TimelineItem *item = new TimelineItem(event, with_sender, scroll_widget_);
|
||||
return item;
|
||||
}
|
||||
|
||||
void
|
||||
TimelineView::addTimelineItem(TimelineItem *item, TimelineDirection direction)
|
||||
{
|
||||
|
|
Loading…
Reference in a new issue