load messages

This commit is contained in:
Peter Maquiran
2024-08-15 10:26:20 +01:00
parent ea4ca5c34c
commit 9697290bb7
11 changed files with 102 additions and 73 deletions
+47 -6
View File
@@ -107,6 +107,8 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
downloadFile: any;
files: any[] = [];
@ViewChild('filechooser') fileChooserElementRef: ElementRef;
@ViewChild('array') myInputRef!: ElementRef;
//items: File[] = [];
fileSelected?: Blob;
pdfUrl?: string;
@@ -172,6 +174,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
this.roomData$ = this.roomRepositoryService.getItemByIdLive(this.roomId)
this.getMessages();
this.listenToIncomingMessage();
this.listenToDeleteMessage();
this.listenToUpdateMessage();
@@ -206,15 +209,52 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
})
//this.userTyping$ = this.userTypingMemoryDataSource.select(state => state) as any
this.userTypingServiceRepository.getUserTypingLive().subscribe((e) => {
const arrayNames = e.map(e => e.userName)
this.userTyping$ = e as any
// let a = this.userTypingMemoryDataSource.select(state => state).subscribe((e) => {
// this.userTyping$ = e as any
// })
const uniqueArray = [...new Set(arrayNames)];
(this.myInputRef.nativeElement as HTMLDivElement).innerHTML = '::'+ uniqueArray
})
}
async getMessages() {
// dont remove this line
this.messages1[this.roomId] = []
let messages = await this.messageRepositoryService.getItems(this.roomId)
this.messages1[this.roomId] = []
this.messages1[this.roomId] = messages
this.loadAttachment()
setTimeout(() => {
this.scrollToBottomClicked()
}, 100)
}
async loadAttachment() {
for(const message of this.messages1[this.roomId]) {
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
}
}
}
}
ngOnInit() {
try {
@@ -830,10 +870,11 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
message.attachments = [{
file: compressedImage.value,
file: compressedImage.value.split(',')[1],
fileName: "foto",
source: MessageAttachmentSource.Device,
fileType: MessageAttachmentFileType.Image
fileType: MessageAttachmentFileType.Image,
mimeType: 'image/'+picture.value.format
}]
this.chatServiceService.sendMessage(message)
-22
View File
@@ -11,7 +11,6 @@ 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 { ChatService } from 'src/app/services/chat.service';
import { NotificationHolderService } from 'src/app/store/notification-holder.service';
import { Platform } from '@ionic/angular';
import { Storage } from '@ionic/storage';
@@ -51,7 +50,6 @@ export class LoginPage implements OnInit {
public ThemeService: ThemeService,
public p: PermissionService,
// public ChatSystemService: ChatSystemService,
private ChatService: ChatService,
private platform: Platform,
private storage: Storage,
private storageService: StorageService,
@@ -137,20 +135,6 @@ export class LoginPage implements OnInit {
await this.authService.SetSession(attempt, this.userattempt);
this.changeProfileService.run();
if (attempt.ChatData) {
try {
this.NotificationHolderService.clear()
await this.authService.loginToChatWs();
this.ChatService.setheader()
} catch(error) {
console.log("faild to clear chat")
}
}
this.changeProfileService.runLogin();
this.ChatServiceService.asyncAllRoomMessage()
this.getToken();
@@ -172,12 +156,6 @@ export class LoginPage implements OnInit {
await this.authService.SetSession(attempt, this.userattempt);
this.changeProfileService.run();
if (attempt.ChatData) {
await this.authService.loginToChatWs();
this.ChatService.setheader();
}
this.storageService.remove("Notifications")
this.ChatServiceService.asyncAllRoomMessage()