2021-03-17 21:14:25 +03:00
|
|
|
// SPDX-FileCopyrightText: 2021 Nheko Contributors
|
|
|
|
//
|
|
|
|
// SPDX-License-Identifier: GPL-3.0-or-later
|
|
|
|
|
2021-02-16 02:36:10 +03:00
|
|
|
#include "notifications/Manager.h"
|
|
|
|
|
|
|
|
#include "Cache.h"
|
|
|
|
#include "EventAccessors.h"
|
|
|
|
#include "Utils.h"
|
|
|
|
|
2021-03-17 21:17:57 +03:00
|
|
|
QString
|
2021-03-17 21:08:17 +03:00
|
|
|
NotificationsManager::getMessageTemplate(const mtx::responses::Notification ¬ification)
|
2021-02-16 02:36:10 +03:00
|
|
|
{
|
2021-09-18 01:22:33 +03:00
|
|
|
const auto sender =
|
|
|
|
cache::displayName(QString::fromStdString(notification.room_id),
|
|
|
|
QString::fromStdString(mtx::accessors::sender(notification.event)));
|
2021-03-17 21:08:17 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
// 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);
|
|
|
|
}
|
2021-03-17 21:08:17 +03:00
|
|
|
|
2021-09-18 01:22:33 +03:00
|
|
|
if (mtx::accessors::msg_type(notification.event) == mtx::events::MessageType::Emote) {
|
2021-10-01 04:24:28 +03:00
|
|
|
return QString("* %1 %2").arg(sender);
|
2021-09-18 01:22:33 +03:00
|
|
|
} 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 {
|
2021-10-01 04:24:28 +03:00
|
|
|
return QString("%1: %2").arg(sender);
|
2021-09-18 01:22:33 +03:00
|
|
|
}
|
2021-02-16 02:36:10 +03:00
|
|
|
}
|