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


Commits:
71b882ee by lovetox at 2022-01-01T23:22:44+01:00
Storage: Add type annotations

- - - - -
2fcbee61 by lovetox at 2022-01-01T23:23:03+01:00
Archive: Remove unused methods

- - - - -


4 changed files:

- gajim/common/helpers.py
- gajim/common/storage/archive.py
- gajim/common/storage/base.py
- pyrightconfig.json


Changes:

=====================================
gajim/common/helpers.py
=====================================
@@ -836,7 +836,7 @@ def _get_path_childs(full_path: str) -> list[str]:
             path_childs = full_path.split(':')
         return path_childs
 
-    def set_value(self, full_path: str, key: str, value: str) -> None:
+    def set_value(self, full_path: str, key: str, value: Optional[str]) -> 
None:
         path_childs = self._get_path_childs(full_path)
         _dict = self.data
         for path in path_childs:


=====================================
gajim/common/storage/archive.py
=====================================
@@ -92,7 +92,7 @@
 class JidsTableRow(NamedTuple):
     jid_id: int
     jid: JID
-    type: str
+    type: JIDConstant
 
 
 class ConversationRow(NamedTuple):
@@ -269,30 +269,6 @@ def get_jid_from_id(self, jid_id: int) -> JidsTableRow:
     def get_jids_in_db(self) -> KeysView[JID]:
         return self._jid_ids.keys()
 
-    def jid_is_from_pm(self, jid: str) -> bool:
-        """
-        If jid is gajim@conf/nkour it's likely a pm one, how we know gajim@conf
-        is not a normal guy and nkour is not his resource?  we ask if 
gajim@conf
-        is already in jids (with type room jid) this fails if user disables
-        logging for room and only enables for pm (so highly unlikely) and if we
-        fail we do not go chaos (user will see the first pm as if it was 
message
-        in room's public chat) and after that all okay
-        """
-        if jid.find('/') > -1:
-            possible_room_jid = jid.split('/', 1)[0]
-            return self.jid_is_room_jid(possible_room_jid)
-        # it's not a full jid, so it's not a pm one
-        return False
-
-    def jid_is_room_jid(self, jid: str) -> Optional[bool]:
-        """
-        Return True if it's a room jid, False if it's not, None if we don't 
know
-        """
-        jid_ = self._jid_ids.get(jid)
-        if jid_ is None:
-            return None
-        return jid_.type == JIDConstant.ROOM_TYPE
-
     def get_account_id(self,
                        account: str,
                        type_: JIDConstant = JIDConstant.NORMAL_TYPE
@@ -346,8 +322,9 @@ def get_jid_id(self,
 
         sql = 'INSERT INTO jids (jid, type) VALUES (?, ?)'
         lastrowid = self._con.execute(sql, (jid, type_)).lastrowid
-        Row = namedtuple('Row', 'jid_id jid type')
-        self._jid_ids[jid] = Row(lastrowid, jid, type_)
+        self._jid_ids[jid] = JidsTableRow(jid_id=lastrowid,
+                                          jid=jid,
+                                          type=type_)
         self._delayed_commit()
         return lastrowid
 
@@ -1091,7 +1068,8 @@ def update_additional_data(self,
         if is_groupchat:
             type_ = JIDConstant.ROOM_TYPE
 
-        archive_id = self.get_jid_id(str(properties.jid.bare), type_=type_)
+        assert properties.jid is not None
+        archive_id = self.get_jid_id(properties.jid.bare, type_=type_)
         account_id = self.get_account_id(account)
 
         if is_groupchat:
@@ -1131,6 +1109,7 @@ def update_additional_data(self,
             additional_data = result.additional_data
 
         if properties.is_moderation:
+            assert properties.moderation is not None
             additional_data.set_value(
                 'retracted', 'by', properties.moderation.moderator_jid)
             additional_data.set_value(


=====================================
gajim/common/storage/base.py
=====================================
@@ -78,7 +78,7 @@ def _jid_converter(jid: bytes) -> JID:
 sqlite3.register_adapter(JID, _jid_adapter)
 
 def _convert_disco_info(disco_info: bytes) -> DiscoInfo:
-    return parse_disco_info(Iq(node=disco_info))
+    return parse_disco_info(Iq(node=disco_info))  # type: ignore
 
 def _adapt_disco_info(disco_info: DiscoInfo) -> str:
     return str(disco_info.stanza)


=====================================
pyrightconfig.json
=====================================
@@ -16,7 +16,7 @@
         "gajim/common/passwords.py",
         "gajim/common/regex.py",
         "gajim/common/sound.py",
-        "gajim/common/storage/cache.py",
+        "gajim/common/storage/",
         "gajim/gtk/app_side_bar.py",
         "gajim/gtk/chat_filter.py",
         "gajim/gtk/chat_page.py",



View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/932b79c70dc0bb5c82a8f0d67ef74808520c2cf4...2fcbee61731b53b61324b65819e7792df4c39b85

-- 
View it on GitLab: 
https://dev.gajim.org/gajim/gajim/-/compare/932b79c70dc0bb5c82a8f0d67ef74808520c2cf4...2fcbee61731b53b61324b65819e7792df4c39b85
You're receiving this email because of your account on dev.gajim.org.


_______________________________________________
Commits mailing list
[email protected]
https://lists.gajim.org/cgi-bin/listinfo/commits

Reply via email to