Skip to content

Commit 7bd77b3

Browse files
committed
(types) clean
1 parent 9998e47 commit 7bd77b3

File tree

2 files changed

+17
-30
lines changed

2 files changed

+17
-30
lines changed

src/utils/data-validation.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ export function roomsValidation(obj) {
2121

2222
if (!validate(obj, roomsValidate)) {
2323
throw new Error(
24-
'Rooms object is not valid! Must contain roomId[String, Number], roomName[String] and users[Array]'
24+
'Rooms object is not valid! Must contain at least roomId[String, Number], roomName[String] and users[Array]'
2525
)
2626
}
2727
}
@@ -41,15 +41,14 @@ export function partcipantsValidation(obj) {
4141

4242
if (!validate(obj, participantsValidate)) {
4343
throw new Error(
44-
'Participants object is not valid! Must contain _id[String, Number] and username[String]'
44+
'Participants object is not valid! Must contain at least _id[String, Number] and username[String]'
4545
)
4646
}
4747
}
4848

4949
export function messagesValidation(obj) {
5050
const messagesValidate = [
5151
{ key: '_id', type: ['string', 'number'] },
52-
{ key: 'content', type: ['string', 'number'] },
5352
{ key: 'senderId', type: ['string', 'number'] }
5453
]
5554

@@ -62,7 +61,7 @@ export function messagesValidation(obj) {
6261

6362
if (!validate(obj, messagesValidate)) {
6463
throw new Error(
65-
'Messages object is not valid! Must contain _id[String, Number], content[String, Number] and senderId[String, Number]'
64+
'Messages object is not valid! Must contain at least _id[String, Number] and senderId[String, Number]'
6665
)
6766
}
6867
}

types/index.d.ts

Lines changed: 14 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,13 @@ export interface RoomUser {
1616
status: UserStatus
1717
}
1818

19-
export type RoomUsers = RoomUser[]
20-
2119
export interface MessageFile {
2220
name: string
2321
type: string
2422
extension: string
2523
url: string
26-
localUrl: string
27-
preview: string
24+
localUrl?: string
25+
preview?: string
2826
size?: number
2927
audio?: boolean
3028
duration?: number
@@ -48,28 +46,26 @@ export interface Room {
4846
roomId: string
4947
roomName: string
5048
avatar: string
51-
users: RoomUsers
49+
users: RoomUser[]
5250
unreadCount?: number
5351
index?: StringNumber | Date
5452
lastMessage?: LastMessage
5553
typingUsers?: string[]
5654
}
5755

58-
export type Rooms = Room[]
59-
6056
export interface MessageReactions {
6157
[key: string]: StringNumber[]
6258
}
6359

6460
export interface Message {
6561
_id: string
66-
indexId?: StringNumber
67-
content: string
6862
senderId: string
63+
indexId?: StringNumber
64+
content?: string
6965
username?: string
7066
avatar?: string
71-
date: string
72-
timestamp: string
67+
date?: string
68+
timestamp?: string
7369
system?: boolean
7470
saved?: boolean
7571
distributed?: boolean
@@ -83,23 +79,17 @@ export interface Message {
8379
replyMessage?: Message
8480
}
8581

86-
export type Messages = Message[]
87-
8882
export interface CustomAction {
8983
name: string
9084
title: string
9185
}
9286

93-
export type CustomActions = CustomAction[]
94-
9587
export interface MessageAction {
9688
name: string
9789
title: string
9890
onlyMe?: boolean
9991
}
10092

101-
export type MessageActions = MessageAction[]
102-
10393
export interface TextFormatting {
10494
disabled?: boolean
10595
italic?: string
@@ -111,8 +101,6 @@ export interface TextFormatting {
111101
}
112102
export type TemplateText = { tag: string; text: string }
113103

114-
export type TemplatesText = TemplateText[]
115-
116104
export interface AutoScroll {
117105
send?: {
118106
new?: boolean
@@ -138,21 +126,21 @@ export interface LinkOptions {
138126
export interface Props {
139127
height?: string
140128
'current-user-id': string
141-
rooms: Rooms
129+
rooms: Room[]
142130
'rooms-order'?: 'desc' | 'asc'
143131
'loading-rooms'?: boolean
144132
'rooms-loaded'?: boolean
145133
'room-id'?: string
146134
'load-first-room'?: boolean
147135
'rooms-list-opened'?: boolean
148-
messages: Messages
136+
messages: Message[]
149137
'room-message'?: string
150138
'username-options'?: UsernameOptions
151139
'messages-loaded'?: boolean
152-
'room-actions'?: CustomActions
153-
'menu-actions'?: CustomActions
140+
'room-actions'?: CustomAction[]
141+
'menu-actions'?: CustomAction[]
154142
'message-actions'?: MessageActions
155-
'message-selection-actions'?: CustomActions
143+
'message-selection-actions'?: CustomAction[]
156144
'templates-text'?: TemplatesText
157145
'auto-scroll'?: AutoScroll
158146
'show-search'?: boolean
@@ -188,8 +176,8 @@ export interface AdvancedChatOptions {
188176
}
189177

190178
export class VueAdvancedChat extends Vue {
191-
rooms: Rooms
192-
messages: Messages
179+
rooms: Room[]
180+
messages: Message[]
193181

194182
$props: Props
195183

0 commit comments

Comments
 (0)