Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sidebar-chat-row: Use other unread count bg for muted chats #137

Merged
merged 1 commit into from
Nov 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions data/resources/style-dark.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
.chat-list row .unread-count-muted {
background-color: @dark_1;
}

.chat-history row .message-bubble:not(.outgoing) {
background-color: alpha(white, 0.1);
}
Expand Down
9 changes: 8 additions & 1 deletion data/resources/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
}

.chat-list row .unread-count {
background-color: @accent_bg_color;
color: @accent_fg_color;
font-size: 0.8em;
font-weight: bold;
Expand All @@ -24,6 +23,14 @@
padding: 2px 5px;
}

.chat-list row .unread-count-unmuted {
background-color: @accent_bg_color;
}

.chat-list row .unread-count-muted {
background-color: @light_5;
}

.chat-history listview {
padding: 3px 0;
}
Expand Down
5 changes: 1 addition & 4 deletions data/resources/ui/sidebar-chat-row.ui
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
</object>
</child>
<child>
<object class="GtkLabel">
<object class="GtkLabel" id="unread_count_label">
<property name="valign">center</property>
<property name="ellipsize">end</property>
<property name="justify">center</property>
Expand All @@ -86,9 +86,6 @@
<lookup name="chat">SidebarChatRow</lookup>
</lookup>
</binding>
<style>
<class name="unread-count"/>
</style>
</object>
</child>
</object>
Expand Down
50 changes: 49 additions & 1 deletion src/session/chat/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use gtk::glib;
use gtk::prelude::*;
use gtk::subclass::prelude::*;
use tdgrand::enums::{self, ChatType, Update};
use tdgrand::types::Chat as TelegramChat;
use tdgrand::types::{Chat as TelegramChat, ChatNotificationSettings};

use crate::session::Avatar;
use crate::Session;
Expand All @@ -19,6 +19,10 @@ use crate::Session;
#[gboxed(type_name = "BoxedChatType")]
pub struct BoxedChatType(ChatType);

#[derive(Clone, Debug, glib::GBoxed)]
#[gboxed(type_name = "BoxedChatNotificationSettings")]
pub struct BoxedChatNotificationSettings(pub ChatNotificationSettings);

mod imp {
use super::*;
use once_cell::sync::{Lazy, OnceCell};
Expand All @@ -35,6 +39,7 @@ mod imp {
pub is_pinned: Cell<bool>,
pub unread_count: Cell<i32>,
pub draft_message: RefCell<String>,
pub notification_settings: RefCell<Option<BoxedChatNotificationSettings>>,
pub history: OnceCell<History>,
pub session: OnceCell<Session>,
}
Expand Down Expand Up @@ -119,6 +124,13 @@ mod imp {
None,
glib::ParamFlags::READWRITE,
),
glib::ParamSpec::new_boxed(
"notification-settings",
"Notification Settings",
"The notification settings of this chat",
BoxedChatNotificationSettings::static_type(),
glib::ParamFlags::READWRITE,
),
glib::ParamSpec::new_object(
"history",
"History",
Expand Down Expand Up @@ -182,6 +194,11 @@ mod imp {
let draft_message = value.get().unwrap();
self.draft_message.replace(draft_message);
}
"notification-settings" => {
let notification_settings = value.get().unwrap();
self.notification_settings
.replace(Some(notification_settings));
}
"session" => {
let session = value.get().unwrap();
self.session.set(session).unwrap();
Expand All @@ -200,6 +217,12 @@ mod imp {
"is-pinned" => self.is_pinned.get().to_value(),
"unread-count" => self.unread_count.get().to_value(),
"draft-message" => self.draft_message.borrow().to_value(),
"notification-settings" => self
.notification_settings
.borrow()
.as_ref()
.unwrap()
.to_value(),
"history" => self.history.get().to_value(),
"session" => self.session.get().to_value(),
_ => unimplemented!(),
Expand Down Expand Up @@ -234,6 +257,10 @@ impl Chat {
("title", &chat.title),
("avatar", &avatar),
("unread-count", &chat.unread_count),
(
"notification-settings",
&BoxedChatNotificationSettings(chat.notification_settings),
),
("session", &session),
])
.expect("Failed to create Chat")
Expand Down Expand Up @@ -278,6 +305,9 @@ impl Chat {
}
}
}
Update::ChatNotificationSettings(update) => {
self.set_notification_settings(update.notification_settings);
}
Update::ChatPosition(update) => {
if let enums::ChatList::Main = update.position.list {
self.set_order(update.position.order);
Expand Down Expand Up @@ -382,6 +412,24 @@ impl Chat {
}
}

pub fn notification_settings(&self) -> ChatNotificationSettings {
self.property("notification-settings")
.unwrap()
.get::<BoxedChatNotificationSettings>()
.unwrap()
.0
}

fn set_notification_settings(&self, notification_settings: ChatNotificationSettings) {
if self.notification_settings() != notification_settings {
self.set_property(
"notification-settings",
&BoxedChatNotificationSettings(notification_settings),
)
.unwrap();
}
}

pub fn history(&self) -> History {
self.property("history").unwrap().get().unwrap()
}
Expand Down
5 changes: 5 additions & 0 deletions src/session/chat_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ impl ChatList {
chat.handle_update(update);
}
}
Update::ChatNotificationSettings(ref update_) => {
if let Some(chat) = self_.list.borrow().get(&update_.chat_id) {
chat.handle_update(update);
}
}
Update::ChatPosition(ref update_) => {
if let Some(chat) = self_.list.borrow().get(&update_.chat_id) {
chat.handle_update(update);
Expand Down
1 change: 1 addition & 0 deletions src/session/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ impl Session {
| Update::ChatTitle(_)
| Update::ChatPhoto(_)
| Update::ChatLastMessage(_)
| Update::ChatNotificationSettings(_)
| Update::ChatPosition(_)
| Update::ChatReadInbox(_)
| Update::ChatDraftMessage(_)
Expand Down
32 changes: 31 additions & 1 deletion src/session/sidebar/chat_row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use gettextrs::gettext;
use gtk::{glib, prelude::*, subclass::prelude::*};
use tdgrand::enums::{ChatType, MessageContent};

use crate::session::chat::{Message, MessageSender};
use crate::session::chat::{BoxedChatNotificationSettings, Message, MessageSender};
use crate::session::components::Avatar;
use crate::session::Chat;
use crate::utils::{dim_and_escape, escape};
Expand All @@ -24,6 +24,8 @@ mod imp {
pub last_message_label: TemplateChild<gtk::Label>,
#[template_child]
pub pin_image: TemplateChild<gtk::Image>,
#[template_child]
pub unread_count_label: TemplateChild<gtk::Label>,
}

#[glib::object_subclass]
Expand Down Expand Up @@ -214,6 +216,34 @@ impl ChatRow {
);
let pin_image = self_.pin_image.get();
pin_visibility_expression.bind(&pin_image, "visible", Some(&pin_image));

let notification_settings_expression = gtk::PropertyExpression::new(
Chat::static_type(),
Some(&chat_expression),
"notification-settings",
);
let unread_count_label_css_expression = gtk::ClosureExpression::new(
|args| {
let notification_settings =
args[1].get::<BoxedChatNotificationSettings>().unwrap().0;

vec![
"unread-count".to_string(),
if notification_settings.mute_for > 0 {
"unread-count-muted"
} else {
"unread-count-unmuted"
}
.to_string(),
]
},
&[notification_settings_expression.upcast()],
);
unread_count_label_css_expression.bind(
&*self_.unread_count_label,
"css-classes",
gtk::NONE_WIDGET,
);
}

self_.chat.replace(chat);
Expand Down