diff --git a/src/app/models/chatMethod.ts b/src/app/models/chatMethod.ts new file mode 100644 index 000000000..122e3ff01 --- /dev/null +++ b/src/app/models/chatMethod.ts @@ -0,0 +1,101 @@ +export interface Ts { + $date: any; +} + +export interface U { + _id: string; + username: string; + name: string; +} + +interface UpdatedAt { + $date: any; +} + +interface Attachment { + ts: Date; + title_link_download: boolean; +} + +export interface File { + type: string; + guid: string; + image_url: string; + subject: string; + start_date?: Date; + end_date?: Date; + venue: string; + id: string; +} + +interface EditedAt { + $date: number; +} + +interface EditedBy { + _id: string; + username: string; +} + + + +interface Ts2 { + $date: number; +} + +interface U2 { + _id: string; + username: string; + name: string; +} + +interface UpdatedAt2 { + $date: number; +} + +interface FirstUnread { + _id: string; + rid: string; + msg: string; + ts: Ts2; + u: U2; + _updatedAt: UpdatedAt2; + mentions: any[]; + channels: any[]; +} + +export interface Message { + _id: string; + rid: string; + msg: string; + ts: Ts; + u: U; + _updatedAt: UpdatedAt; + mentions: any[]; + channels: any[]; + attachments: Attachment[]; + file: File; + editedAt: EditedAt; + editedBy: EditedBy; + urls: any[]; +} + +export interface ChatMessage { + msg: string; + id: string; + result: Message +} + + + + + +export interface chatHistory { + msg: string; + id: string; + result: { + messages: Message[]; + firstUnread: FirstUnread; + unreadNotLoaded: number; + }; +} diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index cf1b39a98..ffdf4c9cf 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -1,4 +1,6 @@ import { Injectable } from '@angular/core'; +import { Message } from 'src/app/models/chatMethod'; +import { chatHistory, ChatMessage, File } from 'src/app/models/chatMethod' @Injectable({ providedIn: 'root' @@ -13,10 +15,12 @@ export class MessageService { u = {} _id ='' _updatedAt = {} + file + attachments constructor() { } - setData({channels, mentions, msg ,rid ,ts, u, _id, _updatedAt}) { + setData({channels, mentions, msg ,rid ,ts, u, _id, _updatedAt, file, attachments}:Message) { this.channels = channels this.mentions = mentions this.msg = msg @@ -25,13 +29,12 @@ export class MessageService { this.u = u this._id = _id this._updatedAt = _updatedAt + this.file = file + this.attachments = attachments } delete() {} showDateDuration() {} - - - } diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index 210147e20..7c5299e45 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -4,7 +4,7 @@ import { MessageService } from 'src/app/services/chat/message.service' import { ChatUserService } from 'src/app/services/chat/chat-user.service' import { showDateDuration } from 'src/plugin/showDateDuration' import { ToastsService } from '../toast.service'; - +import { chatHistory, ChatMessage } from 'src/app/models/chatMethod' @Injectable({ providedIn: 'root' }) @@ -39,13 +39,13 @@ export class RoomService { receiveMessage() { this.WsChatService.receiveLiveMessageFromRoom( this.id, - (Chatmessage) => { + (ChatMessage:ChatMessage) => { - Chatmessage = this.fix_updatedAt(Chatmessage) + ChatMessage = this.fix_updatedAt(ChatMessage) const message = new MessageService() - message.setData(Chatmessage.result) + message.setData(ChatMessage.result) this.massages.push(message) - this.calDateDuration(Chatmessage.result._updatedAt) + this.calDateDuration(ChatMessage.result._updatedAt) this.ToastService.presentToast('nova mensagem') } ) @@ -60,15 +60,15 @@ export class RoomService { if(this.hasLoadHistory){ return false} - this.WsChatService.loadHistory(this.id, limit).then((message:any) => { - console.log('loadHistory', message) + this.WsChatService.loadHistory(this.id, limit).then((chatHistory:chatHistory) => { + console.log('loadHistory', chatHistory) - message.result.messages.reverse().forEach(element => { + chatHistory.result.messages.reverse().forEach(message => { - element = this.fix_updatedAt(element) - const message = new MessageService() - message.setData(element) - this.massages.push(message) + message = this.fix_updatedAt(message) + const wewMessage = new MessageService() + wewMessage.setData(message) + this.massages.push(wewMessage) }); })