Clean up notification code a bit
This commit is contained in:
parent
95026dcc62
commit
e5d75c814b
16 changed files with 204 additions and 474 deletions
|
|
@ -5,6 +5,7 @@
|
|||
|
||||
#include "Cache.h"
|
||||
#include "EventAccessors.h"
|
||||
#include "MxcImageProvider.h"
|
||||
#include "Utils.h"
|
||||
|
||||
#include <mtx/responses/notifications.hpp>
|
||||
|
|
@ -14,17 +15,7 @@
|
|||
QString
|
||||
NotificationsManager::formatNotification(const mtx::responses::Notification ¬ification)
|
||||
{
|
||||
const auto sender =
|
||||
cache::displayName(QString::fromStdString(notification.room_id),
|
||||
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
||||
|
||||
return QTextDocumentFragment::fromHtml(
|
||||
mtx::accessors::formattedBodyWithFallback(notification.event)
|
||||
.replace(QRegularExpression("<mx-reply>.+</mx-reply>"), ""))
|
||||
.toPlainText()
|
||||
.prepend((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
||||
? "* " + sender + " "
|
||||
: "");
|
||||
return utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body;
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -39,25 +30,33 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
|||
cache::displayName(QString::fromStdString(notification.room_id),
|
||||
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
||||
|
||||
QImage image;
|
||||
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image)
|
||||
image = QImage{cacheImage(notification.event)};
|
||||
|
||||
const auto isEncrypted =
|
||||
std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>(
|
||||
¬ification.event) != nullptr;
|
||||
const auto isReply = utils::isReply(notification.event);
|
||||
|
||||
if (isEncrypted) {
|
||||
// TODO: decrypt this message if the decryption setting is on in the UserSettings
|
||||
const QString messageInfo = (isReply ? tr("%1 replied with an encrypted message")
|
||||
: tr("%1 sent an encrypted message"))
|
||||
.arg(sender);
|
||||
objCxxPostNotification(room_name, messageInfo, "", image);
|
||||
objCxxPostNotification(room_name, messageInfo, "", QImage());
|
||||
} else {
|
||||
const QString messageInfo =
|
||||
(isReply ? tr("%1 replied to a message") : tr("%1 sent a message")).arg(sender);
|
||||
objCxxPostNotification(
|
||||
room_name, messageInfo, formatNotification(notification), image);
|
||||
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image)
|
||||
MxcImageProvider::download(
|
||||
QString::fromStdString(mtx::accessors::url(notification.event))
|
||||
.remove("mxc://"),
|
||||
QSize(200, 80),
|
||||
[this, notification, room_name, messageInfo](
|
||||
QString, QSize, QImage image, QString) {
|
||||
objCxxPostNotification(room_name,
|
||||
messageInfo,
|
||||
formatNotification(notification),
|
||||
image);
|
||||
});
|
||||
else
|
||||
objCxxPostNotification(
|
||||
room_name, messageInfo, formatNotification(notification), QImage());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue