mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 20:47:54 +00:00
improve
This commit is contained in:
@@ -81,6 +81,7 @@ export interface Message {
|
||||
editedBy: EditedBy;
|
||||
urls: any[];
|
||||
temporaryData: object
|
||||
localReference?: string
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -103,6 +103,7 @@ export class LoginPage implements OnInit {
|
||||
if (attempt.UserId == SessionStore.user.UserId) {
|
||||
await this.authService.SetSession(attempt, this.userattempt);
|
||||
await this.authService.loginChat();
|
||||
await this.authService.loginToChatWs()
|
||||
this.getToken();
|
||||
SessionStore.setInativity(true);
|
||||
|
||||
@@ -117,6 +118,7 @@ export class LoginPage implements OnInit {
|
||||
|
||||
this.changeProfileService.run()
|
||||
await this.authService.loginChat();
|
||||
await this.authService.loginToChatWs()
|
||||
this.getToken();
|
||||
this.router.navigateByUrl('/pin', { replaceUrl: true });
|
||||
}
|
||||
|
||||
@@ -125,8 +125,6 @@ export class AuthService {
|
||||
|
||||
if(responseChat) {
|
||||
|
||||
this.loginToChatWs()
|
||||
|
||||
console.log('Login to Rocket chat OK', responseChat);
|
||||
this.ValidatedUserChat = responseChat;
|
||||
localStorage.setItem('userChat', JSON.stringify(responseChat));
|
||||
@@ -146,7 +144,7 @@ export class AuthService {
|
||||
}, expirationDate)
|
||||
}
|
||||
|
||||
private loginToChatWs() {
|
||||
loginToChatWs() {
|
||||
setTimeout(()=>{
|
||||
|
||||
this.WsChatService.connect();
|
||||
|
||||
@@ -34,13 +34,14 @@ export class MessageService {
|
||||
errorUploadingAttachment = false
|
||||
loadHistory = false
|
||||
duration = ''
|
||||
localReference = null
|
||||
|
||||
constructor(private storage: Storage,
|
||||
private NfService: NfService,
|
||||
private WsChatService: WsChatService) {
|
||||
}
|
||||
|
||||
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData}:Message) {
|
||||
setData({customFields, channels, mentions, msg ,rid ,ts, u, t, _id, _updatedAt, file, attachments, temporaryData, localReference}:Message) {
|
||||
this.customFields = customFields
|
||||
this.channels = channels || []
|
||||
this.mentions = mentions || []
|
||||
@@ -54,6 +55,7 @@ export class MessageService {
|
||||
this.file = file
|
||||
this.attachments = attachments
|
||||
this.temporaryData = temporaryData
|
||||
this.localReference = localReference || null
|
||||
|
||||
if(!this.ts) {
|
||||
this.offline = true
|
||||
@@ -104,8 +106,8 @@ export class MessageService {
|
||||
this.sendAttempt++;
|
||||
|
||||
if(!this.hasFile) {
|
||||
this.WsChatService.send({roomId:this.rid, msg:this.msg}).then((data: any) => {
|
||||
let ChatMessage = data.result
|
||||
this.WsChatService.send({roomId:this.rid, msg:this.msg, requestId: this.localReference}).then(({message, requestId}) => {
|
||||
let ChatMessage = message.result
|
||||
|
||||
if (environment.chatOffline) {
|
||||
this.redefinedMessage(this, ChatMessage)
|
||||
@@ -132,8 +134,8 @@ export class MessageService {
|
||||
this.errorUploadingAttachment = false
|
||||
this.temporaryData = {}
|
||||
|
||||
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file}).then((data: any) => {
|
||||
let ChatMessage = data.result
|
||||
this.WsChatService.send({roomId:this.rid, msg: this.msg, attachments: this.attachments, file: this.file, requestId: this.localReference}).then(({message, requestId}) => {
|
||||
let ChatMessage = message.result
|
||||
|
||||
if (environment.chatOffline) {
|
||||
this.redefinedMessage(this, ChatMessage)
|
||||
@@ -154,14 +156,19 @@ export class MessageService {
|
||||
})
|
||||
|
||||
} else if(uploadSuccessfully == false) {
|
||||
|
||||
this.errorUploadingAttachment = true
|
||||
|
||||
return new Promise((resolve, reject)=>{
|
||||
reject(false)
|
||||
})
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
redefinedMessage(message, ChatMessage) {
|
||||
ChatMessage = this.NfService.fix_updatedAt(ChatMessage)
|
||||
this.setData(ChatMessage)
|
||||
}
|
||||
|
||||
@@ -178,4 +185,5 @@ export class MessageService {
|
||||
this.duration = showDateDuration(date || this._updatedAt);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -10,5 +10,16 @@ export class NfService {
|
||||
beforeSendAttachment = async (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)));
|
||||
downloadFileMsg = async (message: MessageService, room?: RoomService): Promise<boolean> => new Promise ((resolve, reject)=> (resolve(true)));
|
||||
|
||||
fix_updatedAt(message) {
|
||||
if (message.result) {
|
||||
message.result._updatedAt = message.result._updatedAt['$date']
|
||||
} else if(message._updatedAt) {
|
||||
if(message._updatedAt.hasOwnProperty('$date')) {
|
||||
message._updatedAt = message._updatedAt['$date']
|
||||
}
|
||||
}
|
||||
return message
|
||||
}
|
||||
|
||||
constructor() { }
|
||||
}
|
||||
|
||||
@@ -39,10 +39,11 @@ export class RoomService {
|
||||
message = ''
|
||||
lastMessageTxt = ''
|
||||
userThatIsTyping = ''
|
||||
|
||||
private ToastService = ToastsService
|
||||
mgsArray = [];
|
||||
|
||||
messagesLocalReference = []
|
||||
|
||||
scrollDown = () => { }
|
||||
|
||||
/**
|
||||
@@ -92,12 +93,11 @@ export class RoomService {
|
||||
this.id,
|
||||
"stream-room-messages",
|
||||
(_ChatMessage) => {
|
||||
console.log('recivemessage', _ChatMessage)
|
||||
|
||||
let ChatMessage = _ChatMessage.fields.args[0]
|
||||
|
||||
ChatMessage = this.fix_updatedAt(ChatMessage)
|
||||
console.log('recivemessage', ChatMessage)
|
||||
|
||||
alert('receive')
|
||||
const message = this.prepareMessage(ChatMessage)
|
||||
this.lastMessage = message
|
||||
this.calDateDuration(ChatMessage._updatedAt)
|
||||
@@ -117,7 +117,7 @@ export class RoomService {
|
||||
|
||||
setTimeout(()=>{
|
||||
this.scrollDown()
|
||||
}, 50)
|
||||
}, 50)
|
||||
|
||||
}
|
||||
)
|
||||
@@ -266,7 +266,7 @@ export class RoomService {
|
||||
*/
|
||||
async send({file = null, attachments = null, temporaryData = {}}) {
|
||||
|
||||
const localReference = uuidv4()
|
||||
const localReference = uuidv4() + 'peter'
|
||||
|
||||
let offlineChatMessage = {
|
||||
rid: this.id,
|
||||
@@ -278,14 +278,15 @@ export class RoomService {
|
||||
}
|
||||
|
||||
const message: MessageService = this.prepareMessage(offlineChatMessage, environment.chatOffline)
|
||||
|
||||
message.send().then((ChatMessage) => {
|
||||
this.updateMessageDB(ChatMessage, localReference)
|
||||
})
|
||||
|
||||
if (environment.chatOffline) {
|
||||
|
||||
message.send().then((ChatMessage) => {
|
||||
this.updateMessageDB(ChatMessage, localReference)
|
||||
})
|
||||
|
||||
this.messagesLocalReference.push(localReference)
|
||||
this.addMessageDB(offlineChatMessage)
|
||||
|
||||
setTimeout(() => {
|
||||
this.scrollDown()
|
||||
}, 150)
|
||||
@@ -392,6 +393,7 @@ export class RoomService {
|
||||
if(wewMessage.offline == false) {
|
||||
this.prepareMessage(ChatMessage)
|
||||
} else {
|
||||
alert('create offline')
|
||||
const offlineMessage = this.prepareMessage(ChatMessage)
|
||||
offlineMessage.send().then(()=>{
|
||||
this.updateMessageDB(ChatMessage, ChatMessage.localReference)
|
||||
@@ -449,15 +451,23 @@ export class RoomService {
|
||||
wewMessage.loadHistory = this.hasLoadHistory
|
||||
|
||||
if(!message._id && environment.chatOffline) {
|
||||
if(this.hasLoadHistory) alert('create offline')
|
||||
|
||||
this.messages.push(wewMessage)
|
||||
return wewMessage
|
||||
}
|
||||
|
||||
const found = this.messages.find((MessageService) => {
|
||||
return MessageService._id == message._id
|
||||
if (MessageService._id == message._id) {
|
||||
if(this.hasLoadHistory) console.log(`${MessageService._id} == ${message._id}`)
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
})
|
||||
|
||||
if (save && !found) {
|
||||
if(this.hasLoadHistory) alert('not found')
|
||||
this.messages.push(wewMessage)
|
||||
}
|
||||
|
||||
|
||||
@@ -36,6 +36,7 @@ export class WsChatService {
|
||||
|
||||
this.ws.registerCallback({
|
||||
type:'Onmessage',
|
||||
key:'ping-pong',
|
||||
funx:(message: any) => {
|
||||
if(message.msg == "ping") {
|
||||
this.ws.send({message:{msg:"pong"}, loginRequired: false})
|
||||
@@ -157,9 +158,7 @@ export class WsChatService {
|
||||
}
|
||||
|
||||
// send message to room
|
||||
send({roomId, msg, attachments = null, file = null}) {
|
||||
|
||||
const requestId = uuidv4()
|
||||
send({roomId, msg, attachments = null, file = null, requestId = uuidv4()}) {
|
||||
|
||||
var message = {
|
||||
msg: "method",
|
||||
@@ -178,7 +177,7 @@ export class WsChatService {
|
||||
return new Promise((resolve, reject) => {
|
||||
this.ws.registerCallback({type:'Onmessage', funx:(message)=>{
|
||||
if(message.id == requestId ) { // same request send
|
||||
resolve(message)
|
||||
resolve({message, requestId})
|
||||
return true
|
||||
}
|
||||
}})
|
||||
@@ -677,7 +676,7 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
this.wsMsgQueue[requestId] = {message, requestId, loginRequired}
|
||||
} else {
|
||||
let messageStr = JSON.stringify(message)
|
||||
|
||||
console.log('messageStr', messageStr)
|
||||
this.socket.send(messageStr)
|
||||
}
|
||||
return requestId
|
||||
@@ -686,6 +685,8 @@ updateRoomEventss(roomId, collection:string, funx: Function, ) {
|
||||
onmessage: async (event: any)=> {
|
||||
const data = JSON.parse(event.data)
|
||||
|
||||
console.log('onmessage', data)
|
||||
|
||||
for (const [key, value] of Object.entries(this.wsCallbacks)) {
|
||||
if(value.type== 'Onmessage') {
|
||||
const dontRepeat = await value.funx(data)
|
||||
|
||||
@@ -49,7 +49,7 @@
|
||||
<div class="message-item-options d-flex justify-content-end">
|
||||
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon>
|
||||
<mat-menu #beforeMenu="matMenu" xPosition="before">
|
||||
<button (click)="deleteMessage(msg._id, msg)" class="menuButton">Apagar mensagem</button>
|
||||
<button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
<div class="title">
|
||||
@@ -68,7 +68,7 @@
|
||||
<div class="message-item-options d-flex justify-content-end">
|
||||
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon>
|
||||
<mat-menu #beforeMenu="matMenu" xPosition="before">
|
||||
<button (click)="deleteMessage(msg._id, msg)" class="menuButton">Apagar mensagem</button>
|
||||
<button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
<div class="title">
|
||||
|
||||
@@ -307,7 +307,8 @@ export class GroupMessagesPage implements OnInit, OnChanges, AfterViewInit, OnDe
|
||||
this.wsChatMethodsService.getGroupRoom(this.roomId).send({})
|
||||
}
|
||||
|
||||
deleteMessage(msgId: string, room:any) {
|
||||
deleteMessage(msgId: string) {
|
||||
const room = this.wsChatMethodsService.getGroupRoom(this.roomId)
|
||||
this.alertService.confirmDeleteMessage(msgId, room);
|
||||
}
|
||||
|
||||
|
||||
@@ -34,8 +34,7 @@ export class ContactsPage implements OnInit {
|
||||
private authService: AuthService,
|
||||
public ThemeService: ThemeService,
|
||||
public WsChatMethodsService: WsChatMethodsService
|
||||
)
|
||||
{
|
||||
) {
|
||||
this.loggedUser = authService.ValidatedUserChat['data'];
|
||||
this.textSearch="";
|
||||
this.dm=null;
|
||||
|
||||
@@ -44,7 +44,7 @@
|
||||
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">
|
||||
</fa-icon>
|
||||
<mat-menu #beforeMenu="matMenu" xPosition="before">
|
||||
<button (click)="deleteMessage(msg._id, msg)" class="menuButton">Apagar mensagem</button>
|
||||
<button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
<div class="title">
|
||||
@@ -63,7 +63,7 @@
|
||||
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer">
|
||||
</fa-icon>
|
||||
<mat-menu #beforeMenu="matMenu" xPosition="before">
|
||||
<button (click)="deleteMessage(msg._id, msg)" class="menuButton">Apagar mensagem</button>
|
||||
<button (click)="deleteMessage(msg._id)" class="menuButton">Apagar mensagem</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
<div class="title">
|
||||
|
||||
@@ -249,7 +249,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.wsChatMethodsService.getDmRoom(this.roomId).send({})
|
||||
}
|
||||
|
||||
deleteMessage(msgId: string, room:any) {
|
||||
deleteMessage(msgId: string) {
|
||||
const room = this.wsChatMethodsService.getDmRoom(this.roomId)
|
||||
this.alertService.confirmDeleteMessage(msgId, room);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user