Improvement[Community] Improve methods in IMessageChatLoader (#25746)

- Add @staticmethod to static methods in `IMessageChatLoader`.
- Format args name.
This commit is contained in:
ZhangShenao 2024-08-27 02:20:22 +08:00 committed by GitHub
parent 815f59dba5
commit 44e3e2391c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -68,7 +68,8 @@ class IMessageChatLoader(BaseChatLoader):
"Please install it with `pip install pysqlite3`"
) from e
def _parse_attributedBody(self, attributedBody: bytes) -> str:
@staticmethod
def _parse_attributed_body(attributed_body: bytes) -> str:
"""
Parse the attributedBody field of the message table
for the text content of the message.
@ -88,17 +89,18 @@ class IMessageChatLoader(BaseChatLoader):
that byte.
Args:
attributedBody (bytes): attributedBody field of the message table.
attributed_body (bytes): attributedBody field of the message table.
Return:
str: Text content of the message.
"""
content = attributedBody.split(b"NSString")[1][5:]
content = attributed_body.split(b"NSString")[1][5:]
length, start = content[0], 1
if content[0] == 129:
length, start = int.from_bytes(content[1:3], "little"), 3
return content[start : start + length].decode("utf-8", errors="ignore")
def _get_session_query(self, use_chat_handle_table: bool) -> str:
@staticmethod
def _get_session_query(use_chat_handle_table: bool) -> str:
# Messages sent pre OSX 12 require a join through the chat_handle_join table
# However, the table doesn't exist if database created with OSX 12 or above.
@ -151,7 +153,7 @@ class IMessageChatLoader(BaseChatLoader):
if text:
content = text
elif attributedBody:
content = self._parse_attributedBody(attributedBody)
content = self._parse_attributed_body(attributedBody)
else: # Skip messages with no content
continue