Improve visualization of replies to non-message events
This commit is contained in:
committed by
Tobias Fella
parent
4c638a740e
commit
207a7876b6
@@ -70,9 +70,11 @@ public:
|
|||||||
*
|
*
|
||||||
* @param event the event to return a type for.
|
* @param event the event to return a type for.
|
||||||
*
|
*
|
||||||
|
* @param isInReply whether this event is to be treated like a replied-to event (i.e., a basic text fallback should be shown if no other type is used)
|
||||||
|
*
|
||||||
* @sa Type
|
* @sa Type
|
||||||
*/
|
*/
|
||||||
static Type typeForEvent(const Quotient::RoomEvent &event)
|
static Type typeForEvent(const Quotient::RoomEvent &event, bool isInReply = false)
|
||||||
{
|
{
|
||||||
using namespace Quotient;
|
using namespace Quotient;
|
||||||
|
|
||||||
@@ -103,7 +105,8 @@ public:
|
|||||||
if (event.matrixType() == u"org.matrix.msc3672.beacon_info"_s) {
|
if (event.matrixType() == u"org.matrix.msc3672.beacon_info"_s) {
|
||||||
return MessageComponentType::LiveLocation;
|
return MessageComponentType::LiveLocation;
|
||||||
}
|
}
|
||||||
return MessageComponentType::Other;
|
// In the (unlikely) case that this is a reply to a state event, we do want to show something
|
||||||
|
return isInReply ? MessageComponentType::Text : MessageComponentType::Other;
|
||||||
}
|
}
|
||||||
if (is<const EncryptedEvent>(event)) {
|
if (is<const EncryptedEvent>(event)) {
|
||||||
return MessageComponentType::Encrypted;
|
return MessageComponentType::Encrypted;
|
||||||
@@ -116,7 +119,8 @@ public:
|
|||||||
return MessageComponentType::Poll;
|
return MessageComponentType::Poll;
|
||||||
}
|
}
|
||||||
|
|
||||||
return MessageComponentType::Other;
|
// In the (unlikely) case that this is a reply to an unusual event, we do want to show something
|
||||||
|
return isInReply ? MessageComponentType::Text : MessageComponentType::Other;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -451,6 +451,9 @@ QString EventHandler::getBody(const NeoChatRoom *room, const Quotient::RoomEvent
|
|||||||
[](const EncryptedEvent &) {
|
[](const EncryptedEvent &) {
|
||||||
return i18nc("@info In room list", "Encrypted event");
|
return i18nc("@info In room list", "Encrypted event");
|
||||||
},
|
},
|
||||||
|
[](const ReactionEvent &e) {
|
||||||
|
return i18nc("[user] reacted with <emoji>", "reacted with %1", e.key());
|
||||||
|
},
|
||||||
i18n("Unknown event"));
|
i18n("Unknown event"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -590,7 +590,7 @@ TextHandler::textComponents(QString string, Qt::TextFormat inputFormat, const Ne
|
|||||||
string = string.trimmed();
|
string = string.trimmed();
|
||||||
|
|
||||||
if (event != nullptr && room != nullptr) {
|
if (event != nullptr && room != nullptr) {
|
||||||
if (auto e = eventCast<const Quotient::RoomMessageEvent>(event); e->msgtype() == Quotient::MessageEventType::Emote && components.size() == 1) {
|
if (auto e = eventCast<const Quotient::RoomMessageEvent>(event); e && e->msgtype() == Quotient::MessageEventType::Emote && components.size() == 1) {
|
||||||
if (components[0].type == MessageComponentType::Text) {
|
if (components[0].type == MessageComponentType::Text) {
|
||||||
components[0].content = emoteString(room, event) + components[0].content;
|
components[0].content = emoteString(room, event) + components[0].content;
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -512,7 +512,7 @@ QList<MessageComponent> MessageContentModel::messageContentComponents(bool isEdi
|
|||||||
if (isEditing) {
|
if (isEditing) {
|
||||||
newComponents += MessageComponent{MessageComponentType::ChatBar, QString(), {}};
|
newComponents += MessageComponent{MessageComponentType::ChatBar, QString(), {}};
|
||||||
} else {
|
} else {
|
||||||
newComponents.append(componentsForType(MessageComponentType::typeForEvent(*event.first)));
|
newComponents.append(componentsForType(MessageComponentType::typeForEvent(*event.first, m_isReply)));
|
||||||
}
|
}
|
||||||
|
|
||||||
if (m_room->urlPreviewEnabled()) {
|
if (m_room->urlPreviewEnabled()) {
|
||||||
@@ -598,20 +598,23 @@ QList<MessageComponent> MessageContentModel::componentsForType(MessageComponentT
|
|||||||
|
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case MessageComponentType::Text: {
|
case MessageComponentType::Text: {
|
||||||
const auto roomMessageEvent = eventCast<const Quotient::RoomMessageEvent>(event.first);
|
if (const auto roomMessageEvent = eventCast<const Quotient::RoomMessageEvent>(event.first)) {
|
||||||
auto body = EventHandler::rawMessageBody(*roomMessageEvent);
|
auto body = EventHandler::rawMessageBody(*roomMessageEvent);
|
||||||
if (body.trimmed().isEmpty()) {
|
if (body.trimmed().isEmpty()) {
|
||||||
return TextHandler().textComponents(i18n("<i>This event does not have any content.</i>"),
|
return TextHandler().textComponents(i18n("<i>This event does not have any content.</i>"),
|
||||||
Qt::TextFormat::RichText,
|
Qt::TextFormat::RichText,
|
||||||
m_room,
|
m_room,
|
||||||
roomMessageEvent,
|
roomMessageEvent,
|
||||||
roomMessageEvent->isReplaced());
|
roomMessageEvent->isReplaced());
|
||||||
|
} else {
|
||||||
|
return TextHandler().textComponents(body,
|
||||||
|
EventHandler::messageBodyInputFormat(*roomMessageEvent),
|
||||||
|
m_room,
|
||||||
|
roomMessageEvent,
|
||||||
|
roomMessageEvent->isReplaced());
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
return TextHandler().textComponents(body,
|
return TextHandler().textComponents(EventHandler::plainBody(m_room, event.first), Qt::TextFormat::PlainText, m_room, event.first, false);
|
||||||
EventHandler::messageBodyInputFormat(*roomMessageEvent),
|
|
||||||
m_room,
|
|
||||||
roomMessageEvent,
|
|
||||||
roomMessageEvent->isReplaced());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case MessageComponentType::File: {
|
case MessageComponentType::File: {
|
||||||
|
|||||||
Reference in New Issue
Block a user