Skip to content
Draft
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.css
Original file line number Diff line number Diff line change
Expand Up @@ -349,6 +349,10 @@ messagereply label.message {
color: @window_fg_color;
}

messagebubble.outgoing messagereply label.message {
color: currentColor;
}

messagesticker {
border-spacing: 6px;
}
Expand Down
17 changes: 17 additions & 0 deletions src/model/chat.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,8 @@ mod imp {
#[property(get)]
pub(super) title: RefCell<String>,
#[property(get)]
pub(super) theme_name: RefCell<String>,
#[property(get)]
pub(super) avatar: RefCell<Option<model::Avatar>>,
#[property(get)]
pub(super) last_read_outbox_message_id: Cell<i64>,
Expand Down Expand Up @@ -173,6 +175,7 @@ impl Chat {
imp.block_list
.replace(td_chat.block_list.map(model::BoxedBlockList));
imp.title.replace(td_chat.title);
imp.theme_name.replace(td_chat.theme_name);
imp.avatar.replace(td_chat.photo.map(model::Avatar::from));
imp.last_read_outbox_message_id
.set(td_chat.last_read_outbox_message_id);
Expand Down Expand Up @@ -232,6 +235,7 @@ impl Chat {
self.set_last_read_outbox_message_id(update.last_read_outbox_message_id);
}
ChatTitle(update) => self.set_title(update.title),
ChatTheme(update) => self.set_theme_name(update.theme_name),
ChatUnreadMentionCount(update) => {
self.set_unread_mention_count(update.unread_mention_count)
}
Expand Down Expand Up @@ -322,6 +326,19 @@ impl Chat {
self.notify_title();
}

fn set_theme_name(&self, theme_name: String) {
if self.theme_name() == theme_name {
return;
}
self.imp().theme_name.replace(theme_name);
self.notify_theme_name();
}

pub(crate) fn chat_theme(&self) -> Option<tdlib::types::ChatTheme> {
self.session_()
.find_chat_theme(&self.imp().theme_name.borrow())
}

fn set_avatar(&self, avatar: Option<model::Avatar>) {
if self.avatar() == avatar {
return;
Expand Down
33 changes: 33 additions & 0 deletions src/model/client_state_session.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ use glib::prelude::*;
use glib::subclass::prelude::*;
use glib::Properties;
use gtk::glib;
use gtk::glib::subclass::Signal;
use once_cell::sync::Lazy;

use crate::model;
use crate::utils;
Expand All @@ -20,6 +22,7 @@ mod imp {
pub(crate) struct ClientStateSession {
pub(super) filter_chat_lists: RefCell<HashMap<i32, model::ChatList>>,
pub(super) chats: RefCell<HashMap<i64, model::Chat>>,
pub(super) chat_themes: RefCell<Vec<tdlib::types::ChatTheme>>,
pub(super) users: RefCell<HashMap<i64, model::User>>,
pub(super) basic_groups: RefCell<HashMap<i64, model::BasicGroup>>,
pub(super) supergroups: RefCell<HashMap<i64, model::Supergroup>>,
Expand Down Expand Up @@ -52,6 +55,12 @@ mod imp {
}

impl ObjectImpl for ClientStateSession {
fn signals() -> &'static [Signal] {
static SIGNALS: Lazy<Vec<Signal>> =
Lazy::new(|| vec![Signal::builder("update-chat-themes").build()]);
SIGNALS.as_ref()
}

fn properties() -> &'static [glib::ParamSpec] {
Self::derived_properties()
}
Expand Down Expand Up @@ -388,6 +397,25 @@ impl ClientStateSession {
}
}

pub(crate) fn find_chat_theme(&self, name: &str) -> Option<tdlib::types::ChatTheme> {
self.imp()
.chat_themes
.borrow()
.iter()
.find(|theme| theme.name == name)
.cloned()
}

pub(crate) fn connect_update_chat_themes<F>(&self, callback: F) -> glib::SignalHandlerId
where
F: Fn() + 'static,
{
self.connect_local("update-chat-themes", true, move |_| {
callback();
None
})
}

pub(crate) fn handle_update(&self, update: tdlib::enums::Update) {
use tdlib::enums::Update::*;

Expand All @@ -400,6 +428,7 @@ impl ClientStateSession {
}
ChatTitle(ref data) => self.chat(data.chat_id).handle_update(update),
ChatPhoto(ref data) => self.chat(data.chat_id).handle_update(update),
ChatTheme(ref data) => self.chat(data.chat_id).handle_update(update),
ChatPermissions(ref data) => self.chat(data.chat_id).handle_update(update),
ChatLastMessage(ref data) => {
let chat = self.chat(data.chat_id);
Expand Down Expand Up @@ -502,6 +531,10 @@ impl ClientStateSession {
UserStatus(data) => {
self.user(data.user_id).update_status(data.status);
}
ChatThemes(chat_themes) => {
self.imp().chat_themes.replace(chat_themes.chat_themes);
self.emit_by_name::<()>("update-chat-themes", &[]);
}
_ => {}
}
}
Expand Down
Loading