Simplify formatting on Windows

This commit is contained in:
Loren Burkholder 2021-02-26 15:38:15 -05:00 committed by Nicolas Werner
parent 2192e8bea8
commit 3748d7853e
No known key found for this signature in database
GPG key ID: C8D75E610773F2D9
2 changed files with 20 additions and 27 deletions

View file

@ -84,10 +84,9 @@ private:
#if defined(Q_OS_WINDOWS) #if defined(Q_OS_WINDOWS)
private: private:
void systemPostNotification(const QString &roomName, void systemPostNotification(const QString &line1,
const QString &sender, const QString &line2,
const QString &text, const QString &iconPath);
const QImage &icon);
#endif #endif
// these slots are platform specific (D-Bus only) // these slots are platform specific (D-Bus only)

View file

@ -60,39 +60,33 @@ NotificationsManager::postNotification(const mtx::responses::Notification &notif
&notification.event) != nullptr; &notification.event) != nullptr;
const auto isReply = utils::isReply(notification.event); const auto isReply = utils::isReply(notification.event);
if (isEncrypted) { const auto line1 =
// TODO: decrypt this message if the decryption setting is on in the UserSettings (room_name == sender) ? sender : QString("%1 - %2").arg(sender).arg(room_name);
const QString text = (isReply ? tr("%1 replied with an encrypted message") const auto line2 = (isEncrypted ? (isReply ? tr("%1 replied with an encrypted message")
: tr("%1 sent an encrypted message")) : tr("%1 sent an encrypted message"))
.arg(sender); : formatNotification(notification));
systemPostNotification(room_name, sender, text, icon);
} else {
systemPostNotification(room_name, sender, formatNotification(notification), icon);
}
systemPostNotification(room_name, sender, text, icon); auto iconPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) +
room_name + "-room-avatar.png";
if (!icon.save(iconPath))
iconPath.clear();
systemPostNotification(line1, line2, iconPath);
} }
void void
NotificationsManager::systemPostNotification(const QString &roomName, NotificationsManager::systemPostNotification(const QString &line1,
const QString &sender, const QString &line2,
const QString &text, const QString &iconPath)
const QImage &icon)
{ {
if (!isInitialized) if (!isInitialized)
init(); init();
auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02); auto templ = WinToastTemplate(WinToastTemplate::ImageAndText02);
if (roomName != sender) templ.setTextField(line1.toStdWString(), WinToastTemplate::FirstLine);
templ.setTextField(QString("%1 - %2").arg(sender).arg(roomName).toStdWString(), templ.setTextField(line2.toStdWString(), WinToastTemplate::SecondLine);
WinToastTemplate::FirstLine);
else
templ.setTextField(sender.toStdWString(), WinToastTemplate::FirstLine);
templ.setTextField(text.toStdWString(), WinToastTemplate::SecondLine);
auto iconPath = QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + roomName + if (!iconPath.isNull())
"-room-avatar.png";
if (icon.save(iconPath))
templ.setImagePath(iconPath.toStdWString()); templ.setImagePath(iconPath.toStdWString());
WinToast::instance()->showToast(templ, new CustomHandler()); WinToast::instance()->showToast(templ, new CustomHandler());