-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathchat.py
47 lines (33 loc) · 944 Bytes
/
chat.py
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
45
46
47
"""
chat example
run:
python -m example.chat
"""
from database.database import init_db
from env_wrapper import load_env
from pagination.pagination import PaginationSortOptions
from user.service import UserService
from chat.service import ChatHistoryPaginationOptions, ChatService
# setup
load_env()
init_db()
# list chat history
from_user = UserService.find_by_id(2)
to_user = UserService.find_by_id(3)
opts = ChatHistoryPaginationOptions()
opts.page = 1
opts.limit = 20
opts.sort = PaginationSortOptions.DESC
opts.order_by = "send_date"
opts.search = ""
opts.from_user_id = from_user.id
opts.to_user_id = to_user.id
chats = ChatService.list_chat_history(opts)
for chat in chats:
print(chat)
print("=" * 10)
# get last chat message
from_user = UserService.find_by_id(2)
to_user = UserService.find_by_id(3)
last_chat_message = ChatService.get_last_chat_message(from_user, to_user)
print(last_chat_message)