diff sat/plugins/plugin_xep_0424.py @ 4037:524856bd7b19

massive refactoring to switch from camelCase to snake_case: historically, Libervia (SàT before) was using camelCase as allowed by PEP8 when using a pre-PEP8 code, to use the same coding style as in Twisted. However, snake_case is more readable and it's better to follow PEP8 best practices, so it has been decided to move on full snake_case. Because Libervia has a huge codebase, this ended with a ugly mix of camelCase and snake_case. To fix that, this patch does a big refactoring by renaming every function and method (including bridge) that are not coming from Twisted or Wokkel, to use fully snake_case. This is a massive change, and may result in some bugs.
author Goffi <goffi@goffi.org>
date Sat, 08 Apr 2023 13:54:42 +0200
parents 6090141b1b70
children c23cad65ae99
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0424.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0424.py	Sat Apr 08 13:54:42 2023 +0200
@@ -70,13 +70,13 @@
     def __init__(self, host):
         log.info(_("XEP-0424 (Message Retraction) plugin initialization"))
         self.host = host
-        host.memory.updateParams(PARAMS)
+        host.memory.update_params(PARAMS)
         self._h = host.plugins["XEP-0334"]
         self._f = host.plugins["XEP-0422"]
-        host.registerNamespace("message-retract", NS_MESSAGE_RETRACT)
-        host.trigger.add("messageReceived", self._messageReceivedTrigger, 100)
-        host.bridge.addMethod(
-            "messageRetract",
+        host.register_namespace("message-retract", NS_MESSAGE_RETRACT)
+        host.trigger.add("messageReceived", self._message_received_trigger, 100)
+        host.bridge.add_method(
+            "message_retract",
             ".plugin",
             in_sign="ss",
             out_sign="",
@@ -84,16 +84,16 @@
             async_=True,
         )
 
-    def getHandler(self, __):
+    def get_handler(self, __):
         return XEP_0424_handler()
 
     def _retract(self, message_id: str, profile: str) -> None:
-        client = self.host.getClient(profile)
+        client = self.host.get_client(profile)
         return defer.ensureDeferred(
             self.retract(client, message_id)
         )
 
-    def retractByOriginId(
+    def retract_by_origin_id(
         self,
         client: SatXMPPEntity,
         dest_jid: jid.JID,
@@ -109,17 +109,17 @@
         message_elt = domish.Element((None, "message"))
         message_elt["from"] = client.jid.full()
         message_elt["to"] = dest_jid.full()
-        apply_to_elt = self._f.applyToElt(message_elt, origin_id)
+        apply_to_elt = self._f.apply_to_elt(message_elt, origin_id)
         apply_to_elt.addElement((NS_MESSAGE_RETRACT, "retract"))
-        self.host.plugins["XEP-0428"].addFallbackElt(
+        self.host.plugins["XEP-0428"].add_fallback_elt(
             message_elt,
             "[A message retraction has been requested, but your client doesn't support "
             "it]"
         )
-        self._h.addHintElements(message_elt, [self._h.HINT_STORE])
+        self._h.add_hint_elements(message_elt, [self._h.HINT_STORE])
         client.send(message_elt)
 
-    async def retractByHistory(
+    async def retract_by_history(
         self,
         client: SatXMPPEntity,
         history: History
@@ -138,8 +138,8 @@
                 "client is probably not supporting message retraction."
             )
         else:
-            self.retractByOriginId(client, history.dest_jid, origin_id)
-            await self.retractDBHistory(client, history)
+            self.retract_by_origin_id(client, history.dest_jid, origin_id)
+            await self.retract_db_history(client, history)
 
     async def retract(
         self,
@@ -163,9 +163,9 @@
             raise exceptions.NotFound(
                 f"message to retract not found in database ({message_id})"
             )
-        await self.retractByHistory(client, history)
+        await self.retract_by_history(client, history)
 
-    async def retractDBHistory(self, client, history: History) -> None:
+    async def retract_db_history(self, client, history: History) -> None:
         """Mark an history instance in database as retracted
 
         @param history: history instance
@@ -176,7 +176,7 @@
         # we assign a new object to be sure to trigger an update
         history.extra = deepcopy(history.extra) if history.extra else {}
         history.extra["retracted"] = True
-        keep_history = self.host.memory.getParamA(
+        keep_history = self.host.memory.param_get_a(
             NAME, CATEGORY, profile_key=client.profile
         )
         old_version: Dict[str, Any] = {
@@ -194,13 +194,13 @@
             session_add=[history]
         )
 
-    async def _messageReceivedTrigger(
+    async def _message_received_trigger(
         self,
         client: SatXMPPEntity,
         message_elt: domish.Element,
         post_treat: defer.Deferred
     ) -> bool:
-        fastened_elts = await self._f.getFastenedElts(client, message_elt)
+        fastened_elts = await self._f.get_fastened_elts(client, message_elt)
         if fastened_elts is None:
             return True
         for elt in fastened_elts.elements:
@@ -218,7 +218,7 @@
                 break
         else:
             return True
-        if not await self.host.trigger.asyncPoint(
+        if not await self.host.trigger.async_point(
             "XEP-0424_retractReceived", client, message_elt, elt, fastened_elts
         ):
             return False
@@ -230,7 +230,7 @@
             )
             return False
         log.info(f"[{client.profile}] retracting message {fastened_elts.id!r}")
-        await self.retractDBHistory(client, fastened_elts.history)
+        await self.retract_db_history(client, fastened_elts.history)
         # TODO: send bridge signal
 
         return False