mirror of
https://github.com/paul-nameless/tg
synced 2024-11-25 21:30:22 +00:00
Add forward msg functionality and multiple msgs selection
This commit is contained in:
parent
3413d8fed8
commit
a215b0bc65
5 changed files with 80 additions and 0 deletions
|
@ -97,8 +97,49 @@ class Controller:
|
|||
"I": self.write_long_msg,
|
||||
"A": self.write_long_msg,
|
||||
"bp": self.breakpoint,
|
||||
|
||||
" ": self.select_msg,
|
||||
"^[": self.discard_selected_msgs, # esc
|
||||
"y": self.copy_msgs,
|
||||
"p": self.forward_msgs,
|
||||
}
|
||||
|
||||
def forward_msgs(self, _: int):
|
||||
chat_id = self.model.chats.id_by_index(self.model.current_chat)
|
||||
if not self.model.yanked_msgs:
|
||||
return
|
||||
from_chat_id, msg_ids = self.model.yanked_msgs
|
||||
self.tg.forward_msgs(chat_id, from_chat_id, msg_ids)
|
||||
self.present_info(f"Forwarded {len(msg_ids)} messages")
|
||||
|
||||
def copy_msgs(self, _: int):
|
||||
# can_be_forwarded
|
||||
chat_id = self.model.chats.id_by_index(self.model.current_chat)
|
||||
msg_ids = self.model.selected[chat_id]
|
||||
if not msg_ids:
|
||||
self.present_error("No msgs selected")
|
||||
return
|
||||
self.model.yanked_msgs = (chat_id, msg_ids)
|
||||
self.discard_selected_msgs(0)
|
||||
self.present_info(f"Copied {len(msg_ids)} messages")
|
||||
|
||||
def select_msg(self, _: int):
|
||||
chat_id = self.model.chats.id_by_index(self.model.current_chat)
|
||||
msg = MsgProxy(self.model.current_msg)
|
||||
|
||||
if msg.msg_id in self.model.selected[chat_id]:
|
||||
self.model.selected[chat_id].remove(msg.msg_id)
|
||||
else:
|
||||
self.model.selected[chat_id].append(msg.msg_id)
|
||||
self.model.next_msg(1)
|
||||
self.refresh_msgs()
|
||||
self.present_info("Removed selections")
|
||||
|
||||
def discard_selected_msgs(self, _: int):
|
||||
chat_id = self.model.chats.id_by_index(self.model.current_chat)
|
||||
self.model.selected[chat_id] = []
|
||||
self.refresh_msgs()
|
||||
|
||||
def jump_bottom(self, _: int):
|
||||
log.info("jump_bottom:")
|
||||
if self.model.jump_bottom():
|
||||
|
|
|
@ -16,6 +16,8 @@ class Model:
|
|||
self.users = UserModel(tg)
|
||||
self.current_chat = 0
|
||||
self.downloads: Dict[int, Tuple[int, int]] = {}
|
||||
self.selected: Dict[int, List[int]] = defaultdict(list)
|
||||
self.yanked_msgs: Tuple[int, List[int]] = None
|
||||
|
||||
def get_me(self):
|
||||
return self.users.get_me()
|
||||
|
|
|
@ -187,3 +187,9 @@ class MsgProxy:
|
|||
@property
|
||||
def sender_id(self) -> int:
|
||||
return self.msg["sender_user_id"]
|
||||
|
||||
@property
|
||||
def forward(self) -> Optional[Dict[str, Any]]:
|
||||
if "forward_info" not in self.msg:
|
||||
return None
|
||||
return self.msg["forward_info"]
|
||||
|
|
24
tg/tdlib.py
24
tg/tdlib.py
|
@ -1,3 +1,5 @@
|
|||
from typing import Any, Dict, List
|
||||
|
||||
from telegram.client import AsyncResult, Telegram
|
||||
|
||||
|
||||
|
@ -149,3 +151,25 @@ class Tdlib(Telegram):
|
|||
"message_id": message_id,
|
||||
}
|
||||
return self._send_data(data)
|
||||
|
||||
def forward_msgs(
|
||||
self,
|
||||
chat_id: int,
|
||||
from_chat_id: int,
|
||||
message_ids: List[int],
|
||||
as_album: bool = False,
|
||||
send_copy: bool = False,
|
||||
remove_caption: bool = False,
|
||||
options: Dict[str, Any] = {},
|
||||
) -> AsyncResult:
|
||||
data = {
|
||||
"@type": "forwardMessages",
|
||||
"chat_id": chat_id,
|
||||
"from_chat_id": from_chat_id,
|
||||
"message_ids": message_ids,
|
||||
"as_album": as_album,
|
||||
"send_copy": send_copy,
|
||||
"remove_caption": remove_caption,
|
||||
"options": options,
|
||||
}
|
||||
return self._send_data(data)
|
||||
|
|
|
@ -259,6 +259,12 @@ class MsgView:
|
|||
flags = []
|
||||
chat = self.model.chats.chats[self.model.current_chat]
|
||||
|
||||
if msg_proxy.msg_id in self.model.selected[chat["id"]]:
|
||||
flags.append("selected")
|
||||
|
||||
if msg_proxy.forward is not None:
|
||||
flags.append("forwarded")
|
||||
|
||||
if (
|
||||
not self.model.is_me(msg_proxy.sender_id)
|
||||
and msg_proxy.msg_id > chat["last_read_inbox_message_id"]
|
||||
|
@ -276,6 +282,7 @@ class MsgView:
|
|||
flags.append(self.states.get(state_type, state_type))
|
||||
if msg_proxy.msg["edit_date"]:
|
||||
flags.append("edited")
|
||||
|
||||
if not flags:
|
||||
return ""
|
||||
return ",".join(flags)
|
||||
|
|
Loading…
Reference in a new issue