aboutsummaryrefslogtreecommitdiff
path: root/main/src/ui/chat_input
diff options
context:
space:
mode:
authorMarvin W <git@larma.de>2026-03-14 13:42:58 +0800
committerMarvin W <git@larma.de>2026-04-08 19:02:44 +0200
commit64757cbe2572259ad201f4c691aeb545088ae42a (patch)
tree6c3de38252417500ab1234687bd413e29dcc4d1b /main/src/ui/chat_input
parent82da21c1a67d5a50d0a4940b5e3c687929b041c2 (diff)
Add implementation for XEP-0202 Entity Time
Diffstat (limited to 'main/src/ui/chat_input')
-rw-r--r--main/src/ui/chat_input/view.vala97
1 files changed, 97 insertions, 0 deletions
diff --git a/main/src/ui/chat_input/view.vala b/main/src/ui/chat_input/view.vala
index dbb1f74e..8b57a08d 100644
--- a/main/src/ui/chat_input/view.vala
+++ b/main/src/ui/chat_input/view.vala
@@ -26,11 +26,18 @@ public class View : Box {
[GtkChild] public unowned MenuButton encryption_button;
[GtkChild] public unowned Separator file_separator;
[GtkChild] public unowned Label chat_input_status;
+ [GtkChild] public unowned Box unavailable_box;
+ [GtkChild] public unowned Image unavailable_icon;
+ [GtkChild] public unowned Label unavailable_label;
public EncryptionButton encryption_widget;
+ private bool is_dnd = false;
+ private bool is_night = false;
+
public View init(StreamInteractor stream_interactor) {
this.stream_interactor = stream_interactor;
+ stream_interactor.get_module(PresenceManager.IDENTITY).show_received.connect(on_show_received);
encryption_widget = new EncryptionButton(stream_interactor, encryption_button);
@@ -61,9 +68,99 @@ public class View : Box {
chat_text_view.text_view.buffer.text = entry_cache[conversation];
}
+ update_unavailable_message();
+
do_focus();
}
+ private void on_show_received(Jid jid, Account account) {
+ if (this.conversation.type_ == Conversation.Type.CHAT && this.conversation.counterpart.equals_bare(jid)) {
+ update_unavailable_message();
+ }
+ }
+
+ private void update_unavailable_message() {
+ if (conversation.type_ != Conversation.Type.CHAT) {
+ is_dnd = false;
+ is_night = false;
+ set_unavailable_message(null, null);
+ } else {
+ PresenceManager presence_manager = stream_interactor.get_module(PresenceManager.IDENTITY);
+ Gee.List<Jid>? full_jids = presence_manager.get_full_jids(conversation.counterpart, conversation.account);
+ if (full_jids != null) {
+ foreach (Jid full_jid in full_jids) {
+ if (presence_manager.get_last_show(full_jid, conversation.account) == Presence.Stanza.SHOW_DND) {
+ if (update_utc_offset_minutes_timeout != 0) {
+ Source.remove(update_utc_offset_minutes_timeout);
+ update_utc_offset_minutes_timeout = 0;
+ }
+ is_dnd = true;
+ set_unavailable_message(Markup.printf_escaped(_("%s has <b>paused their notifications</b>"), Util.get_conversation_display_name(stream_interactor, conversation)), "dino-bell-large-none-symbolic", true);
+ return;
+ }
+ }
+ }
+ is_dnd = false;
+ update_utc_offset_minutes();
+ }
+ }
+
+ private uint update_utc_offset_minutes_timeout = 0;
+ private void update_utc_offset_minutes() {
+ Conversation conversation = this.conversation;
+ if (update_utc_offset_minutes_timeout != 0) {
+ Source.remove(update_utc_offset_minutes_timeout);
+ update_utc_offset_minutes_timeout = 0;
+ }
+ if (conversation.type_ == Conversation.Type.CHAT) {
+ stream_interactor.get_module(EntityInfo.IDENTITY).get_utc_offset_minutes_for_bare_jid.begin(conversation.account, conversation.counterpart, (_, res) => {
+ set_utc_offset_minutes(conversation, stream_interactor.get_module(EntityInfo.IDENTITY).get_utc_offset_minutes_for_bare_jid.end(res));
+ update_utc_offset_minutes_timeout = WeakTimeout.add_once(60000 - (int) (new DateTime.now_utc().get_seconds()*1000d), this, update_utc_offset_minutes);
+ });
+ }
+ }
+
+ private void set_utc_offset_minutes(Conversation conversation, int utc_offset_minutes) {
+ if (this.conversation != conversation) return;
+ string? display_time = null;
+ if (utc_offset_minutes != int.MIN && new DateTime.now_local().get_utc_offset() / TimeSpan.MINUTE != utc_offset_minutes) {
+ var datetime = new DateTime.now(new TimeZone.offset(utc_offset_minutes * 60));
+ if (datetime.get_hour() >= 22 || datetime.get_hour() < 8) {
+ display_time = datetime.format(Util.is_24h_format() ?
+ /* xgettext:no-c-format */ /* Time in 24h format (w/o seconds) */ _("%H∶%M") :
+ /* xgettext:no-c-format */ /* Time in 12h format (w/o seconds) */ _("%l∶%M %p"));
+ }
+ }
+ is_night = (display_time != null);
+ if (!is_dnd) {
+ if (!is_night) {
+ set_unavailable_message(null, null);
+ } else {
+ set_unavailable_message(Markup.printf_escaped(_("It's <b>%s</b> for %s"), display_time, Util.get_conversation_display_name(stream_interactor, conversation)), "dino-clock-alt-symbolic", true);
+ }
+ }
+ }
+
+ private void set_unavailable_message(string? message, string? icon, bool use_markup = false) {
+ if (message == null) {
+ unavailable_box.visible = false;
+ } else {
+ if (use_markup) {
+ unavailable_label.set_markup(message);
+ } else {
+ unavailable_label.use_markup = use_markup;
+ unavailable_label.label = message;
+ }
+ unavailable_box.visible = true;
+ }
+ if (icon == null) {
+ unavailable_icon.opacity = 0;
+ } else {
+ unavailable_icon.icon_name = icon;
+ unavailable_icon.opacity = 1;
+ }
+ }
+
public void set_input_state(Plugins.InputFieldStatus.MessageType message_type) {
switch (message_type) {
case Plugins.InputFieldStatus.MessageType.NONE: