Merge pull request #90 from paul-nameless/show-unseen

Show unseen flag in chat pane
This commit is contained in:
Nameless 2020-06-26 10:31:58 +08:00 committed by GitHub
commit 47f6b915c9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 24 additions and 18 deletions

View file

@ -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": "*",

View file

@ -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)

View file

@ -323,7 +323,7 @@ class MsgModel:
return result.update
return next(iter(m for m in self.msgs[chat_id] if m["id"] == msg_id))
def remove_message(self, chat_id, msg_id):
def remove_message(self, chat_id: int, msg_id: int):
msg_set = self.msg_ids[chat_id]
if msg_id not in msg_set:
return False

View file

@ -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,

View file

@ -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]