File size: 6,219 Bytes
2c6bb7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
590318c
2c6bb7b
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
// User types
export interface User {
  id: string
  email: string
  username: string
  displayName: string
  avatar?: string
  bio?: string
  isOnline: boolean
  lastSeen: Date
  isAdmin: boolean
  createdAt: Date
  updatedAt: Date
}

export interface UserProfile {
  id: string
  userId: string
  displayName: string
  bio?: string
  avatar?: string
  theme: 'light' | 'dark' | 'system'
  notifications: NotificationSettings
  privacy: PrivacySettings
}

export interface NotificationSettings {
  messages: boolean
  mentions: boolean
  groups: boolean
  sounds: boolean
  desktop: boolean
}

export interface PrivacySettings {
  showOnlineStatus: boolean
  showLastSeen: boolean
  allowDirectMessages: boolean
  allowGroupInvites: boolean
}

// Chat types
export interface Chat {
  id: string
  type: 'direct' | 'group'
  name?: string
  description?: string
  avatar?: string
  participants: ChatParticipant[]
  lastMessage?: Message
  unreadCount: number
  createdAt: Date
  updatedAt: Date
}

export interface ChatParticipant {
  id: string
  chatId: string
  userId: string
  user: User
  role: 'member' | 'admin' | 'owner'
  joinedAt: Date
  permissions: ChatPermissions
}

export interface ChatPermissions {
  canSendMessages: boolean
  canSendMedia: boolean
  canAddMembers: boolean
  canRemoveMembers: boolean
  canEditChat: boolean
  canDeleteMessages: boolean
}

// Message types
export interface Message {
  id: string
  chatId: string
  senderId: string
  sender: User
  content: string
  type: MessageType
  attachments: MessageAttachment[]
  replyTo?: string
  replyToMessage?: Message
  reactions: MessageReaction[]
  isEdited: boolean
  isDeleted: boolean
  status?: 'sent' | 'delivered' | 'read'
  createdAt: Date
  updatedAt: Date
}

export type MessageType = 'text' | 'image' | 'file' | 'audio' | 'video' | 'system'

export interface MessageAttachment {
  id: string
  messageId: string
  type: 'image' | 'file' | 'audio' | 'video'
  name: string
  url: string
  size: number
  mimeType: string
  thumbnail?: string
}

export interface MessageReaction {
  id: string
  messageId: string
  userId: string
  user: User
  emoji: string
  createdAt: Date
}

// Group types
export interface Group {
  id: string
  name: string
  description?: string
  avatar?: string
  type: 'public' | 'private'
  memberCount: number
  maxMembers: number
  ownerId: string
  owner: User
  settings: GroupSettings
  createdAt: Date
  updatedAt: Date
}

export interface GroupSettings {
  allowMemberInvites: boolean
  requireApproval: boolean
  allowFileSharing: boolean
  allowVoiceMessages: boolean
  messageHistory: 'visible' | 'hidden'
  slowMode: number // seconds
}

// Socket events
export interface SocketEvents {
  // Connection
  connect: () => void
  disconnect: () => void
  
  // Authentication
  authenticate: (token: string) => void
  authenticated: (user: User) => void
  
  // Messages
  'message:send': (data: SendMessageData) => void
  'message:receive': (message: Message) => void
  'message:edit': (data: EditMessageData) => void
  'message:delete': (data: DeleteMessageData) => void
  'message:reaction': (data: MessageReactionData) => void
  
  // Typing
  'typing:start': (data: TypingData) => void
  'typing:stop': (data: TypingData) => void
  'typing:update': (data: TypingData) => void
  
  // User status
  'user:online': (userId: string) => void
  'user:offline': (userId: string) => void
  'user:status': (data: UserStatusData) => void
  
  // Chat events
  'chat:join': (chatId: string) => void
  'chat:leave': (chatId: string) => void
  'chat:update': (chat: Chat) => void
  
  // Group events
  'group:member:add': (data: GroupMemberData) => void
  'group:member:remove': (data: GroupMemberData) => void
  'group:update': (group: Group) => void
}

// Socket data types
export interface SendMessageData {
  chatId: string
  content: string
  type: MessageType
  attachments?: File[]
  replyTo?: string
}

export interface EditMessageData {
  messageId: string
  content: string
}

export interface DeleteMessageData {
  messageId: string
}

export interface MessageReactionData {
  messageId: string
  emoji: string
  action: 'add' | 'remove'
}

export interface TypingData {
  chatId: string
  userId: string
}

export interface UserStatusData {
  userId: string
  isOnline: boolean
  lastSeen?: Date
}

export interface GroupMemberData {
  groupId: string
  userId: string
  role?: 'member' | 'admin' | 'owner'
}

// API types
export interface ApiResponse<T = any> {
  success: boolean
  data?: T
  error?: string
  message?: string
}

export interface PaginatedResponse<T> {
  data: T[]
  total: number
  page: number
  limit: number
  hasMore: boolean
}

export interface LoginRequest {
  email: string
  password: string
}

export interface RegisterRequest {
  email: string
  username: string
  password: string
  displayName: string
}

export interface CreateChatRequest {
  type: 'direct' | 'group'
  name?: string
  description?: string
  participantIds: string[]
}

export interface UpdateProfileRequest {
  displayName?: string
  bio?: string
  avatar?: File
}

// Admin types
export interface AdminStats {
  totalUsers: number
  activeUsers: number
  totalChats: number
  totalMessages: number
  storageUsed: number
  serverUptime: number
}

export interface AdminUser extends User {
  messageCount: number
  chatCount: number
  lastActivity: Date
  status: 'active' | 'suspended' | 'banned'
}

export interface AdminChat extends Chat {
  messageCount: number
  activeMembers: number
  reportCount: number
  status: 'active' | 'archived' | 'suspended'
}

// Error types
export interface AppError {
  code: string
  message: string
  details?: any
}

export type ErrorCode = 
  | 'AUTH_REQUIRED'
  | 'INVALID_CREDENTIALS'
  | 'USER_NOT_FOUND'
  | 'CHAT_NOT_FOUND'
  | 'MESSAGE_NOT_FOUND'
  | 'PERMISSION_DENIED'
  | 'VALIDATION_ERROR'
  | 'SERVER_ERROR'
  | 'NETWORK_ERROR'