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

Add secret chat style #625

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
2 changes: 2 additions & 0 deletions data/resources/icons/scalable/status/padlock2-symbolic.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 1 addition & 0 deletions data/resources/resources.gresource.xml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
<file preprocess="xml-stripblanks">icons/scalable/status/message-read-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/status/message-unread-left-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/status/message-unread-right-symbolic.svg</file>
<file preprocess="xml-stripblanks">icons/scalable/status/padlock2-symbolic.svg</file>

<file compressed="true">images/pattern.svg</file>

Expand Down
28 changes: 28 additions & 0 deletions src/ui/session/content/chat_history.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ mod imp {
pub(super) is_auto_scrolling: Cell<bool>,
pub(super) is_loading_messages: Cell<bool>,
pub(super) sticky: Cell<bool>,
pub(super) is_secret_chat: Cell<bool>,
#[template_child]
pub(super) window_title: TemplateChild<adw::WindowTitle>,
#[template_child]
Expand Down Expand Up @@ -92,6 +93,9 @@ mod imp {
glib::ParamSpecBoolean::builder("sticky")
.read_only()
.build(),
glib::ParamSpecBoolean::builder("is-secret-chat")
.read_only()
.build(),
]
});
PROPERTIES.as_ref()
Expand All @@ -106,6 +110,7 @@ mod imp {
obj.set_chat(chat);
}
"sticky" => obj.set_sticky(value.get().unwrap()),
"is_secret_chat" => obj.set_is_secret_chat(value.get().unwrap()),
_ => unimplemented!(),
}
}
Expand All @@ -116,6 +121,7 @@ mod imp {
match pspec.name() {
"chat" => obj.chat().to_value(),
"sticky" => obj.sticky().to_value(),
"is-secret-chat" => obj.is_secret_chat().to_value(),
_ => unimplemented!(),
}
}
Expand Down Expand Up @@ -311,6 +317,15 @@ impl ChatHistory {
let imp = self.imp();

if let Some(chat) = chat {
match chat.chat_type() {
model::ChatType::Secret(_) => {
self.set_is_secret_chat(true);
}
_ => {
self.set_is_secret_chat(false);
}
}

self.action_set_enabled(
"chat-history.leave-chat",
match chat.chat_type() {
Expand Down Expand Up @@ -412,6 +427,19 @@ impl ChatHistory {
self.notify("sticky");
}

pub(crate) fn is_secret_chat(&self) -> bool {
self.imp().is_secret_chat.get()
}

fn set_is_secret_chat(&self, is_secret_chat: bool) {
if self.is_secret_chat() == is_secret_chat {
return;
}

self.imp().is_secret_chat.set(is_secret_chat);
self.notify("is-secret-chat");
}

fn scroll_down(&self) {
let imp = self.imp();

Expand Down
13 changes: 12 additions & 1 deletion src/ui/session/content/chat_history.ui
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,18 @@
<child>
<object class="AdwHeaderBar">
<child type="title">
<object class="AdwWindowTitle" id="window_title"/>
<object class="GtkBox">
<child>
<object class="GtkImage">
<property name="visible" bind-source="PaplChatHistory"
bind-property="is-secret-chat" bind-flags="sync-create" />
<property name="icon-name">padlock2-symbolic</property>
</object>
</child>
<child>
<object class="AdwWindowTitle" id="window_title"/>
</child>
</object>
</child>
<child type="end">
<object class="GtkMenuButton">
Expand Down
2 changes: 2 additions & 0 deletions src/ui/session/sidebar/row.blp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ template $PaplSidebarRow {
Box {
spacing: 6;

Image secret_chat_icon {}

Inscription title_label {
hexpand: true;
text-overflow: ellipsize_end;
Expand Down
23 changes: 23 additions & 0 deletions src/ui/session/sidebar/row.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ mod imp {
pub(super) chat_signal_group: OnceCell<glib::SignalGroup>,
pub(super) session_signal_group: OnceCell<glib::SignalGroup>,
#[template_child]
pub(super) secret_chat_icon: TemplateChild<gtk::Image>,
#[template_child]
pub(super) title_label: TemplateChild<gtk::Inscription>,
#[template_child]
pub(super) message_status_icon: TemplateChild<gtk::Image>,
Expand Down Expand Up @@ -368,6 +370,7 @@ impl Row {
self.update_status_stack();
self.update_unread_count_style();
self.update_actions();
self.update_secret_chat_style();

self.notify("item");
}
Expand Down Expand Up @@ -580,6 +583,26 @@ impl Row {
}
}

fn update_secret_chat_style(&self) {
if let Some(item) = self.item() {
let imp = self.imp();
let chat = item.chat_();
let icon = &imp.secret_chat_icon;
match chat.chat_type() {
model::ChatType::Secret(_) => {
icon.set_icon_name(Some("padlock2-symbolic"));
icon.set_css_classes(&["accent"]);
icon.set_visible(true);
let title_label = &imp.title_label;
title_label.set_css_classes(&["accent"]);
}
_ => {
icon.set_visible(false);
}
}
}
}

fn update_archive_actions(&self, archive: bool, unarchive: bool) {
self.action_set_enabled("sidebar-row.archive", archive);
self.action_set_enabled("sidebar-row.unarchive", unarchive);
Expand Down