diff --git a/src/app/pages/chat/chat.page.ts b/src/app/pages/chat/chat.page.ts index 939b20322..1f3d974e4 100644 --- a/src/app/pages/chat/chat.page.ts +++ b/src/app/pages/chat/chat.page.ts @@ -651,11 +651,11 @@ export class ChatPage implements OnInit { async getChatMembers() { - this.chatService.getAllUsers().subscribe(res => { - // - this.transformDataUserList(res['users']) + // this.chatService.getAllUsers().subscribe(res => { + // // + // this.transformDataUserList(res['users']) - }); + // }); } getGroupsDB() { diff --git a/src/app/services/chat/message.service.ts b/src/app/services/chat/message.service.ts index 80077e5b7..bc37ba7cc 100644 --- a/src/app/services/chat/message.service.ts +++ b/src/app/services/chat/message.service.ts @@ -408,36 +408,36 @@ export class MessageService { } async redefinedMessage(ChatMessage , update = true) { - ChatMessage = this.NfService.fix_updatedAt(ChatMessage) + // ChatMessage = this.NfService.fix_updatedAt(ChatMessage) - const message = this.getChatObj() + // const message = this.getChatObj() - this.manualRetry = false - this.messageSend = true + // this.manualRetry = false + // this.messageSend = true - ChatMessage = Object.assign(message, ChatMessage) - this.setData(ChatMessage) + // ChatMessage = Object.assign(message, ChatMessage) + // this.setData(ChatMessage) - const roomObject = this.ChatSystemService.getRoomById(this.rid) - const users = roomObject.getUsersByStatus('online') - for(const user of users) { - this.addReceived(user._id) - } + // const roomObject = this.ChatSystemService.getRoomById(this.rid) + // const users = roomObject.getUsersByStatus('online') + // for(const user of users) { + // this.addReceived(user._id) + // } - if(!roomObject.isGroup) { - var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe - this.notificationService.ChatSendMessageNotification(memeberTosend[0].username,ChatMessage.u.name,ChatMessage.msg || "Anexo",this.rid) - } else { - var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe - var usersNames = []; - for(let i = 0; i < memeberTosend.length; i++) { - usersNames.push(memeberTosend[i].username) - } - this.notificationService.ChatSendMessageNotificationGrup(usersNames,ChatMessage.u.name,ChatMessage.msg || "Anexo",this.rid) - } + // if(!roomObject.isGroup) { + // var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe + // this.notificationService.ChatSendMessageNotification(memeberTosend[0].username,ChatMessage.u.name,ChatMessage.msg || "Anexo",this.rid) + // } else { + // var memeberTosend = this.ChatSystemService.getRoomById(this.rid).membersExcludeMe + // var usersNames = []; + // for(let i = 0; i < memeberTosend.length; i++) { + // usersNames.push(memeberTosend[i].username) + // } + // this.notificationService.ChatSendMessageNotificationGrup(usersNames,ChatMessage.u.name,ChatMessage.msg || "Anexo",this.rid) + // } - await this.saveChanges() + // await this.saveChanges() } sendNotificaton @@ -458,8 +458,8 @@ export class MessageService { if (this.file.type == "application/img") { downloadFile = 'data:image/jpeg;base64,' + btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); } else if (this.file.type != "application/img") { - - + + downloadFile = btoa(new Uint8Array(event.body).reduce((data, byte) => data + String.fromCharCode(byte), '')); downloadUrl = event.url console.log('downloaded file', downloadFile) diff --git a/src/app/services/chat/room.service.ts b/src/app/services/chat/room.service.ts index b7d2ac6d9..db713cf67 100644 --- a/src/app/services/chat/room.service.ts +++ b/src/app/services/chat/room.service.ts @@ -400,22 +400,22 @@ export class RoomService { async info() { // set unread messages - const response: any = await this.chatService.GetSubscriptionRoomUnreadM(this.id).toPromise() + // const response: any = await this.chatService.GetSubscriptionRoomUnreadM(this.id).toPromise() - if(response?.subscription?.unread >= 1) { - this.messageUnread = true - } + // if(response?.subscription?.unread >= 1) { + // this.messageUnread = true + // } } getUsersByStatus(status: 'offline' | 'online') { - return this.getAllUsers().filter((user => { - for (const member of this.membersExcludeMe) { - if (user._id == member._id && user.status == status) { - return true - } - } - })) + // return this.getAllUsers().filter((user => { + // for (const member of this.membersExcludeMe) { + // if (user._id == member._id && user.status == status) { + // return true + // } + // } + // })) } @@ -430,40 +430,40 @@ export class RoomService { getAllMemberThatIsNotOffline(): string[] { - const membersIds = this.getRoomMembersIds() - const allChatUsers = this.getAllUsers() + // const membersIds = this.getRoomMembersIds() + // const allChatUsers = this.getAllUsers() - const AllMemberThatIsNotOffline = [] + // const AllMemberThatIsNotOffline = [] - for (let user of allChatUsers) { - if (membersIds.includes(user._id)) { + // for (let user of allChatUsers) { + // if (membersIds.includes(user._id)) { - if (user.status != 'offline') { - AllMemberThatIsNotOffline.push(user._id) - } - } - } + // if (user.status != 'offline') { + // AllMemberThatIsNotOffline.push(user._id) + // } + // } + // } - return AllMemberThatIsNotOffline + return [] } getAllMemberThatIsOffline(): string[] { - const membersIds = this.getRoomMembersIds() - const allChatUsers = this.getAllUsers() + // const membersIds = this.getRoomMembersIds() + // const allChatUsers = this.getAllUsers() - const AllMemberThatIsNotOffline = [] + // const AllMemberThatIsNotOffline = [] - for (let user of allChatUsers) { - if (membersIds.includes(user._id)) { + // for (let user of allChatUsers) { + // if (membersIds.includes(user._id)) { - if (user.status == 'offline') { - AllMemberThatIsNotOffline.push(user._id) - } - } - } + // if (user.status == 'offline') { + // AllMemberThatIsNotOffline.push(user._id) + // } + // } + // } - return AllMemberThatIsNotOffline + return [] } @@ -997,7 +997,7 @@ export class RoomService { const messagesToSave = await this.prepareMessageCreateIfNotExist({ message: message }); if (messagesToSave != null) { - messagesToSave.received = users.map((user) => user._id) + // messagesToSave.received = users.map((user) => user._id) messagesToSave.addMessageDB() } @@ -1008,7 +1008,7 @@ export class RoomService { const messagesToSave = await this.prepareMessageCreateIfNotExist({ message: message }); if (messagesToSave != null) { - messagesToSave.received = users.map((user) => user._id) + // messagesToSave.received = users.map((user) => user._id) this.addMessageDB.push(messagesToSave) } diff --git a/src/app/shared/chat/messages/contacts/contacts.page.html b/src/app/shared/chat/messages/contacts/contacts.page.html index 7b8cbfc29..5c15d7303 100644 --- a/src/app/shared/chat/messages/contacts/contacts.page.html +++ b/src/app/shared/chat/messages/contacts/contacts.page.html @@ -36,7 +36,7 @@ {{ header }} -
+

{{ user.wxFullName }}

diff --git a/src/app/shared/chat/messages/contacts/contacts.page.ts b/src/app/shared/chat/messages/contacts/contacts.page.ts index f955cd0c7..4e51f4680 100644 --- a/src/app/shared/chat/messages/contacts/contacts.page.ts +++ b/src/app/shared/chat/messages/contacts/contacts.page.ts @@ -10,7 +10,8 @@ import { ContactRepositoryService } from 'src/app/services/Repositorys/contacts/ import { UserContacts } from 'src/app/services/Repositorys/contacts/data-source/contacts-data-source.service'; import { RoomRepositoryService } from 'src/app/services/Repositorys/chat/repository/room-repository.service'; import { HttpErrorResponse } from '@angular/common/http'; - +import { HttpErrorHandle } from 'src/app/services/http-error-handle.service'; +import { ToastService } from 'src/app/services/toast.service'; class UserToSelect { @@ -45,11 +46,12 @@ export class ContactsPage implements OnInit { constructor( private modalController: ModalController, - private chatService: ChatService, public ThemeService: ThemeService, public ChatSystemService: ChatSystemService, private contactsRepositoryService: ContactRepositoryService, - private roomRepositoryService: RoomRepositoryService + private roomRepositoryService: RoomRepositoryService, + private httpErrorHandle: HttpErrorHandle, + private toastService: ToastService, ) { this.loggedUser = SessionStore.user.ChatData['data']; this.textSearch = ""; @@ -72,8 +74,8 @@ export class ContactsPage implements OnInit { this.userList.sort((a, b) => a.wxFullName.toLowerCase().localeCompare(b.wxFullName.toLowerCase())); } - openMessagesPage(username: string) { - this.createRoom(username); + openMessagesPage(username: string, wxUserId: number) { + this.createRoom(username, wxUserId); /* if (window.innerWidth < 701) { this.createRoom(username); } @@ -150,12 +152,13 @@ export class ContactsPage implements OnInit { } - async createRoom(username: string) { + async createRoom(username: string, wxUserId: number) { const result = await this.roomRepositoryService.create({ roomName: username, createdBy: SessionStore.user.UserId, roomType: 0, - expirationDate: null + expirationDate: null, + members: [wxUserId] }) @@ -163,10 +166,13 @@ export class ContactsPage implements OnInit { if(result.isOk()) { - // this.addGroupMessage.emit(result); + this.openMessage.emit(result.value.data.id); } else if(result.error instanceof HttpErrorResponse) { - + this.httpErrorHandle.httpStatusHandle(result.error) + } else { + this.toastService._badRequest("Pedimos desculpa mas não foi possível executar a acção. Por favor, contacte o apoio técnico.") + console.log(result.error) } /* this.chatService.createRoom(body).subscribe(res => { @@ -192,13 +198,5 @@ export class ContactsPage implements OnInit { await modal.present(); } - async openMessages(username: string) { - /* this.close(); */ - - let dm: any; - //Create new room - this.createRoom(username); - - } }