mirror of
https://github.com/paul-nameless/tg
synced 2024-11-22 03:43:19 +00:00
Show unseen flag in chat pane
This commit is contained in:
parent
4c449da54a
commit
801df444f1
4 changed files with 23 additions and 17 deletions
|
@ -125,7 +125,10 @@ CHAT_FLAGS = {
|
|||
"online": "●",
|
||||
"pinned": "P",
|
||||
"muted": "M",
|
||||
# chat is marked as unread
|
||||
"unread": "U",
|
||||
# last msg haven't been seen by recipient
|
||||
"unseen": "✓",
|
||||
}
|
||||
MSG_FLAGS = {
|
||||
"selected": "*",
|
||||
|
|
|
@ -25,8 +25,8 @@ def run(tg: Tdlib, stdscr: window) -> None:
|
|||
|
||||
model = Model(tg)
|
||||
status_view = StatusView(stdscr)
|
||||
msg_view = MsgView(stdscr, model.msgs, model, model.users)
|
||||
chat_view = ChatView(stdscr, model.users)
|
||||
msg_view = MsgView(stdscr, model)
|
||||
chat_view = ChatView(stdscr, model)
|
||||
view = View(stdscr, chat_view, msg_view, status_view)
|
||||
controller = Controller(model, view, tg)
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@ emoji_pattern = re.compile(
|
|||
"\U0001F300-\U0001F5FF" # symbols & pictographs
|
||||
"\U0001F680-\U0001F6FF" # transport & map symbols
|
||||
"\U0001F1E0-\U0001F1FF" # flags (iOS)
|
||||
"\U00002702-\U000027B0"
|
||||
# "\U00002702-\U000027B0"
|
||||
# "\U000024C2-\U0001F251"
|
||||
"]+",
|
||||
flags=re.UNICODE,
|
||||
|
|
31
tg/views.py
31
tg/views.py
|
@ -126,13 +126,13 @@ class StatusView:
|
|||
|
||||
|
||||
class ChatView:
|
||||
def __init__(self, stdscr: window, users: UserModel, p: float = 0.5):
|
||||
def __init__(self, stdscr: window, model: Model):
|
||||
self.stdscr = stdscr
|
||||
self.h = 0
|
||||
self.w = 0
|
||||
self.win = stdscr.subwin(self.h, self.w, 0, 0)
|
||||
self._refresh = self.win.refresh
|
||||
self.users = users
|
||||
self.model = model
|
||||
|
||||
def resize(self, rows: int, cols: int, p: float = 0.25) -> None:
|
||||
self.h = rows - 1
|
||||
|
@ -214,7 +214,17 @@ class ChatView:
|
|||
) -> str:
|
||||
flags = []
|
||||
|
||||
if self.users.is_online(chat["id"]):
|
||||
msg = chat.get("last_message")
|
||||
if (
|
||||
msg
|
||||
and self.model.is_me(msg["sender_user_id"])
|
||||
and msg["id"] > chat["last_read_outbox_message_id"]
|
||||
and not self.model.is_me(chat["id"])
|
||||
):
|
||||
# last msg haven't been seen by recipient
|
||||
flags.append("unseen")
|
||||
|
||||
if self.model.users.is_online(chat["id"]):
|
||||
flags.append("online")
|
||||
|
||||
if is_pinned:
|
||||
|
@ -234,16 +244,9 @@ class ChatView:
|
|||
|
||||
class MsgView:
|
||||
def __init__(
|
||||
self,
|
||||
stdscr: window,
|
||||
msg_model: MsgModel,
|
||||
model: Model,
|
||||
users: UserModel,
|
||||
p: float = 0.5,
|
||||
) -> None:
|
||||
self.msg_model = msg_model
|
||||
self, stdscr: window, model: Model,
|
||||
):
|
||||
self.model = model
|
||||
self.users = users
|
||||
self.stdscr = stdscr
|
||||
self.h = 0
|
||||
self.w = 0
|
||||
|
@ -297,7 +300,7 @@ class MsgView:
|
|||
def _format_reply_msg(
|
||||
self, chat_id: int, msg: str, reply_to: int, width_limit: int
|
||||
) -> str:
|
||||
_msg = self.msg_model.get_message(chat_id, reply_to)
|
||||
_msg = self.model.msgs.get_message(chat_id, reply_to)
|
||||
if not _msg:
|
||||
return msg
|
||||
reply_msg = MsgProxy(_msg)
|
||||
|
@ -473,7 +476,7 @@ class MsgView:
|
|||
def _get_user_by_id(self, user_id: int) -> str:
|
||||
if user_id == 0:
|
||||
return ""
|
||||
user = self.users.get_user(user_id)
|
||||
user = self.model.users.get_user(user_id)
|
||||
if user["first_name"] and user["last_name"]:
|
||||
return f'{user["first_name"]} {user["last_name"]}'[:20]
|
||||
|
||||
|
|
Loading…
Reference in a new issue