Browse Source

notifications: Don't use Session as the helper widget

merge-requests/1327/merge
Kévin Commaille 3 years ago
parent
commit
af92711df0
No known key found for this signature in database
GPG Key ID: 29A48C1F03620416
  1. 13
      src/session/avatar/data.rs
  2. 5
      src/session/notifications.rs

13
src/session/avatar/data.rs

@ -1,7 +1,10 @@
use gtk::{gdk, glib, prelude::*, subclass::prelude::*};
use super::AvatarImage;
use crate::utils::notifications::{paintable_as_notification_icon, string_as_notification_icon};
use crate::{
application::Application,
utils::notifications::{paintable_as_notification_icon, string_as_notification_icon},
};
mod imp {
use std::cell::RefCell;
@ -109,11 +112,13 @@ impl AvatarData {
/// Get this avatar as a notification icon.
///
/// Returns `None` if an error occurred while generating the icon.
pub fn as_notification_icon(&self, helper_widget: &gtk::Widget) -> Option<gdk::Texture> {
pub fn as_notification_icon(&self) -> Option<gdk::Texture> {
let window = Application::default().main_window().upcast();
let icon = if let Some(paintable) = self.image().paintable() {
paintable_as_notification_icon(paintable.upcast_ref(), helper_widget)
paintable_as_notification_icon(paintable.upcast_ref(), &window)
} else {
string_as_notification_icon(&self.display_name().unwrap_or_default(), helper_widget)
string_as_notification_icon(&self.display_name().unwrap_or_default(), &window)
};
match icon {

5
src/session/notifications.rs

@ -156,10 +156,7 @@ impl Notifications {
.set_default_action_and_target_value("app.show-room", Some(&payload.to_variant()));
notification.set_body(Some(&body));
if let Some(icon) = room
.avatar_data()
.as_notification_icon(session.upcast_ref())
{
if let Some(icon) = room.avatar_data().as_notification_icon() {
notification.set_icon(&icon);
}

Loading…
Cancel
Save