Philipp Hörist pushed to branch storage at gajim / gajim


Commits:
cc508cbd by Philipp Hörist at 2024-04-10T22:12:24+02:00
imprv: Reformat

- - - - -


2 changed files:

- gajim/common/storage/archive/models.py
- gajim/common/storage/archive/storage.py


Changes:

=====================================
gajim/common/storage/archive/models.py
=====================================
@@ -666,7 +666,10 @@ class Message(MappedAsDataclass, Base, UtilMixin, 
kw_only=True):
             sa.text('timestamp ASC'),
         ),
         Index(
-            'idx_message_id', 'id', 'fk_remote_pk', 'fk_account_pk',
+            'idx_message_id',
+            'id',
+            'fk_remote_pk',
+            'fk_account_pk',
         ),
     )
 


=====================================
gajim/common/storage/archive/storage.py
=====================================
@@ -5,6 +5,7 @@
 from __future__ import annotations
 
 from typing import Any
+from typing import Literal
 
 import calendar
 import datetime as dt
@@ -621,6 +622,7 @@ def get_days_containing_messages(
                 Message.fk_remote_pk == fk_remote_pk,
                 Message.fk_account_pk == fk_account_pk,
                 Message.timestamp.between(start, end),
+                Message.correction_id.is_(None),
             )
         )
 
@@ -628,21 +630,21 @@ def get_days_containing_messages(
         return session.scalars(stmt).all()
 
     def _get_message_ts(
-        self, session: Session, account: str, jid: JID, direction: int
+        self,
+        session: Session,
+        account: str,
+        jid: JID,
+        direction: Literal['first', 'last'],
     ) -> datetime | None:
-
         fk_account_pk = self._get_account_pk(session, account)
         fk_remote_pk = self._get_jid_pk(session, jid)
 
-        stmt = (
-            select(Message.timestamp)
-            .where(
-                Message.fk_remote_pk == fk_remote_pk,
-                Message.fk_account_pk == fk_account_pk,
-                Message.correction_id.is_(None),
-            )
+        stmt = select(Message.timestamp).where(
+            Message.fk_remote_pk == fk_remote_pk,
+            Message.fk_account_pk == fk_account_pk,
+            Message.correction_id.is_(None),
         )
-        if direction == 1:
+        if direction == 'first':
             stmt = stmt.order_by(sa.desc(Message.timestamp), 
sa.desc(Message.pk))
         else:
             stmt = stmt.order_by(Message.timestamp, Message.pk)
@@ -660,7 +662,7 @@ def get_last_message_ts(
         '''
         Get the timestamp of the last message we received for the jid
         '''
-        return self._get_message_ts(session, account, jid, direction=1)
+        return self._get_message_ts(session, account, jid, direction='first')
 
     @with_session
     @timeit
@@ -670,7 +672,7 @@ def get_first_message_ts(
         '''
         Get the timestamp of the first message we received for the jid
         '''
-        return self._get_message_ts(session, account, jid, direction=2)
+        return self._get_message_ts(session, account, jid, direction='last')
 
     @with_session
     @timeit



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/cc508cbd1f2eb856d8488c54244a8c2fd292c096

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/cc508cbd1f2eb856d8488c54244a8c2fd292c096
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list -- [email protected]
To unsubscribe send an email to [email protected]

Reply via email to