mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
fix chat
This commit is contained in:
@@ -47,7 +47,7 @@
|
||||
<div class="messages height-100 width-100 d-flex flex-column" #scrollMe >
|
||||
|
||||
<div
|
||||
*ngFor="let message of (roomMessage$ | async)" class="messages-list-item-wrapper"
|
||||
*ngFor="let message of messages1[roomId]" class="messages-list-item-wrapper"
|
||||
[ngClass]="{'my-message': message.sender.wxUserId === sessionStore.user.UserId, 'other-message': message.sender.wxUserId !== sessionStore.user.UserId}"
|
||||
>
|
||||
<div class="message-container">
|
||||
@@ -62,7 +62,7 @@
|
||||
<div *ngIf="attachment.fileType == 1">
|
||||
|
||||
<ion-icon src="assets/icon/webtrix.svg" class="file-icon font-25"></ion-icon>
|
||||
<ion-label>{{ attachment.fileName}}</ion-label>
|
||||
<ion-label>{{ attachment.fileName }}</ion-label>
|
||||
<!-- <ion-icon *ngIf="ThemeService.currentTheme == 'default' && attachment.type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/default/icons-download.svg" slot="end"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' && attachment.type != 'webtrix' && !( msg.downloadLoader == true || msg.uploadingFile == true ) " class="icon-download" src="assets/icon/theme/gov/icons-download.svg" slot="end"></ion-icon>
|
||||
<ion-icon *ngIf="( msg.downloadLoader == true || msg.uploadingFile == true )" class="icon-download" src="assets/gif/theme/{{ThemeService.currentTheme}}/Blocks-loader.svg" slot="end"></ion-icon> -->
|
||||
|
||||
@@ -36,16 +36,14 @@ import { sanitize } from "sanitize-filename-ts";
|
||||
import { FilePicker } from '@capawesome/capacitor-file-picker';
|
||||
//======
|
||||
import { Observable as DexieObservable } from 'Dexie';
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { Subscription } from 'rxjs';
|
||||
import { MessageRepositoryService } from 'src/app/module/chat/data/repository/message-respository.service'
|
||||
import { RoomRepositoryService } from 'src/app/module/chat/data/repository/room-repository.service'
|
||||
import { MessageTable } from 'src/app/module/chat/infra/database/dexie/schema/message';
|
||||
import { MessageInputDTO } from 'src/app/module/chat/data/dto/message/messageInputDtO';
|
||||
import { RoomListItemOutPutDTO } from 'src/app/module/chat/data/dto/room/roomListOutputDTO';
|
||||
import { UserTypingServiceRepository } from 'src/app/module/chat/data/repository/user-typing-repository.service';
|
||||
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
|
||||
import { EditMessagePage } from 'src/app/modals/edit-message/edit-message.page';
|
||||
import { tap } from 'rxjs/operators';
|
||||
import { MessageEntity } from 'src/app/module/chat/domain/entity/message';
|
||||
import { MemberTable } from 'src/app/module/chat/infra/database/dexie/schema/members';
|
||||
import { TypingTable } from 'src/app/module/chat/infra/database/dexie/schema/typing';
|
||||
@@ -54,7 +52,6 @@ import { MessageAttachmentFileType, MessageAttachmentSource } from 'src/app/modu
|
||||
import { compressImageBase64 } from 'src/app/utils/imageCompressore';
|
||||
import { FilePickerService } from 'src/app/infra/file-picker/file-picker.service'
|
||||
import { FilePickerMobileService } from 'src/app/infra/file-picker/mobile/file-picker-mobile.service'
|
||||
import { AttachmentsPageRoutingModule } from '../../events/attachments/attachments-routing.module';
|
||||
|
||||
const IMAGE_DIR = 'stored-images';
|
||||
|
||||
@@ -132,6 +129,13 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
emojis: string[] = ['😊', '😂', '❤️', '👍', '😢']; // Add more emojis as needed
|
||||
textField = ''
|
||||
|
||||
|
||||
messageReceiveSubject: Subscription
|
||||
messageDeleteSubject: Subscription
|
||||
messageUpdateSubject: Subscription
|
||||
messageSendSubject: Subscription
|
||||
messages1: {[key: string]: MessageEntity[]} = {}
|
||||
|
||||
constructor(
|
||||
public popoverController: PopoverController,
|
||||
private modalController: ModalController,
|
||||
@@ -168,8 +172,13 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
|
||||
this.roomData$ = this.roomRepositoryService.getItemByIdLive(this.roomId)
|
||||
|
||||
this.roomMessage$ = this.messageRepositoryService.getItemsLive(this.roomId)
|
||||
this.listenToIncomingMessage();
|
||||
this.listenToDeleteMessage();
|
||||
this.listenToUpdateMessage();
|
||||
this.listenToSendMessage()
|
||||
|
||||
|
||||
this.roomMessage$ = this.messageRepositoryService.getItemsLive(this.roomId)
|
||||
this.roomMembers$ = this.roomRepositoryService.getRoomMemberByIdLive(this.roomId) as any
|
||||
this.roomStatus$ = this.roomRepositoryService.getRoomStatus(this.roomId)
|
||||
this.roomRepositoryService.getRoomById(this.roomId)
|
||||
@@ -266,6 +275,96 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
}, 1000)
|
||||
}
|
||||
|
||||
|
||||
|
||||
listenToIncomingMessage() {
|
||||
this.messageReceiveSubject?.unsubscribe();
|
||||
this.messageReceiveSubject = this.chatServiceService.listenToIncomingMessage(this.roomId).subscribe(async (message) => {
|
||||
this.messages1[this.roomId].push(message as MessageEntity)
|
||||
|
||||
if(message.hasAttachment) {
|
||||
|
||||
const result = await this.chatServiceService.getMessageAttachmentByMessageId({
|
||||
$messageId: message.$id,
|
||||
id: message.attachments[0].id
|
||||
})
|
||||
|
||||
if(result.isOk()) {
|
||||
|
||||
message.attachments[0].safeFile = result.value
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
this.scrollToBottomClicked()
|
||||
}, 100)
|
||||
});
|
||||
}
|
||||
|
||||
listenToDeleteMessage() {
|
||||
this.messageDeleteSubject?.unsubscribe();
|
||||
|
||||
this.messageDeleteSubject = this.chatServiceService.listenToDeleteMessage(this.roomId).subscribe((deleteMessage) => {
|
||||
console.log('delete class', deleteMessage);
|
||||
|
||||
const index = this.messages1[this.roomId].findIndex(e => e?.id === deleteMessage.id); // Use triple equals for comparison
|
||||
|
||||
if (index !== -1) { // Check if the item was found
|
||||
console.log('delete ==')
|
||||
this.messages1[this.roomId].splice(index, 1);
|
||||
// console.log('removed index', index);
|
||||
} else {
|
||||
// console.log('message not found');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
listenToUpdateMessage() {
|
||||
this.messageUpdateSubject?.unsubscribe();
|
||||
|
||||
this.messageUpdateSubject = this.chatServiceService.listenToUpdateMessage(this.roomId).subscribe((updateMessage) => {
|
||||
|
||||
const index = this.messages1[this.roomId].findIndex(e => e?.id === updateMessage.id); // Use triple equals for comparison
|
||||
|
||||
if (index !== -1) { // Check if the item was found
|
||||
console.log('update ==')
|
||||
this.messages1[this.roomId][index].message = updateMessage.message
|
||||
this.messages1[this.roomId][index].reactions = updateMessage.reactions
|
||||
} else {
|
||||
// console.log('message not found');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
listenToSendMessage() {
|
||||
this.messageSendSubject?.unsubscribe();
|
||||
|
||||
this.messageSendSubject = this.chatServiceService.listenToSendMessage(this.roomId).subscribe((updateMessage) => {
|
||||
console.log('update message', updateMessage);
|
||||
|
||||
const index = this.messages1[this.roomId].findIndex(e => e?.requestId === updateMessage.requestId); // Use triple equals for comparison
|
||||
|
||||
if (index !== -1) { // Check if the item was found
|
||||
console.log('update ==')
|
||||
|
||||
this.messages1[this.roomId][index].id = updateMessage.id
|
||||
|
||||
let attachmentIndex = 0;
|
||||
|
||||
for(const message of updateMessage.attachments) {
|
||||
console.log('set attachmen id', message)
|
||||
this.messages1[this.roomId][index].attachments[attachmentIndex].id = message.id
|
||||
attachmentIndex++;
|
||||
}
|
||||
|
||||
} else {
|
||||
// console.log('message not found');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
async loadFiles() {
|
||||
|
||||
this.storage.get('fileName').then((fileName) => {
|
||||
|
||||
@@ -11,15 +11,14 @@ import { ClearStoreService } from 'src/app/services/clear-store.service';
|
||||
import { ChangeProfileService } from 'src/app/services/change-profile.service';
|
||||
import { ThemeService } from 'src/app/services/theme.service';
|
||||
import { PermissionService } from 'src/app/services/permission.service';
|
||||
// import { ChatSystemService } from 'src/app/services/chat/chat-system.service';
|
||||
import { ChatService } from 'src/app/services/chat.service';
|
||||
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
|
||||
import { Platform } from '@ionic/angular';
|
||||
import { FirstEnterService } from '../../services/first-enter.service';
|
||||
import { Storage } from '@ionic/storage';
|
||||
import { StorageService } from 'src/app/services/storage.service';
|
||||
import { DeviceService } from 'src/app/services/device.service'
|
||||
import { Cy } from 'cypress/enum'
|
||||
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
|
||||
|
||||
@Component({
|
||||
selector: 'app-login',
|
||||
templateUrl: './login.page.html',
|
||||
@@ -54,11 +53,10 @@ export class LoginPage implements OnInit {
|
||||
// public ChatSystemService: ChatSystemService,
|
||||
private ChatService: ChatService,
|
||||
private platform: Platform,
|
||||
private FirstEnterService: FirstEnterService,
|
||||
private storage: Storage,
|
||||
private storageService: StorageService,
|
||||
private NotificationHolderService: NotificationHolderService,
|
||||
private DeviceService: DeviceService
|
||||
private ChatServiceService: ChatServiceService
|
||||
) { }
|
||||
|
||||
ngOnInit() { }
|
||||
@@ -152,8 +150,9 @@ export class LoginPage implements OnInit {
|
||||
|
||||
}
|
||||
|
||||
this.changeProfileService.runLogin();
|
||||
|
||||
this.changeProfileService.runLogin();
|
||||
this.ChatServiceService.asyncAllRoomMessage()
|
||||
this.getToken();
|
||||
SessionStore.setInativity(true);
|
||||
SessionStore.hasPassLogin = true;
|
||||
@@ -180,6 +179,8 @@ export class LoginPage implements OnInit {
|
||||
this.ChatService.setheader();
|
||||
}
|
||||
this.storageService.remove("Notifications")
|
||||
|
||||
this.ChatServiceService.asyncAllRoomMessage()
|
||||
this.getToken();
|
||||
|
||||
if (!this.platform.is('desktop') && !this.platform.is('mobileweb')) {
|
||||
|
||||
Reference in New Issue
Block a user