Philipp Hörist pushed to branch master at gajim / gajim
Commits:
bec58992 by Philipp Hörist at 2022-10-09T13:20:05+02:00
refactor: Remove usage of get_number_of_accounts()
- - - - -
23d5b164 by Philipp Hörist at 2022-10-09T13:20:05+02:00
refactor: MAM: Use only timezone aware datetime objects
- - - - -
4 changed files:
- gajim/common/app.py
- gajim/common/modules/mam.py
- gajim/gtk/account_side_bar.py
- gajim/gtk/chat_banner.py
Changes:
=====================================
gajim/common/app.py
=====================================
@@ -341,13 +341,6 @@ def get_jid_without_resource(jid: str) -> str:
return jid.split('/')[0]
-def get_number_of_accounts() -> int:
- '''
- Return the number of ALL accounts
- '''
- return len(connections.keys())
-
-
def get_number_of_connected_accounts(
accounts_list: Optional[list[str]] = None) -> int:
'''
=====================================
gajim/common/modules/mam.py
=====================================
@@ -22,6 +22,7 @@
import time
from datetime import datetime
from datetime import timedelta
+from datetime import timezone
import nbxmpp
from nbxmpp.errors import StanzaError
@@ -356,7 +357,7 @@ def _get_query_params(self) -> tuple[Optional[ſtr],
Optional[datetime]]:
else:
# First Start, we request the last week
- start_date = datetime.utcnow() - timedelta(days=7)
+ start_date = datetime.now(timezone.utc) - timedelta(days=7)
self._log.info('Request archive: %s, after date %s',
own_jid, start_date)
return mam_id, start_date
@@ -365,13 +366,15 @@ def _get_muc_query_params(self,
jid: JID,
threshold: SyncThreshold
) -> tuple[Optional[str], Optional[datetime]]:
+
archive = app.storage.archive.get_archive_infos(jid)
mam_id = None
start_date = None
+ now = datetime.now(timezone.utc)
if archive is None or archive.last_mam_id is None:
# First join
- start_date = datetime.utcnow() - timedelta(days=1)
+ start_date = now - timedelta(days=1)
self._log.info('Request archive: %s, after date %s',
jid, start_date)
@@ -390,10 +393,10 @@ def _get_muc_query_params(self,
self._log.info('No last muc timestamp found: %s', jid)
last_timestamp = 0
- last = datetime.utcfromtimestamp(float(last_timestamp))
- if datetime.utcnow() - last > timedelta(days=threshold):
+ last = datetime.fromtimestamp(float(last_timestamp), timezone.utc)
+ if now - last > timedelta(days=threshold):
# To much time has elapsed since last join, apply threshold
- start_date = datetime.utcnow() - timedelta(days=threshold)
+ start_date = now - timedelta(days=threshold)
self._log.info('Too much time elapsed since last join, '
'request archive: %s, after date %s, '
'threshold: %s', jid, start_date, threshold)
=====================================
gajim/gtk/account_side_bar.py
=====================================
@@ -136,7 +136,7 @@ def set_unread_count(self, count: int) -> None:
self._unread_label.set_visible(bool(count))
def _update_account_color_visibility(self, *args: Any) -> None:
- visible = app.get_number_of_accounts() > 1
+ visible = len(app.settings.get_active_accounts()) > 1
self._account_color_bar.set_visible(visible)
=====================================
gajim/gtk/chat_banner.py
=====================================
@@ -314,7 +314,7 @@ def _update_account_badge(self) -> None:
self._account_badge.set_visible(False)
return
- visible = app.get_number_of_accounts() > 1
+ visible = len(app.settings.get_active_accounts()) > 1
if visible:
self._account_badge.set_account(self._contact.account)
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/61fec3e4037536c42fa3e83e4ad19f3ae1432ec2...23d5b1641077c07fdae35dbc6cdbc176e9278075
--
View it on GitLab:
https://dev.gajim.org/gajim/gajim/-/compare/61fec3e4037536c42fa3e83e4ad19f3ae1432ec2...23d5b1641077c07fdae35dbc6cdbc176e9278075
You're receiving this email because of your account on dev.gajim.org.
_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits