mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix direct room
This commit is contained in:
@@ -27,6 +27,7 @@ import { RoomViewModel } from './store/model/room';
|
||||
import { MessageLocalDataSourceService } from 'src/app/module/chat/data/repository/message/message-local-data-source.service'
|
||||
import { ToastService } from 'src/app/services/toast.service';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { IDBoolean } from 'src/app/infra/database/dexie/type';
|
||||
@Component({
|
||||
selector: 'app-chat',
|
||||
templateUrl: './chat.page.html',
|
||||
@@ -110,8 +111,8 @@ export class ChatPage implements OnInit {
|
||||
}
|
||||
|
||||
|
||||
updatemessage(sortedRooms) {
|
||||
this.rooms = sortedRooms
|
||||
updatemessage(sortedRooms: RoomViewModel[]) {
|
||||
this.rooms = sortedRooms.filter(e => e.local == IDBoolean.false)
|
||||
|
||||
this.rooms.sort((a, b) =>
|
||||
new Date(b.messages?.[0]?.sentAt as string || b.createdAt ).getTime() -
|
||||
@@ -347,7 +348,7 @@ export class ChatPage implements OnInit {
|
||||
this.RoomSelected = exist
|
||||
this.selectedRoomId = exist.$id;
|
||||
if (window.innerWidth < 701) {
|
||||
this.openMessagesModal($roomId);
|
||||
this.openMessagesModal(this.RoomSelected);
|
||||
}
|
||||
else {
|
||||
this.selectedRoomId = $roomId;
|
||||
@@ -378,7 +379,7 @@ export class ChatPage implements OnInit {
|
||||
|
||||
openMessagesToStartDirectConversation(room: RoomViewModel) {
|
||||
if (window.innerWidth < 701) {
|
||||
// this.openMessagesModal(roomId);
|
||||
this.openMessagesModal(room);
|
||||
}
|
||||
else {
|
||||
this.roomId = null;
|
||||
@@ -460,10 +461,8 @@ export class ChatPage implements OnInit {
|
||||
});
|
||||
|
||||
modal.onDidDismiss().then((Data) => {
|
||||
|
||||
// let data = Data.data
|
||||
// let roomId = data.roomId
|
||||
// this.openMessagesPage(roomId);
|
||||
console.log('Data', Data.data)
|
||||
this.openMessagesToStartDirectConversation(Data.data);
|
||||
|
||||
});
|
||||
|
||||
@@ -497,7 +496,7 @@ export class ChatPage implements OnInit {
|
||||
await modal.present();
|
||||
}
|
||||
|
||||
async openMessagesModal(roomId: any) {
|
||||
async openMessagesModal(room: RoomViewModel) {
|
||||
this.closeAllDesktopComponents();
|
||||
|
||||
//
|
||||
@@ -506,7 +505,7 @@ export class ChatPage implements OnInit {
|
||||
component: MessagesPage,
|
||||
cssClass: 'modal modal-desktop isMessagesChatOpened',
|
||||
componentProps: {
|
||||
roomId: roomId,
|
||||
room: room,
|
||||
},
|
||||
});
|
||||
await modal.present();
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
<ion-list class="header-bottom-contacts" *ngIf="roomMembers$ | async as memberList" >
|
||||
<ng-container *ngFor="let user of memberList; let i = index">
|
||||
<span *ngIf="roomType == RoomTypeEnum.Group"> {{ user.wxFullName }}<ng-container *ngIf="i < memberList.length - 1">, </ng-container> </span>
|
||||
<span > {{ user.wxFullName }}<ng-container *ngIf="i < memberList.length - 1">, </ng-container> </span>
|
||||
</ng-container>
|
||||
</ion-list>
|
||||
|
||||
|
||||
@@ -75,8 +75,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
@Input() _room!: RoomViewModel
|
||||
room!: RoomViewModel
|
||||
|
||||
@Input() roomId: string;
|
||||
@Input() showMessages: string;
|
||||
|
||||
@Output() openNewEventPage: EventEmitter<any> = new EventEmitter<any>();
|
||||
@Output() getDirectMessages: EventEmitter<any> = new EventEmitter<any>();
|
||||
@@ -142,6 +140,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
messageSendSubject: Subscription
|
||||
messageTypingSubject: Subscription
|
||||
messageOnReconnectSubject: Subscription
|
||||
messageOnSetRoomId: Subscription
|
||||
|
||||
messages1: {[key: string]: MessageViewModal[]} = {}
|
||||
MessageAttachmentFileType = MessageAttachmentFileType
|
||||
@@ -155,6 +154,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
date: {[key: string]: Object} = {}
|
||||
handleClickActive = true
|
||||
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
private modalController: ModalController,
|
||||
@@ -188,7 +188,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
|
||||
this.room = {...this._room} as any
|
||||
console.log('message', this.room)
|
||||
|
||||
if(this.room.local == IDBoolean.false) {
|
||||
this.getMessages()
|
||||
this.subscribeToChanges()
|
||||
@@ -204,6 +204,30 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.roomType = e.roomType;
|
||||
}
|
||||
})
|
||||
|
||||
this.messageOnSetRoomId?.unsubscribe()
|
||||
|
||||
if(this.room.local == IDBoolean.true) {
|
||||
this.messageOnSetRoomId = this.chatServiceService.roomDirectOnSetId({$roomId: this.room.$id}).subscribe((data) => {
|
||||
this.messageOnSetRoomId?.unsubscribe()
|
||||
|
||||
this.room = new RoomViewModel(data)
|
||||
|
||||
const hasMyMessage = this.messages1[this.room.$id].find(e => e.sender.wxUserId == SessionStore.user.UserId)
|
||||
|
||||
if(!hasMyMessage) {
|
||||
setTimeout(() => {
|
||||
this.getMessages()
|
||||
}, 500)
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
this.subscribeToChanges()
|
||||
}, 500)
|
||||
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
subscribeToChanges() {
|
||||
@@ -246,9 +270,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
|
||||
updateRoomDetails() {
|
||||
if(!this.room?.local) {
|
||||
this.chatServiceService.getRoomById(this.room.id)
|
||||
}
|
||||
this.chatServiceService.getRoomById(this.room.id)
|
||||
}
|
||||
|
||||
removeBold() {
|
||||
@@ -420,7 +442,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
memberId: SessionStore.user.UserId,
|
||||
messageId: message.id,
|
||||
requestId: '',
|
||||
roomId: this.room.$id
|
||||
roomId: this.room.id
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -506,8 +528,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
const index = this.messages1[this.room.$id].findIndex(e => e?.id === updateMessage.id); // Use triple equals for comparison
|
||||
|
||||
console.log('updateMessage', updateMessage)
|
||||
|
||||
if (index !== -1) { // Check if the item was found
|
||||
this.messages1[this.room.$id][index].info = updateMessage.info
|
||||
this.messages1[this.room.$id][index].message = updateMessage.message
|
||||
@@ -580,6 +600,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
sendTyping() {
|
||||
if(this.room.local == IDBoolean.false) {
|
||||
this.UserTypingRemoteRepositoryService.sendTyping(this.room.id)
|
||||
} else {
|
||||
console.log('dont send')
|
||||
}
|
||||
}
|
||||
|
||||
@@ -768,8 +790,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
if(this.room.id) {
|
||||
message.roomId = this.room.id
|
||||
} else {
|
||||
message.roomId = this.room.$id
|
||||
}
|
||||
|
||||
message.sentAt = new Date().toISOString()
|
||||
@@ -792,7 +812,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
async messageResult(result: Promise<Result<MessageOutPutDataDTO, any>> ) {
|
||||
let message = await result
|
||||
|
||||
console.log('result', message)
|
||||
|
||||
if(message.isOk() && this.room.local == IDBoolean.true) {
|
||||
this.room.local = IDBoolean.false;
|
||||
|
||||
@@ -9,6 +9,7 @@ import { ToastService } from 'src/app/services/toast.service';
|
||||
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
|
||||
import { MessageEntity } from 'src/app/core/chat/entity/message';
|
||||
import { RoomType } from "src/app/core/chat/entity/group";
|
||||
import { RoomViewModel } from '../../../store/model/room';
|
||||
|
||||
@Component({
|
||||
selector: 'app-contacts',
|
||||
@@ -69,12 +70,12 @@ export class ContactsPage implements OnInit {
|
||||
async loadUsers() {
|
||||
|
||||
this.loading = true
|
||||
const getallChatUsers = await this.contactsRepositoryService.getUsers()
|
||||
const getallChatUsers = await this.chatServiceService.getContactList()
|
||||
|
||||
|
||||
if(getallChatUsers.isOk()) {
|
||||
|
||||
this.allChatUsers = getallChatUsers.value.data.result.sort((a,b) => {
|
||||
this.allChatUsers = getallChatUsers.value.sort((a,b) => {
|
||||
if(a.wxFullName < b.wxFullName) {
|
||||
return -1;
|
||||
}
|
||||
@@ -163,22 +164,34 @@ export class ContactsPage implements OnInit {
|
||||
this.modalController.dismiss({});
|
||||
}
|
||||
|
||||
select(user: UserContacts) {
|
||||
async select(user: UserContacts) {
|
||||
|
||||
const message = new MessageEntity();
|
||||
|
||||
message.sender = {
|
||||
userPhoto: '',
|
||||
wxeMail: SessionStore.user.Email,
|
||||
wxFullName: SessionStore.user.FullName,
|
||||
wxUserId: SessionStore.user.UserId
|
||||
// const result = await this.chatServiceService.sendMessage(message, RoomType.Direct)
|
||||
|
||||
const result = await this.chatServiceService.roomCreateLocalDirectMessage({
|
||||
roomName: user.wxFullName,
|
||||
receiverId: user.wxUserId,
|
||||
});
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
const room = await this.chatServiceService.roomGetLocalById({
|
||||
$roomId: result.value
|
||||
})
|
||||
|
||||
if(room.isOk()) {
|
||||
|
||||
console.log('room', room)
|
||||
console.log('result.value', result.value)
|
||||
console.log('receiverId', user.wxUserId)
|
||||
|
||||
this.modalController.dismiss(new RoomViewModel(room.value))
|
||||
}
|
||||
|
||||
} else {
|
||||
//
|
||||
}
|
||||
|
||||
message.receiverId = user.wxUserId
|
||||
|
||||
message.message = 'hello'
|
||||
|
||||
this.chatServiceService.sendMessage(message, RoomType.Group)
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@
|
||||
</div>
|
||||
<div class="middle-container" *ngIf="!showMessageOptions">
|
||||
<div class="middle" >
|
||||
<ion-label *ngIf="roomData$ | async as roomData" class="title">{{ roomData.roomName }}</ion-label>
|
||||
<ion-label class="title">{{ room?.roomName }}</ion-label>
|
||||
<span *ngIf="roomStatus$ | async as roomStatus"><ion-icon *ngIf="roomStatus"
|
||||
class="online" name="ellipse"></ion-icon></span>
|
||||
</div>
|
||||
|
||||
@@ -55,6 +55,7 @@ import { LastMessage } from '../../utils/lastMessage';
|
||||
import { File } from '@awesome-cordova-plugins/file/ngx';
|
||||
import { FileOpener } from '@awesome-cordova-plugins/file-opener/ngx';
|
||||
import { FileSystemMobileService } from 'src/app/infra/file-system/mobile/file-system-mobile.service';
|
||||
import { RoomViewModel } from '../../store/model/room';
|
||||
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
@@ -148,6 +149,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
IMessageType = IMessageType
|
||||
handleClickActive = false
|
||||
|
||||
room!: RoomViewModel
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
private modalController: ModalController,
|
||||
@@ -178,6 +181,10 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
this.roomId = this.navParams.get('roomId');
|
||||
|
||||
this.room = this.navParams.get('room');
|
||||
|
||||
console.log('room', this.room)
|
||||
|
||||
|
||||
this.roomData$ = this.RoomLocalRepository.getRoomByIdLive(this.roomId)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user