mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
improve message service
This commit is contained in:
@@ -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;
|
||||
};
|
||||
}
|
||||
@@ -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() {}
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
});
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user