mirror of https://github.com/Nheko-Reborn/nheko
commit
f6de66576c
@ -0,0 +1,40 @@ |
||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "notifications/Manager.h" |
||||
|
||||
#include "Cache.h" |
||||
#include "EventAccessors.h" |
||||
#include "Utils.h" |
||||
|
||||
QString |
||||
NotificationsManager::getMessageTemplate(const mtx::responses::Notification ¬ification) |
||||
{ |
||||
const auto sender = |
||||
cache::displayName(QString::fromStdString(notification.room_id), |
||||
QString::fromStdString(mtx::accessors::sender(notification.event))); |
||||
|
||||
// TODO: decrypt this message if the decryption setting is on in the UserSettings
|
||||
if (auto msg = std::get_if<mtx::events::EncryptedEvent<mtx::events::msg::Encrypted>>( |
||||
¬ification.event); |
||||
msg != nullptr) { |
||||
return tr("%1 sent an encrypted message").arg(sender); |
||||
} |
||||
|
||||
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) { |
||||
return tr("* %1 %2", |
||||
"Format an emote message in a notification, %1 is the sender, %2 the " |
||||
"message") |
||||
.arg(sender); |
||||
} else if (utils::isReply(notification.event)) { |
||||
return tr("%1 replied: %2", |
||||
"Format a reply in a notification. %1 is the sender, %2 the message") |
||||
.arg(sender); |
||||
} else { |
||||
return tr("%1: %2", |
||||
"Format a normal message in a notification. %1 is the sender, %2 the " |
||||
"message") |
||||
.arg(sender); |
||||
} |
||||
} |
@ -0,0 +1,66 @@ |
||||
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
||||
//
|
||||
// SPDX-License-Identifier: GPL-3.0-or-later
|
||||
|
||||
#include "Manager.h" |
||||
|
||||
#include <QRegularExpression> |
||||
#include <QTextDocumentFragment> |
||||
|
||||
#include "Cache.h" |
||||
#include "EventAccessors.h" |
||||
#include "MxcImageProvider.h" |
||||
#include "Utils.h" |
||||
|
||||
#include <mtx/responses/notifications.hpp> |
||||
|
||||
#include <variant> |
||||
|
||||
static QString |
||||
formatNotification(const mtx::responses::Notification ¬ification) |
||||
{ |
||||
return utils::stripReplyFallbacks(notification.event, {}, {}).quoted_body; |
||||
} |
||||
|
||||
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))); |
||||
|
||||
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, "", QImage()); |
||||
} else { |
||||
const QString messageInfo = |
||||
(isReply ? tr("%1 replied to a message") : tr("%1 sent a message")).arg(sender); |
||||
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…
Reference in new issue