#include "Manager.h" #include #include #include "Cache.h" #include "EventAccessors.h" #include "Utils.h" #include #include 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(".+"), "")) .toPlainText() .prepend((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) ? "* " + sender + " " : ""); } void NotificationsManager::postNotification(const mtx::responses::Notification ¬ification, const QImage &icon) { Q_UNUSED(icon) const auto room_name = QString::fromStdString(cache::singleRoomInfo(notification.room_id).name); const auto sender = cache::displayName(QString::fromStdString(notification.room_id), QString::fromStdString(mtx::accessors::sender(notification.event))); QImage *image = nullptr; if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image) image = new QImage{cacheImage(notification.event)}; const auto isEncrypted = std::get_if>( ¬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); } 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 != nullptr && !image->isNull()) ? image : nullptr); } }