mirror of
https://github.com/Nheko-Reborn/nheko.git
synced 2024-10-30 17:40:47 +03:00
Better handle encrypted notifications
This commit is contained in:
parent
9168c2c785
commit
2192e8bea8
3 changed files with 56 additions and 18 deletions
|
@ -11,6 +11,7 @@
|
||||||
#include <QTextDocumentFragment>
|
#include <QTextDocumentFragment>
|
||||||
|
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
#include <mtx/responses/notifications.hpp>
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
|
||||||
|
@ -194,6 +195,13 @@ NotificationsManager::formatNotification(const mtx::responses::Notification ¬
|
||||||
const auto sender =
|
const auto sender =
|
||||||
cache::displayName(QString::fromStdString(notification.room_id),
|
cache::displayName(QString::fromStdString(notification.room_id),
|
||||||
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
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);
|
||||||
|
|
||||||
const auto messageLeadIn =
|
const auto messageLeadIn =
|
||||||
((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
||||||
? "* " + sender + " "
|
? "* " + sender + " "
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
#include <mtx/responses/notifications.hpp>
|
#include <mtx/responses/notifications.hpp>
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
QString
|
QString
|
||||||
NotificationsManager::formatNotification(const mtx::responses::Notification ¬ification)
|
NotificationsManager::formatNotification(const mtx::responses::Notification ¬ification)
|
||||||
{
|
{
|
||||||
|
@ -37,22 +39,25 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
cache::displayName(QString::fromStdString(notification.room_id),
|
cache::displayName(QString::fromStdString(notification.room_id),
|
||||||
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
||||||
|
|
||||||
const QString messageInfo =
|
|
||||||
QString("%1 %2 a message")
|
|
||||||
.arg(sender)
|
|
||||||
.arg((utils::isReply(notification.event)
|
|
||||||
? tr("replied to",
|
|
||||||
"Used to denote that this message is a reply to another "
|
|
||||||
"message. Displayed as 'foo replied to a message'.")
|
|
||||||
: tr("sent",
|
|
||||||
"Used to denote that this message is a normal message. Displayed as 'foo "
|
|
||||||
"sent a message'.")));
|
|
||||||
|
|
||||||
QString text = formatNotification(notification);
|
|
||||||
|
|
||||||
QImage *image = nullptr;
|
QImage *image = nullptr;
|
||||||
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image)
|
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Image)
|
||||||
image = new QImage{cacheImage(notification.event)};
|
image = new QImage{cacheImage(notification.event)};
|
||||||
|
|
||||||
objCxxPostNotification(room_name, messageInfo, text, image);
|
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);
|
||||||
|
} 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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
#include <QStandardPaths>
|
#include <QStandardPaths>
|
||||||
#include <QTextDocumentFragment>
|
#include <QTextDocumentFragment>
|
||||||
|
|
||||||
|
#include <variant>
|
||||||
|
|
||||||
#include "Cache.h"
|
#include "Cache.h"
|
||||||
#include "EventAccessors.h"
|
#include "EventAccessors.h"
|
||||||
#include "Utils.h"
|
#include "Utils.h"
|
||||||
|
@ -52,7 +54,21 @@ NotificationsManager::postNotification(const mtx::responses::Notification ¬if
|
||||||
const auto sender =
|
const auto sender =
|
||||||
cache::displayName(QString::fromStdString(notification.room_id),
|
cache::displayName(QString::fromStdString(notification.room_id),
|
||||||
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
||||||
const auto text = formatNotification(notification);
|
|
||||||
|
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 text = (isReply ? tr("%1 replied with an encrypted message")
|
||||||
|
: tr("%1 sent an encrypted message"))
|
||||||
|
.arg(sender);
|
||||||
|
systemPostNotification(room_name, sender, text, icon);
|
||||||
|
} else {
|
||||||
|
systemPostNotification(room_name, sender, formatNotification(notification), icon);
|
||||||
|
}
|
||||||
|
|
||||||
systemPostNotification(room_name, sender, text, icon);
|
systemPostNotification(room_name, sender, text, icon);
|
||||||
}
|
}
|
||||||
|
@ -98,11 +114,20 @@ NotificationsManager::formatNotification(const mtx::responses::Notification ¬
|
||||||
cache::displayName(QString::fromStdString(notification.room_id),
|
cache::displayName(QString::fromStdString(notification.room_id),
|
||||||
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
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'.")
|
||||||
|
: "") +
|
||||||
|
": ");
|
||||||
|
|
||||||
return QTextDocumentFragment::fromHtml(
|
return QTextDocumentFragment::fromHtml(
|
||||||
mtx::accessors::formattedBodyWithFallback(notification.event)
|
mtx::accessors::formattedBodyWithFallback(notification.event)
|
||||||
.replace(QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), ""))
|
.replace(QRegularExpression("(<mx-reply>.+\\<\\/mx-reply\\>)"), ""))
|
||||||
.toPlainText()
|
.toPlainText()
|
||||||
.prepend((mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote)
|
.prepend(messageLeadIn);
|
||||||
? "* " + sender + " "
|
|
||||||
: "");
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue