Separate out a base MessageContentModel.
Separate out a base `MessageContentModel` that can be extended to get the component types from different places. This is used currently for `EventMessageContentModel` but will be used later as part of the rich chat bar. All display text is now in the text component so it never needs special casing. This also cleans up some of the model parameters so more things come from attributes including location and file data (which was already a qvariantmap anyway). Also cleaned up the itinerary and file enhancement views,
This commit is contained in:
@@ -198,6 +198,10 @@ bool EventHandler::isHidden(const NeoChatRoom *room, const Quotient::RoomEvent *
|
||||
|
||||
Qt::TextFormat EventHandler::messageBodyInputFormat(const Quotient::RoomMessageEvent &event)
|
||||
{
|
||||
if (event.isRedacted() && !event.isStateEvent()) {
|
||||
return Qt::RichText;
|
||||
}
|
||||
|
||||
if (event.mimeType().name() == "text/plain"_L1) {
|
||||
return Qt::PlainText;
|
||||
} else {
|
||||
@@ -207,6 +211,11 @@ Qt::TextFormat EventHandler::messageBodyInputFormat(const Quotient::RoomMessageE
|
||||
|
||||
QString EventHandler::rawMessageBody(const Quotient::RoomMessageEvent &event)
|
||||
{
|
||||
if (event.isRedacted() && !event.isStateEvent()) {
|
||||
auto reason = event.redactedBecause()->reason();
|
||||
return (reason.isEmpty()) ? i18n("<i>[This message was deleted]</i>") : i18n("<i>[This message was deleted: %1]</i>", reason.toHtmlEscaped());
|
||||
}
|
||||
|
||||
QString body;
|
||||
|
||||
if (event.has<EventContent::FileContent>()) {
|
||||
|
||||
@@ -7,12 +7,12 @@
|
||||
|
||||
struct MessageComponent {
|
||||
MessageComponentType::Type type = MessageComponentType::Other;
|
||||
QString content;
|
||||
QString display;
|
||||
QVariantMap attributes;
|
||||
|
||||
bool operator==(const MessageComponent &right) const
|
||||
{
|
||||
return type == right.type && content == right.content && attributes == right.attributes;
|
||||
return type == right.type && display == right.display && attributes == right.attributes;
|
||||
}
|
||||
|
||||
bool isEmpty() const
|
||||
|
||||
@@ -1319,6 +1319,19 @@ void NeoChatRoom::copyEventMedia(const QString &eventId)
|
||||
}
|
||||
}
|
||||
|
||||
FileTransferInfo NeoChatRoom::cachedFileTransferInfo(const QString &eventId) const
|
||||
{
|
||||
if (eventId.isEmpty()) {
|
||||
return {};
|
||||
}
|
||||
|
||||
const auto eventResult = getEvent(eventId);
|
||||
if (!eventResult.first) {
|
||||
return {};
|
||||
}
|
||||
return cachedFileTransferInfo(eventResult.first);
|
||||
}
|
||||
|
||||
FileTransferInfo NeoChatRoom::cachedFileTransferInfo(const Quotient::RoomEvent *event) const
|
||||
{
|
||||
QString mxcUrl;
|
||||
|
||||
@@ -544,7 +544,15 @@ public:
|
||||
* @brief Return the cached file transfer information for the event.
|
||||
*
|
||||
* If we downloaded the file previously, return a struct with Completed status
|
||||
* and the local file path stored in KSharedCOnfig
|
||||
* and the local file path stored in KSharedConfig
|
||||
*/
|
||||
Quotient::FileTransferInfo cachedFileTransferInfo(const QString &eventId) const;
|
||||
|
||||
/**
|
||||
* @brief Return the cached file transfer information for the event.
|
||||
*
|
||||
* If we downloaded the file previously, return a struct with Completed status
|
||||
* and the local file path stored in KSharedConfig
|
||||
*/
|
||||
Quotient::FileTransferInfo cachedFileTransferInfo(const Quotient::RoomEvent *event) const;
|
||||
|
||||
|
||||
@@ -592,7 +592,7 @@ TextHandler::textComponents(QString string, Qt::TextFormat inputFormat, const Ne
|
||||
if (event != nullptr && room != nullptr) {
|
||||
if (auto e = eventCast<const Quotient::RoomMessageEvent>(event); e && e->msgtype() == Quotient::MessageEventType::Emote && components.size() == 1) {
|
||||
if (components[0].type == MessageComponentType::Text) {
|
||||
components[0].content = emoteString(room, event) + components[0].content;
|
||||
components[0].display = emoteString(room, event) + components[0].display;
|
||||
} else {
|
||||
components.prepend(MessageComponent{MessageComponentType::Text, emoteString(room, event), {}});
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user