Merge branch 'feature/websocket' of https://bitbucket.org/equilibriumito/gabinete-digital into feature/websocket

This commit is contained in:
tiago.kayaya
2022-01-13 13:46:56 +01:00
13 changed files with 341 additions and 108 deletions
+20 -17
View File
@@ -3,6 +3,8 @@ import { WsChatService } from 'src/app/services/chat/ws-chat.service';
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'
})
@@ -18,6 +20,7 @@ export class RoomService {
private hasLoadHistory = false
duration = ''
private ToastService = ToastsService
constructor(
public WsChatService: WsChatService,
@@ -25,7 +28,6 @@ export class RoomService {
) {}
setData({id, name, lastMessage, _updatedAt}) {
this.id = id
this.name = name
this.lastMessage = lastMessage
@@ -37,15 +39,14 @@ export class RoomService {
receiveMessage() {
this.WsChatService.receiveLiveMessageFromRoom(
this.id,
this.constructor.name+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')
}
)
}
@@ -59,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 => {
console.log('element', element)
element = this.fix_updatedAt(element)
const message = new MessageService()
message.setData(element)
this.massages.push(message)
chatHistory.result.messages.reverse().forEach(message => {
message = this.fix_updatedAt(message)
const wewMessage = new MessageService()
wewMessage.setData(message)
this.massages.push(wewMessage)
});
})
@@ -75,8 +76,6 @@ export class RoomService {
this.hasLoadHistory = true
}
create() {}
deleteMessage(msgId) {}
ReactToMessage() {}
private calDateDuration(date = null) {
@@ -93,4 +92,8 @@ export class RoomService {
return message
}
// to add
countDownDate(){}
}