-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmodels.py
More file actions
58 lines (47 loc) · 1.89 KB
/
models.py
File metadata and controls
58 lines (47 loc) · 1.89 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import swapper
from .base import (
AbstractBaseChatRoom,
AbstractBaseMessage,
AbstractChatRoomParticipant,
AbstractMessageStatus,
AbstractUnreadMessageCount,
)
from .triggers import (
create_message_status_trigger,
decrement_unread_count_trigger,
increment_unread_count_trigger,
set_last_message_on_insert_trigger,
update_last_message_on_delete_trigger,
)
class ChatRoom(AbstractBaseChatRoom):
class Meta(AbstractBaseChatRoom.Meta):
swappable = swapper.swappable_setting("baseapp_chats", "ChatRoom")
class ChatRoomParticipant(AbstractChatRoomParticipant):
class Meta(AbstractChatRoomParticipant.Meta):
swappable = swapper.swappable_setting("baseapp_chats", "ChatRoomParticipant")
class UnreadMessageCount(AbstractUnreadMessageCount):
class Meta(AbstractUnreadMessageCount.Meta):
swappable = swapper.swappable_setting("baseapp_chats", "UnreadMessageCount")
class Message(AbstractBaseMessage):
class Meta(AbstractBaseMessage.Meta):
swappable = swapper.swappable_setting("baseapp_chats", "Message")
triggers = (
[]
if swapper.is_swapped("baseapp_chats", "Message")
else [
set_last_message_on_insert_trigger(ChatRoom),
create_message_status_trigger(ChatRoomParticipant, AbstractBaseMessage.MessageType),
update_last_message_on_delete_trigger(ChatRoom),
]
)
class MessageStatus(AbstractMessageStatus):
class Meta(AbstractMessageStatus.Meta):
swappable = swapper.swappable_setting("baseapp_chats", "MessageStatus")
triggers = (
[]
if swapper.is_swapped("baseapp_chats", "MessageStatus")
else [
increment_unread_count_trigger(UnreadMessageCount, Message),
decrement_unread_count_trigger(UnreadMessageCount, Message),
]
)