commet all chat method and fix create direct message

This commit is contained in:
Peter Maquiran
2024-06-12 00:25:37 +01:00
parent 39bc8979a8
commit 703c3aaed6
5 changed files with 80 additions and 82 deletions
+4 -4
View File
@@ -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() {
+23 -23
View File
@@ -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
+35 -35
View File
@@ -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)
}
@@ -36,7 +36,7 @@
<ion-label>{{ header }}</ion-label>
</div>
<div (click)="openMessagesPage(user.wxFullName)" *virtualItem="let user" class="item-user cursor-pointer">
<div (click)="openMessagesPage(user.wxFullName, user.wxUserId)" *virtualItem="let user" class="item-user cursor-pointer">
<p>{{ user.wxFullName }}</p>
<span class="icon">
<ion-icon [class]="user.status" slot="end" name="ellipse"></ion-icon>
@@ -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);
}
}