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


Commits:
8519cbcf by Philipp Hörist at 2024-03-15T21:19:44+01:00
fix: Delete groupchat reflection

- - - - -


2 changed files:

- gajim/common/modules/message.py
- gajim/common/storage/archive/storage.py


Changes:

=====================================
gajim/common/modules/message.py
=====================================
@@ -2,8 +2,6 @@
 #
 # SPDX-License-Identifier: GPL-3.0-only
 
-# Message handler
-
 from __future__ import annotations
 
 import datetime as dt
@@ -128,15 +126,14 @@ def _message_received(self,
         occupant = None
         if m_type == MessageType.GROUPCHAT:
             # Delete pending message when we receive the reflection
-            # TODO
-            # entitykey = app.storage.archive.delete_pending_message(
-            #     self._account, remote_jid, properties.id)
-
-            # if entitykey is not None:
-            #     app.ged.raise_event(MessageDeleted(account=self._account,
-            #                                        jid=remote_jid,
-            #                                        entitykey=entitykey))
-            # todo
+            entitykey = app.storage.archive.delete_pending_message(
+                self._account, remote_jid, properties.id)
+
+            if entitykey is not None:
+                app.ged.raise_event(MessageDeleted(account=self._account,
+                                                   jid=remote_jid,
+                                                   entitykey=entitykey))
+
             occupant = self._get_occupant_info(
                 remote_jid, timestamp, properties)
 


=====================================
gajim/common/storage/archive/storage.py
=====================================
@@ -29,6 +29,8 @@
 from gajim.common import configpaths
 from gajim.common.const import MAX_MESSAGE_CORRECTION_DELAY
 from gajim.common.storage.archive import migration
+from gajim.common.storage.archive.const import ChatDirection
+from gajim.common.storage.archive.const import MessageType
 from gajim.common.storage.archive.models import Account
 from gajim.common.storage.archive.models import Base
 from gajim.common.storage.archive.models import MAMArchiveState
@@ -708,36 +710,30 @@ def reset_mam_archive_state(self, session: Session, 
account: str, jid: JID) -> N
 
         session.execute(stmt)
 
-    # def delete_pending_message(
-    #     self,
-    #     account: str,
-    #     remote_jid: JID,
-    #     message_id: str
-    # ) -> int | None:
-
-    #     account_ek = self._get_account_ek(account)
-    #     jid_ek = self._get_jid_ek(remote_jid)
-
-    #     delete_stmt = '''
-    #         DELETE FROM message
-    #         WHERE
-    #             state = ? AND
-    #             message_id = ? AND
-    #             fk_jid_ek = ? AND
-    #             fk_account_ek = ?
-    #         RETURNING entitykey
-    #     '''
-
-    #     results = self._con.execute(delete_stmt, (
-    #         MessageState.PENDING,
-    #         message_id,
-    #         jid_ek,
-    #         account_ek)).fetchall()
-
-    #     if results:
-    #         assert len(results) == 1
-    #         self._delayed_commit()
-    #         return results[0].entitykey
+    @with_session
+    def delete_pending_message(
+        self, session: Session, account: str, jid: JID, message_id: str
+    ) -> int | None:
+        fk_account_pk = self._get_account_pk(session, account)
+        fk_remote_pk = self._get_jid_ek(session, jid)
+
+        stmt = select(Message).where(
+            Message.id == message_id,
+            Message.fk_remote_pk == fk_remote_pk,
+            Message.fk_account_pk == fk_account_pk,
+            Message.type == MessageType.GROUPCHAT,
+            Message.direction == ChatDirection.OUTGOING,
+        )
+
+        message = session.scalar(stmt)
+        if message is None:
+            self._log.warning(
+                'Unable to delete pending message with message id: %s', 
message_id
+            )
+            return
+
+        self._delete_message(session, message)
+        return message.pk
 
     @with_session
     def remove_history_for_jid(self, session: Session, account: str, jid: JID) 
-> None:



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

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/commit/8519cbcfec1d34cb1400b1f5dba53a4435c89b3d
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