improve message service

This commit is contained in:
Peter Maquiran
2022-01-13 10:52:03 +01:00
parent 8386781f77
commit 3565d5ceb2
3 changed files with 120 additions and 16 deletions
+12 -12
View File
@@ -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)
});
})