mirror of
https://github.com/paul-nameless/tg
synced 2025-02-16 10:38:23 +00:00
Black formatting update
This commit is contained in:
parent
bc330c9a14
commit
e819a90cb9
4 changed files with 38 additions and 13 deletions
5
.github/workflows/main.yml
vendored
5
.github/workflows/main.yml
vendored
|
@ -30,10 +30,11 @@ jobs:
|
|||
with:
|
||||
python-version: ${{ matrix.python-version }}
|
||||
|
||||
- name: Install dependencies
|
||||
- name: Install black
|
||||
run: |
|
||||
pip install black==19.10b0
|
||||
- name: Lint with flake8
|
||||
|
||||
- name: Check formatting with black
|
||||
run: |
|
||||
black --check .
|
||||
|
||||
|
|
|
@ -140,7 +140,8 @@ class Controller:
|
|||
# using lock here, because refresh_chats is used from another
|
||||
# thread by tdlib python wrapper
|
||||
self.view.draw_chats(
|
||||
self.model.current_chat, self.model.get_chats(limit=self.view.chats.h)
|
||||
self.model.current_chat,
|
||||
self.model.get_chats(limit=self.view.chats.h),
|
||||
)
|
||||
self.refresh_msgs()
|
||||
self.view.draw_status()
|
||||
|
|
|
@ -99,15 +99,21 @@ class ChatModel:
|
|||
if offset + limit < len(self.chats):
|
||||
# return data from cache
|
||||
return sorted(
|
||||
self.chats, key=lambda it: it["last_message"]["date"], reverse=True
|
||||
self.chats,
|
||||
key=lambda it: it["last_message"]["date"],
|
||||
reverse=True,
|
||||
)[offset:limit]
|
||||
|
||||
previous_chats_num = len(self.chat_ids)
|
||||
|
||||
self.fetch_chat_ids(offset=len(self.chats), limit=len(self.chats) + limit)
|
||||
self.fetch_chat_ids(
|
||||
offset=len(self.chats), limit=len(self.chats) + limit
|
||||
)
|
||||
if len(self.chat_ids) == previous_chats_num:
|
||||
return sorted(
|
||||
self.chats, key=lambda it: it["last_message"]["date"], reverse=True
|
||||
self.chats,
|
||||
key=lambda it: it["last_message"]["date"],
|
||||
reverse=True,
|
||||
)[offset:limit]
|
||||
|
||||
for chat_id in self.chat_ids:
|
||||
|
@ -120,7 +126,9 @@ class ChatModel:
|
|||
|
||||
def fetch_chat_ids(self, offset=0, limit=10):
|
||||
if len(self.chats):
|
||||
result = self.tg.get_chats(offset_chat_id=self.chats[-1]["id"], limit=limit)
|
||||
result = self.tg.get_chats(
|
||||
offset_chat_id=self.chats[-1]["id"], limit=limit
|
||||
)
|
||||
else:
|
||||
result = self.tg.get_chats(
|
||||
offset_order=2 ** 63 - 1, offset_chat_id=offset, limit=limit
|
||||
|
@ -200,7 +208,9 @@ class MsgModel:
|
|||
return False
|
||||
log.info(f"removing msg {msg_id=}")
|
||||
# FIXME: potential bottleneck, replace with constan time operation
|
||||
self.msgs[chat_id] = [m for m in self.msgs[chat_id] if m["id"] != msg_id]
|
||||
self.msgs[chat_id] = [
|
||||
m for m in self.msgs[chat_id] if m["id"] != msg_id
|
||||
]
|
||||
msg_set.remove(msg_id)
|
||||
return True
|
||||
|
||||
|
@ -219,7 +229,9 @@ class MsgModel:
|
|||
|
||||
def fetch_msgs(self, chat_id, offset=0, limit=10):
|
||||
if offset + limit < len(self.msgs[chat_id]):
|
||||
return sorted(self.msgs[chat_id], key=lambda d: d["id"])[::-1][offset:limit]
|
||||
return sorted(self.msgs[chat_id], key=lambda d: d["id"])[::-1][
|
||||
offset:limit
|
||||
]
|
||||
|
||||
if len(self.msgs[chat_id]):
|
||||
result = self.tg.get_chat_history(
|
||||
|
@ -237,7 +249,9 @@ class MsgModel:
|
|||
result.wait()
|
||||
self.add_messages(chat_id, result.update["messages"])
|
||||
|
||||
return sorted(self.msgs[chat_id], key=lambda d: d["id"])[::-1][offset:limit]
|
||||
return sorted(self.msgs[chat_id], key=lambda d: d["id"])[::-1][
|
||||
offset:limit
|
||||
]
|
||||
|
||||
def send_message(self, chat_id, text):
|
||||
log.info("Sending msg")
|
||||
|
@ -254,7 +268,9 @@ class MsgModel:
|
|||
return False
|
||||
selected_msg = self.current_msgs[chat_id]
|
||||
msg_item = self.msgs[chat_id].pop(selected_msg)
|
||||
self.current_msgs[chat_id] = min(selected_msg, len(self.msgs[chat_id]) - 1)
|
||||
self.current_msgs[chat_id] = min(
|
||||
selected_msg, len(self.msgs[chat_id]) - 1
|
||||
)
|
||||
log.info(f"Deleting msg from the chat {chat_id}: {msg_item}")
|
||||
message_ids = [msg_item["id"]]
|
||||
r = self.tg.delete_messages(chat_id, message_ids, revoke=True)
|
||||
|
|
|
@ -71,7 +71,10 @@ class View:
|
|||
continue
|
||||
keys += key
|
||||
# if match found or there are not any shortcut matches at all
|
||||
if all(p == keys or not p.startswith(keys) for p in MULTICHAR_KEYBINDINGS):
|
||||
if all(
|
||||
p == keys or not p.startswith(keys)
|
||||
for p in MULTICHAR_KEYBINDINGS
|
||||
):
|
||||
break
|
||||
|
||||
return num(repeat_factor, default=1), keys or "UNKNOWN"
|
||||
|
@ -300,7 +303,11 @@ class MsgView:
|
|||
if _type == "message":
|
||||
return dt, msg["sender_user_id"], parse_content(msg["content"])
|
||||
log.debug("Unknown message type: %s", msg)
|
||||
return dt, msg["sender_user_id"], "unknown msg type: " + str(msg["content"])
|
||||
return (
|
||||
dt,
|
||||
msg["sender_user_id"],
|
||||
"unknown msg type: " + str(msg["content"]),
|
||||
)
|
||||
|
||||
|
||||
def get_last_msg(chat):
|
||||
|
|
Loading…
Add table
Reference in a new issue