Skip to content

Commit

Permalink
(types) clean
Browse files Browse the repository at this point in the history
  • Loading branch information
antoine92190 committed Nov 27, 2022
1 parent 9998e47 commit 7bd77b3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 30 deletions.
7 changes: 3 additions & 4 deletions src/utils/data-validation.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function roomsValidation(obj) {

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

if (!validate(obj, participantsValidate)) {
throw new Error(
'Participants object is not valid! Must contain _id[String, Number] and username[String]'
'Participants object is not valid! Must contain at least _id[String, Number] and username[String]'
)
}
}

export function messagesValidation(obj) {
const messagesValidate = [
{ key: '_id', type: ['string', 'number'] },
{ key: 'content', type: ['string', 'number'] },
{ key: 'senderId', type: ['string', 'number'] }
]

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

if (!validate(obj, messagesValidate)) {
throw new Error(
'Messages object is not valid! Must contain _id[String, Number], content[String, Number] and senderId[String, Number]'
'Messages object is not valid! Must contain at least _id[String, Number] and senderId[String, Number]'
)
}
}
Expand Down
40 changes: 14 additions & 26 deletions types/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,13 @@ export interface RoomUser {
status: UserStatus
}

export type RoomUsers = RoomUser[]

export interface MessageFile {
name: string
type: string
extension: string
url: string
localUrl: string
preview: string
localUrl?: string
preview?: string
size?: number
audio?: boolean
duration?: number
Expand All @@ -48,28 +46,26 @@ export interface Room {
roomId: string
roomName: string
avatar: string
users: RoomUsers
users: RoomUser[]
unreadCount?: number
index?: StringNumber | Date
lastMessage?: LastMessage
typingUsers?: string[]
}

export type Rooms = Room[]

export interface MessageReactions {
[key: string]: StringNumber[]
}

export interface Message {
_id: string
indexId?: StringNumber
content: string
senderId: string
indexId?: StringNumber
content?: string
username?: string
avatar?: string
date: string
timestamp: string
date?: string
timestamp?: string
system?: boolean
saved?: boolean
distributed?: boolean
Expand All @@ -83,23 +79,17 @@ export interface Message {
replyMessage?: Message
}

export type Messages = Message[]

export interface CustomAction {
name: string
title: string
}

export type CustomActions = CustomAction[]

export interface MessageAction {
name: string
title: string
onlyMe?: boolean
}

export type MessageActions = MessageAction[]

export interface TextFormatting {
disabled?: boolean
italic?: string
Expand All @@ -111,8 +101,6 @@ export interface TextFormatting {
}
export type TemplateText = { tag: string; text: string }

export type TemplatesText = TemplateText[]

export interface AutoScroll {
send?: {
new?: boolean
Expand All @@ -138,21 +126,21 @@ export interface LinkOptions {
export interface Props {
height?: string
'current-user-id': string
rooms: Rooms
rooms: Room[]
'rooms-order'?: 'desc' | 'asc'
'loading-rooms'?: boolean
'rooms-loaded'?: boolean
'room-id'?: string
'load-first-room'?: boolean
'rooms-list-opened'?: boolean
messages: Messages
messages: Message[]
'room-message'?: string
'username-options'?: UsernameOptions
'messages-loaded'?: boolean
'room-actions'?: CustomActions
'menu-actions'?: CustomActions
'room-actions'?: CustomAction[]
'menu-actions'?: CustomAction[]
'message-actions'?: MessageActions
'message-selection-actions'?: CustomActions
'message-selection-actions'?: CustomAction[]
'templates-text'?: TemplatesText
'auto-scroll'?: AutoScroll
'show-search'?: boolean
Expand Down Expand Up @@ -188,8 +176,8 @@ export interface AdvancedChatOptions {
}

export class VueAdvancedChat extends Vue {
rooms: Rooms
messages: Messages
rooms: Room[]
messages: Message[]

$props: Props

Expand Down

0 comments on commit 7bd77b3

Please sign in to comment.