Format markup-lacking Linux notifications using lng_dialogs_text_with_from

This commit is contained in:
Ilya Fedin 2025-04-11 14:01:09 +00:00 committed by John Preston
parent 25cd6106f5
commit 9bdc19e2fd

View file

@ -537,17 +537,23 @@ void Manager::Private::showNotification(
.msgId = info.itemId,
};
auto notification = _application
? Gio::Notification::new_(
info.subtitle.isEmpty()
? info.title.toStdString()
: info.subtitle.toStdString()
+ " (" + info.title.toStdString() + ')')
? Gio::Notification::new_(info.title.toStdString())
: Gio::Notification();
std::vector<gi::cstring> actions;
auto hints = GLib::VariantDict::new_();
if (notification) {
notification.set_body(info.message.toStdString());
notification.set_body(info.subtitle.isEmpty()
? info.message.toStdString()
: tr::lng_dialogs_text_with_from(
tr::now,
lt_from_part,
tr::lng_dialogs_text_from_wrapped(
tr::now,
lt_from,
info.subtitle),
lt_message,
info.message).toStdString());
notification.set_icon(
Gio::ThemedIcon::new_(ApplicationIconName().toStdString()));
@ -726,8 +732,6 @@ void Manager::Private::showNotification(
const auto hasImage = !imageKey.empty()
&& hints.lookup_value(imageKey);
const auto hasBodyMarkup = HasCapability("body-markup");
const auto callbackWrap = gi::unwrap(
Gio::AsyncReadyCallback(
crl::guard(this, [=](
@ -766,17 +770,24 @@ void Manager::Private::showNotification(
(!hasImage
? ApplicationIconName().toStdString()
: std::string()).c_str(),
(hasBodyMarkup || info.subtitle.isEmpty()
? info.title.toStdString()
: info.subtitle.toStdString()
+ " (" + info.title.toStdString() + ')').c_str(),
(hasBodyMarkup
info.title.toStdString().c_str(),
(HasCapability("body-markup")
? info.subtitle.isEmpty()
? info.message.toHtmlEscaped().toStdString()
: u"<b>%1</b>\n%2"_q.arg(
info.subtitle.toHtmlEscaped(),
info.message.toHtmlEscaped()).toStdString()
: info.message.toStdString()).c_str(),
: info.subtitle.isEmpty()
? info.message.toStdString()
: tr::lng_dialogs_text_with_from(
tr::now,
lt_from_part,
tr::lng_dialogs_text_from_wrapped(
tr::now,
lt_from,
info.subtitle),
lt_message,
info.message).toStdString()).c_str(),
!actions.empty()
? (actions
| ranges::views::transform(&gi::cstring::c_str)