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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
|
%% JCHAT Record Definitions
%% User record for authentication and profile management
-record(user, {
id, % binary() - Unique user ID (UUID)
email, % binary() - Email address (unique)
password_hash, % binary() - Hashed password (bcrypt)
display_name, % binary() - Display name for UI
created_at, % binary() - ISO8601 timestamp
last_login_at, % binary() | null - Last login time
is_active, % boolean() - Account active status
auth_provider, % binary() - 'local' | 'google' | 'github' etc
auth_provider_id % binary() | null - External provider user ID
}).
%% Session record for tracking active sessions
-record(session, {
id, % binary() - Session token/ID
user_id, % binary() - User ID
created_at, % binary() - ISO8601 timestamp
expires_at, % binary() - ISO8601 timestamp
ip_address, % binary() - Client IP
user_agent % binary() - Client user agent
}).
%% Conversation record
-record(conversation, {
id, % binary() - Conversation ID
title, % binary() | null - Conversation title
description, % binary() | null - Description
conversation_type, % binary() - 'direct' | 'group' | 'channel' | 'announcement'
privacy_level, % binary() - 'private' | 'public' | 'restricted'
created_at, % binary() - ISO8601 timestamp
updated_at, % binary() - ISO8601 timestamp
created_by, % binary() - Creator user ID
is_archived, % boolean() - Archived status
is_muted, % boolean() - Muted status for notifications
participant_ids, % [binary()] - Participant IDs
last_message_id, % binary() | null - Last message ID
last_message_at, % binary() | null - Last message timestamp
unread_count, % integer() - Unread message count
message_count, % integer() - Total message count
settings, % map() - Conversation settings
metadata % map() - Additional conversation data
}).
%% Message record
-record(message, {
id, % binary() - Message ID
conversation_id, % binary() - Conversation ID
sender_id, % binary() - Sender user ID
body, % binary() - Message content
body_type, % binary() - Content type (text/plain, text/html, etc)
sent_at, % binary() - ISO8601 timestamp
received_at, % binary() - ISO8601 timestamp (when delivered to server)
edited_at, % binary() | null - Edit timestamp
is_deleted, % boolean() - Soft delete flag
is_system_message, % boolean() - System/automated message flag
reply_to_message_id, % binary() | null - Reply reference
attachments, % [map()] - Attachment metadata
reactions, % [map()] - Message reactions
delivery_status, % binary() - 'sent' | 'delivered' | 'read' | 'failed'
read_by, % [binary()] - List of user IDs who have read this message
metadata % map() - Additional message data
}).
%% Participant record
-record(participant, {
id, % binary() - Participant ID
conversation_id, % binary() - Conversation ID
user_id, % binary() - User ID
display_name, % binary() - Display name at time of joining
avatar_blob_id, % binary() | null - Avatar image blob ID
role, % binary() - 'owner' | 'admin' | 'moderator' | 'member'
joined_at, % binary() - ISO8601 timestamp
left_at, % binary() | null - Leave timestamp
last_active_at, % binary() | null - Last activity timestamp
is_active, % boolean() - Active in conversation
permissions, % [binary()] - Specific permissions
last_read_message_id, % binary() | null - Last read message
last_read_at, % binary() | null - Last read timestamp
metadata % map() - Additional participant data
}).
%% Presence record
-record(presence, {
user_id, % binary() - User ID
status, % binary() - 'online' | 'away' | 'busy' | 'offline'
status_message, % binary() | null - Custom status message
last_seen_at, % binary() - ISO8601 timestamp
is_typing_in, % binary() | null - Conversation ID if typing
updated_at % binary() - ISO8601 timestamp
}).
%% State counter for JMAP synchronization
-record(state_counter, {
account_id, % binary() - Account ID
object_type, % binary() - Object type (conversation, message, etc)
state, % binary() - Current state value
updated_at % binary() - ISO8601 timestamp
}).
%% Role definition for RBAC
-record(role, {
id, % binary() - Role ID
name, % binary() - Human readable name
description, % binary() - Role description
permissions, % [binary()] - List of permission strings
is_system, % boolean() - System role vs user-defined
created_at % binary() - ISO8601 timestamp
}).
%% User role assignments (system-wide)
-record(user_role, {
user_id, % binary() - User ID
role_id, % binary() - Role ID
granted_by, % binary() - User ID who granted the role
granted_at % binary() - ISO8601 timestamp
}).
%% Conversation-specific role assignments
-record(conversation_role, {
user_id, % binary() - User ID
conversation_id, % binary() - Conversation ID
role_id, % binary() - Role ID
granted_by, % binary() - User ID who granted the role
granted_at % binary() - ISO8601 timestamp
}).
|