diff sat/plugins/plugin_xep_0184.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 31628770a15a
children
line wrap: on
line diff
--- a/sat/plugins/plugin_xep_0184.py	Fri Apr 07 15:18:39 2023 +0200
+++ b/sat/plugins/plugin_xep_0184.py	Sat Apr 08 13:54:42 2023 +0200
@@ -102,17 +102,17 @@
         self._dictRequest = dict()
 
         # parameter value is retrieved before each use
-        host.memory.updateParams(self.params)
+        host.memory.update_params(self.params)
 
-        host.trigger.add("sendMessage", self.sendMessageTrigger)
-        host.bridge.addSignal(
-            "messageState", ".plugin", signature="sss"
+        host.trigger.add("sendMessage", self.send_message_trigger)
+        host.bridge.add_signal(
+            "message_state", ".plugin", signature="sss"
         )  # message_uid, status, profile
 
-    def getHandler(self, client):
+    def get_handler(self, client):
         return XEP_0184_handler(self, client.profile)
 
-    def sendMessageTrigger(
+    def send_message_trigger(
         self, client, mess_data, pre_xml_treatments, post_xml_treatments
     ):
         """Install SendMessage command hook """
@@ -121,7 +121,7 @@
             message = mess_data["xml"]
             message_type = message.getAttribute("type")
 
-            if self._isActif(client.profile) and (
+            if self._is_actif(client.profile) and (
                 message_type == "chat" or message_type == "normal"
             ):
                 message.addElement("request", NS_MESSAGE_DELIVERY_RECEIPTS)
@@ -129,7 +129,7 @@
                 msg_id = message.getAttribute("id")
                 self._dictRequest[msg_id] = uid
                 reactor.callLater(
-                    TEMPO_DELETE_WAITING_ACK_S, self._clearDictRequest, msg_id
+                    TEMPO_DELETE_WAITING_ACK_S, self._clear_dict_request, msg_id
                 )
                 log.debug(
                     _(
@@ -144,13 +144,13 @@
         post_xml_treatments.addCallback(treatment)
         return True
 
-    def onMessageDeliveryReceiptsRequest(self, msg_elt, client):
+    def on_message_delivery_receipts_request(self, msg_elt, client):
         """This method is called on message delivery receipts **request** (XEP-0184 #7)
         @param msg_elt: message element
         @param client: %(doc_client)s"""
         from_jid = jid.JID(msg_elt["from"])
 
-        if self._isActif(client.profile) and client.roster.isSubscribedFrom(from_jid):
+        if self._is_actif(client.profile) and client.roster.is_subscribed_from(from_jid):
             received_elt_ret = domish.Element((NS_MESSAGE_DELIVERY_RECEIPTS, "received"))
             try:
                 received_elt_ret["id"] = msg_elt["id"]
@@ -162,7 +162,7 @@
             msg_result_elt.addChild(received_elt_ret)
             client.send(msg_result_elt)
 
-    def onMessageDeliveryReceiptsReceived(self, msg_elt, client):
+    def on_message_delivery_receipts_received(self, msg_elt, client):
         """This method is called on message delivery receipts **received** (XEP-0184 #7)
         @param msg_elt: message element
         @param client: %(doc_client)s"""
@@ -173,7 +173,7 @@
         try:
             uid = self._dictRequest[msg_id]
             del self._dictRequest[msg_id]
-            self.host.bridge.messageState(
+            self.host.bridge.message_state(
                 uid, STATUS_MESSAGE_DELIVERY_RECEIVED, client.profile
             )
             log.debug(
@@ -182,7 +182,7 @@
         except KeyError:
             pass
 
-    def _clearDictRequest(self, msg_id):
+    def _clear_dict_request(self, msg_id):
         try:
             del self._dictRequest[msg_id]
             log.debug(
@@ -195,8 +195,8 @@
         except KeyError:
             pass
 
-    def _isActif(self, profile):
-        return self.host.memory.getParamA(PARAM_NAME, PARAM_KEY, profile_key=profile)
+    def _is_actif(self, profile):
+        return self.host.memory.param_get_a(PARAM_NAME, PARAM_KEY, profile_key=profile)
 
 
 @implementer(iwokkel.IDisco)
@@ -210,23 +210,23 @@
     def connectionInitialized(self):
         self.xmlstream.addObserver(
             MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_REQUEST,
-            self.plugin_parent.onMessageDeliveryReceiptsRequest,
+            self.plugin_parent.on_message_delivery_receipts_request,
             client=self.parent,
         )
         self.xmlstream.addObserver(
             MSG_CHAT_MESSAGE_DELIVERY_RECEIPTS_RECEIVED,
-            self.plugin_parent.onMessageDeliveryReceiptsReceived,
+            self.plugin_parent.on_message_delivery_receipts_received,
             client=self.parent,
         )
 
         self.xmlstream.addObserver(
             MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_REQUEST,
-            self.plugin_parent.onMessageDeliveryReceiptsRequest,
+            self.plugin_parent.on_message_delivery_receipts_request,
             client=self.parent,
         )
         self.xmlstream.addObserver(
             MSG_NORMAL_MESSAGE_DELIVERY_RECEIPTS_RECEIVED,
-            self.plugin_parent.onMessageDeliveryReceiptsReceived,
+            self.plugin_parent.on_message_delivery_receipts_received,
             client=self.parent,
         )