Welcome to mirror list, hosted at ThFree Co, Russian Federation.

dev.gajim.org/gajim/gajim.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornicoco <nicoco@nicoco.fr>2023-10-20 00:17:57 +0300
committerPhilipp Hörist <philipp@hoerist.com>2023-11-28 23:17:52 +0300
commit1a3af4ac6398f3461d9a4f7acf3c4c09d00ad353 (patch)
tree28ad2b2c28cb0977365b75a844fd3f1cda89c884
parenta2d9eabca7e29c88836f631c9ae8d0830800eea3 (diff)
feat: StartChat: Show last seen
-rw-r--r--gajim/common/helpers.py18
-rw-r--r--gajim/data/style/gajim.css5
-rw-r--r--gajim/gtk/start_chat.py7
-rw-r--r--gajim/gtk/util.py25
4 files changed, 55 insertions, 0 deletions
diff --git a/gajim/common/helpers.py b/gajim/common/helpers.py
index bd5bb9056..7b4ceea34 100644
--- a/gajim/common/helpers.py
+++ b/gajim/common/helpers.py
@@ -52,6 +52,7 @@ from collections import defaultdict
from collections.abc import Callable
from datetime import datetime
from datetime import timedelta
+from datetime import timezone
from functools import wraps
from pathlib import Path
from string import Template
@@ -1589,3 +1590,20 @@ def make_path_from_jid(base_path: Path, jid: JID) -> Path:
if jid.resource is not None:
return path / jid.resource[:30]
return path
+
+
+def format_idle_time(idle_time: datetime) -> str:
+ now = datetime.now(timezone.utc)
+
+ now_date = now.date()
+ idle_date = idle_time.date()
+
+ if idle_date == now_date:
+ return idle_time.strftime(app.settings.get('time_format'))
+ if idle_date == now_date - timedelta(days=1):
+ return _('yesterday ') + idle_time.strftime(
+ app.settings.get('time_format'))
+ if idle_date >= now_date - timedelta(days=6):
+ return idle_time.strftime(f'%a {app.settings.get("time_format")}')
+
+ return idle_date.strftime(app.settings.get('date_format'))
diff --git a/gajim/data/style/gajim.css b/gajim/data/style/gajim.css
index ad50008c5..7a7cd7705 100644
--- a/gajim/data/style/gajim.css
+++ b/gajim/data/style/gajim.css
@@ -219,6 +219,11 @@ infobar.error > revealer > box {
font-weight: bold;
}
+.idle-time {
+ font-size: 80%;
+ font-weight: lighter;
+}
+
.link-button { min-height: 0px; }
.floating-overlay-box {
diff --git a/gajim/gtk/start_chat.py b/gajim/gtk/start_chat.py
index 42c7d1732..37dc8e4db 100644
--- a/gajim/gtk/start_chat.py
+++ b/gajim/gtk/start_chat.py
@@ -59,6 +59,7 @@ from gajim.gtk.tooltips import ContactTooltip
from gajim.gtk.util import AccountBadge
from gajim.gtk.util import GajimPopover
from gajim.gtk.util import get_icon_name
+from gajim.gtk.util import IdleBadge
ContactT = BareContact | GroupchatContact
@@ -812,6 +813,12 @@ class ContactRow(Gtk.ListBoxRow):
account_badge.set_valign(Gtk.Align.START)
account_badge.set_hexpand(True)
name_box.add(account_badge)
+
+ if contact and not contact.is_groupchat:
+ if idle := contact.idle_datetime:
+ idle_badge = IdleBadge(idle)
+ name_box.add(idle_badge)
+
box.add(name_box)
if contact and not contact.is_groupchat and (status := contact.status):
diff --git a/gajim/gtk/util.py b/gajim/gtk/util.py
index 90bdd53a6..5ce5c1d2f 100644
--- a/gajim/gtk/util.py
+++ b/gajim/gtk/util.py
@@ -23,6 +23,7 @@ import logging
import math
import sys
import textwrap
+from datetime import datetime
from functools import lru_cache
from functools import wraps
from importlib import import_module
@@ -52,6 +53,7 @@ from gajim.common.const import Display
from gajim.common.const import LOCATION_DATA
from gajim.common.const import StyleAttr
from gajim.common.ged import EventHelper as CommonEventHelper
+from gajim.common.helpers import format_idle_time
from gajim.common.helpers import URL_REGEX
from gajim.common.i18n import _
from gajim.common.modules.contacts import GroupchatParticipant
@@ -794,6 +796,29 @@ def wrap_with_event_box(klass: Any) -> Any:
return klass_wrapper
+class IdleBadge(Gtk.Label):
+ def __init__(self, idle: datetime | None = None) -> None:
+ Gtk.Label.__init__(
+ self,
+ valign=Gtk.Align.START,
+ halign=Gtk.Align.END,
+ hexpand=True,
+ ellipsize=Pango.EllipsizeMode.NONE,
+ no_show_all=True,
+ )
+ self.set_size_request(50, -1)
+ self.get_style_context().add_class('idle-time')
+ if idle is not None:
+ self.set_idle(idle)
+
+ self.show()
+
+ def set_idle(self, idle: datetime) -> None:
+ self.set_text(_('Last seen %s') % format_idle_time(idle))
+ format_string = app.settings.get('date_time_format')
+ self.set_tooltip_text(idle.strftime(format_string))
+
+
class AccountBadge(Gtk.Label):
def __init__(self, account: str | None = None) -> None:
Gtk.Label.__init__(self)