-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwidgets.py
More file actions
44 lines (38 loc) · 1.72 KB
/
widgets.py
File metadata and controls
44 lines (38 loc) · 1.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from textual.app import ComposeResult
from textual.widgets import Static, Label, ListItem
from textual.containers import Vertical, Horizontal
import datetime
class MessageItem(ListItem):
def __init__(self, author: str, timestamp_ms: int, content: str, is_self: bool = False):
super().__init__()
self.author = author
self.is_self = is_self
try:
# fbchat returns timestamps in milliseconds
dt = datetime.datetime.fromtimestamp(int(timestamp_ms) / 1000.0)
self.timestamp = dt.strftime("%m-%d %H:%M")
except Exception:
self.timestamp = str(timestamp_ms)
self.msg_content = content or "[Attachment/Non-text message]"
def compose(self) -> ComposeResult:
header_class = "message-header self" if self.is_self else "message-header"
with Horizontal(classes="message-header-container"):
yield Static(f"{self.author}", classes=header_class)
yield Static(f"({self.timestamp})", classes="message-time")
yield Static(self.msg_content, classes="message-content")
class ThreadItem(ListItem):
def __init__(self, thread_id: str, name: str, thread_type):
super().__init__()
self.thread_id = str(thread_id)
self.thread_name = name or "Unknown Thread"
self.thread_type = thread_type
def compose(self) -> ComposeResult:
yield Label(f"{self.thread_name}")
class UserItem(ListItem):
def __init__(self, user_id: str, name: str, thread_type):
super().__init__()
self.user_id = str(user_id)
self.user_name = name or "Unknown User"
self.thread_type = thread_type
def compose(self) -> ComposeResult:
yield Label(f"{self.user_name}")