feat: add private daily summaries and history sync
This commit is contained in:
@ -232,10 +232,19 @@ class LarkClient:
|
||||
self._thread_chats[chat_id] = decoders.is_thread_chat(info)
|
||||
return self._thread_chats[chat_id]
|
||||
|
||||
def pull_history(self, chat_id: str, positions, save_storage=None):
|
||||
resp = self.api('messages.PullMessagesByPositionsRequest', {'chatId': str(chat_id), 'positions': [int(p) for p in positions]})
|
||||
def pull_history(self, chat_id: str, positions, save_storage=None, visible_only=False, thread_chat=None):
|
||||
request = {'chatId': str(chat_id), 'positions': [int(p) for p in positions]}
|
||||
if visible_only:
|
||||
request.update({
|
||||
'type': 'CHAT',
|
||||
'onlyVisibleMessages': True,
|
||||
'needNextPosition': True,
|
||||
'direction': 'UP',
|
||||
})
|
||||
resp = self.api('messages.PullMessagesByPositionsRequest', request)
|
||||
messages = (resp or {}).get('messages') or {}
|
||||
thread_chat = self.is_thread_chat(chat_id)
|
||||
if thread_chat is None:
|
||||
thread_chat = self.is_thread_chat(chat_id)
|
||||
out = []
|
||||
for pos_key, v in sorted(messages.items(), key=lambda kv: int(kv[0])):
|
||||
message_type = decoders.enum_to_int(v.get('type', 0))
|
||||
@ -247,7 +256,8 @@ class LarkClient:
|
||||
out.append(msg)
|
||||
if save_storage is not None:
|
||||
try:
|
||||
save_storage.save_message(msg)
|
||||
direction = 'out' if str(v.get('fromId') or '') == str(self.auth.user_id or '') else 'in'
|
||||
save_storage.save_message(msg, direction=direction)
|
||||
except Exception:
|
||||
pass
|
||||
return out
|
||||
|
||||
Reference in New Issue
Block a user