Clean up notification code a bit

This commit is contained in:
Nicolas Werner 2021-03-17 19:08:17 +01:00
parent 95026dcc62
commit e5d75c814b
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
16 changed files with 204 additions and 474 deletions

View file

@ -108,20 +108,11 @@ NotificationsManager::formatNotification(const mtx::responses::Notification &not
cache::displayName(QString::fromStdString(notification.room_id),
QString::fromStdString(mtx::accessors::sender(notification.event)));
const auto messageLeadIn =
((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
? "* " + sender + " "
: sender +
(utils::isReply(notification.event)
? tr(" replied",
"Used to denote that this message is a reply to another "
"message. Displayed as 'foo replied: message'.")
: "") +
": ");
const auto template_ = getMessageTemplate(notification);
if (std::holds_alternative<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
notification.event)) {
return template_;
}
return QTextDocumentFragment::fromHtml(
mtx::accessors::formattedBodyWithFallback(notification.event)
.replace(QRegularExpression("<mx-reply>.+</mx-reply>"), ""))
.toPlainText()
.prepend(messageLeadIn);
return template_.arg(utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body);
}