2021-02-16 02:36:10 +03:00
|
|
|
#include "Manager.h"
|
|
|
|
|
2021-02-20 22:00:13 +03:00
|
|
|
#include <QRegularExpression>
|
2021-02-16 02:36:10 +03:00
|
|
|
#include <QTextDocumentFragment>
|
|
|
|
|
2021-03-17 21:17:57 +03:00
|
|
|
#include "Cache.h"
|
2021-02-20 21:16:43 +03:00
|
|
|
#include "EventAccessors.h"
|
2021-03-17 21:08:17 +03:00
|
|
|
#include "MxcImageProvider.h"
|
2021-02-16 02:36:10 +03:00
|
|
|
#include "Utils.h"
|
|
|
|
|
2021-03-17 21:17:57 +03:00
|
|
|
#include <mtx/responses/notifications.hpp>
|
|
|
|
|
2021-02-26 23:33:27 +03:00
|
|
|
#include <variant>
|
|
|
|
|
2021-02-16 02:36:10 +03:00
|
|
|
QString
|
2021-03-17 21:17:57 +03:00
|
|
|
NotificationsManager::formatNotification(const mtx::responses::Notification ¬ification)
|
2021-02-16 02:36:10 +03:00
|
|
|
{
|
2021-03-17 21:08:17 +03:00
|
|
|
return utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body;
|
2021-03-17 21:17:57 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
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)));
|
|
|
|
|
2021-02-26 23:33:27 +03:00
|
|
|
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);
|
2021-03-17 21:08:17 +03:00
|
|
|
objCxxPostNotification(room_name, messageInfo, "", QImage());
|
2021-02-26 23:33:27 +03:00
|
|
|
} else {
|
|
|
|
const QString messageInfo =
|
|
|
|
(isReply ? tr("%1 replied to a message") : tr("%1 sent a message")).arg(sender);
|
2021-03-17 21:08:17 +03:00
|
|
|
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());
|
2021-02-26 23:33:27 +03:00
|
|
|
}
|
2021-02-16 02:36:10 +03:00
|
|
|
}
|