diff sat/plugins/plugin_xep_0444.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 1f88ca90c3de
children c23cad65ae99
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0444.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0444.py	Sat Apr 08 13:54:42 2023 +0200
@@ -53,23 +53,23 @@
 
     def __init__(self, host):
         log.info(_("Message Reactions initialization"))
-        host.registerNamespace("reactions", NS_REACTIONS)
+        host.register_namespace("reactions", NS_REACTIONS)
         self.host = host
         self._h = host.plugins["XEP-0334"]
-        host.bridge.addMethod(
-            "messageReactionsSet",
+        host.bridge.add_method(
+            "message_reactions_set",
             ".plugin",
             in_sign="ssas",
             out_sign="",
-            method=self._reactionsSet,
+            method=self._reactions_set,
             async_=True,
         )
-        host.trigger.add("messageReceived", self._messageReceivedTrigger)
+        host.trigger.add("messageReceived", self._message_received_trigger)
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return XEP_0444_Handler()
 
-    async def _messageReceivedTrigger(
+    async def _message_received_trigger(
         self,
         client: SatXMPPEntity,
         message_elt: domish.Element,
@@ -77,13 +77,13 @@
     ) -> bool:
         return True
 
-    def _reactionsSet(self, message_id: str, profile: str, reactions: List[str]) -> None:
-        client = self.host.getClient(profile)
+    def _reactions_set(self, message_id: str, profile: str, reactions: List[str]) -> None:
+        client = self.host.get_client(profile)
         return defer.ensureDeferred(
-            self.setReactions(client, message_id)
+            self.set_reactions(client, message_id)
         )
 
-    def sendReactions(
+    def send_reactions(
         self,
         client: SatXMPPEntity,
         dest_jid: jid.JID,
@@ -103,10 +103,10 @@
         reactions_elt["id"] = message_id
         for r in set(reactions):
             reactions_elt.addElement("reaction", content=r)
-        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 addReactionsToHistory(
+    async def add_reactions_to_history(
         self,
         history: History,
         from_jid: jid.JID,
@@ -129,7 +129,7 @@
         h_reactions["summary"] = sorted(list(set().union(*by_jid.values())))
         await self.host.memory.storage.session_add(history)
 
-    async def setReactions(
+    async def set_reactions(
         self,
         client: SatXMPPEntity,
         message_id: str,
@@ -157,8 +157,8 @@
                 "target message has neither origin-id nor message-id, we can't send a "
                 "reaction"
             )
-        await self.addReactionsToHistory(history, client.jid, reactions)
-        self.sendReactions(client, history.dest_jid, mess_id, reactions)
+        await self.add_reactions_to_history(history, client.jid, reactions)
+        self.send_reactions(client, history.dest_jid, mess_id, reactions)
 
 
 @implementer(iwokkel.IDisco)