// SPDX-FileCopyrightText: Nheko Contributors // // SPDX-License-Identifier: GPL-3.0-or-later #include "Manager.h" #include #include #include #include "Cache.h" #include "EventAccessors.h" #include "MxcImageProvider.h" #include "Utils.h" #include #include static QString formatNotification(const mtx::responses::Notification ¬ification) { auto fallbacks = utils::stripReplyFallbacks(notification.event, {}, {}); bool containsSpoiler = fallbacks.quoted_formatted_body.contains(">( ¬ification.event) != nullptr; const auto isReply = utils::isReply(notification.event); auto playSound = false; if (std::find(notification.actions.begin(), notification.actions.end(), mtx::pushrules::actions::Action{mtx::pushrules::actions::set_tweak_sound{ .value = "default"}}) != notification.actions.end()) { playSound = true; } 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, room_id, event_id, messageInfo, "", "", playSound); } 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, room_id, event_id, messageInfo, playSound]( QString, QSize, QImage, QString imgPath) { objCxxPostNotification(room_name, room_id, event_id, messageInfo, formatNotification(notification), imgPath, playSound); }); else objCxxPostNotification(room_name, room_id, event_id, messageInfo, formatNotification(notification), "", playSound); } }