remove old methods

This commit is contained in:
Peter Maquiran
2024-06-10 17:04:04 +01:00
parent bf1457417d
commit 3dc6c0e249
6 changed files with 158 additions and 128 deletions
@@ -0,0 +1,30 @@
import { TableMemberList } from "../../data-source/room/rooom-local-data-source.service";
import { RoomByIdMemberItemOutputDTO } from "../../dto/room/roomByIdOutputDTO";
export function roomMemberListDetermineChanges(serverRooms: RoomByIdMemberItemOutputDTO[], localRooms: TableMemberList[], roomId: string) {
const PServerRooms: (RoomByIdMemberItemOutputDTO & {$roomIdUserId: string}[]) = serverRooms.map( e=> {
return {
...e,
$roomIdUserId: roomId + e.user.wxUserId
}
})
const serverRoomMap = new Map(PServerRooms.map(room => [room.$roomIdUserId, room]));
const localRoomMap = new Map(localRooms.map(room => [room.$roomIdUserId, room]));
const membersToInsert = serverRooms.filter(room => !localRoomMap.has(room.id));
const membersToUpdate = serverRooms.filter(room => {
const localRoom = localRoomMap.get(room.id);
return localRoom && (
room.user.wxUserId !== localRoom.user.wxUserId ||
room.user.userPhoto !== localRoom.user.userPhoto ||
room.joinAt !== localRoom.joinAt
)
});
const membersToDelete = localRooms.filter(room => !serverRoomMap.has(room.id));
return { membersToInsert, membersToUpdate, membersToDelete };
}
@@ -3,8 +3,6 @@ import { RoomListItemOutPutDTO, RoomListOutPutDTO } from '../../dto/room/roomLis
import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie'; import { Dexie, EntityTable, liveQuery, Observable } from 'Dexie';
import { err, ok } from 'neverthrow'; import { err, ok } from 'neverthrow';
import { z } from 'zod'; import { z } from 'zod';
import { UserList } from '../../../contacts/data-source/contacts-data-source.service';
const tableSchema = z.object({ const tableSchema = z.object({
id: z.string(), id: z.string(),
@@ -105,6 +103,7 @@ export class RoomLocalDataSourceService {
return await roomDataSource.room.toArray() return await roomDataSource.room.toArray()
} }
getItemsLive(): Observable<RoomListOutPutDTO[]> { getItemsLive(): Observable<RoomListOutPutDTO[]> {
return liveQuery(() => roomDataSource.room.toArray()) as any; return liveQuery(() => roomDataSource.room.toArray()) as any;
} }
@@ -28,4 +28,5 @@ export const RoomByIdOutputDTOSchema = z.object({
}); });
export type RoomByIdMemberItemOutputDTO = z.infer<typeof MemberSchema>
export type RoomByIdOutputDTO = z.infer<typeof RoomByIdOutputDTOSchema> export type RoomByIdOutputDTO = z.infer<typeof RoomByIdOutputDTOSchema>
@@ -1,7 +1,6 @@
import { Injectable } from '@angular/core'; import { Injectable } from '@angular/core';
import { MessageRemoteDataSourceService } from '../data-source/message/message-remote-data-source.service'; import { MessageRemoteDataSourceService } from '../data-source/message/message-remote-data-source.service';
import { MessageLiveDataSourceService } from '../data-source/message/message-live-data-source.service'; import { MessageLiveDataSourceService } from '../data-source/message/message-live-data-source.service';
import { MessageListInputDTO } from '../dto/message/messageListInputDTO';
import { MessageInputDTO } from '../dto/message/messageInputDtO'; import { MessageInputDTO } from '../dto/message/messageInputDtO';
import { MessageLocalDataSourceService, TableMessage } from '../data-source/message/message-local-data-source.service'; import { MessageLocalDataSourceService, TableMessage } from '../data-source/message/message-local-data-source.service';
import { SessionStore } from 'src/app/store/session.service'; import { SessionStore } from 'src/app/store/session.service';
@@ -8,6 +8,7 @@ import { RoomLocalDataSourceService } from '../data-source/room/rooom-local-data
import { RoomByIdInputDTO } from '../dto/room/roomByIdInputDTO'; import { RoomByIdInputDTO } from '../dto/room/roomByIdInputDTO';
import { roomListDetermineChanges } from '../async/rooms/roomListChangeDetector'; import { roomListDetermineChanges } from '../async/rooms/roomListChangeDetector';
import { UserRemoveListInputDTO } from '../dto/room/userRemoveListInputDTO'; import { UserRemoveListInputDTO } from '../dto/room/userRemoveListInputDTO';
import { roomMemberListDetermineChanges } from '../async/rooms/roomMembersChangeDetector';
@Injectable({ @Injectable({
providedIn: 'root' providedIn: 'root'
@@ -45,6 +46,10 @@ export class RoomRepositoryService {
const result = await this.roomRemoteDataSourceService.getRoom(id) const result = await this.roomRemoteDataSourceService.getRoom(id)
if(result.isOk()) { if(result.isOk()) {
const localList = await this.roomLocalDataSourceService.getRoomMemberById(id)
const { membersToInsert, membersToUpdate, membersToDelete } = roomMemberListDetermineChanges(result.value.data.members, localList, id)
for (const user of result.value.data.members) { for (const user of result.value.data.members) {
this.roomLocalDataSourceService.addMember({...user, roomId:id}) this.roomLocalDataSourceService.addMember({...user, roomId:id})
} }
+121 -125
View File
@@ -14,7 +14,6 @@ import { ViewDocumentPage } from 'src/app/modals/view-document/view-document.pag
import { ThemeService } from 'src/app/services/theme.service'; import { ThemeService } from 'src/app/services/theme.service';
import { ViewEventPage } from 'src/app/modals/view-event/view-event.page'; import { ViewEventPage } from 'src/app/modals/view-event/view-event.page';
import { Storage } from '@ionic/storage'; import { Storage } from '@ionic/storage';
import { ChatSystemService } from 'src/app/services/chat/chat-system.service'
import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service' import { RochetChatConnectorService } from 'src/app/services/chat/rochet-chat-connector.service'
import { MessageService } from 'src/app/services/chat/message.service'; import { MessageService } from 'src/app/services/chat/message.service';
import { CameraService } from 'src/app/services/camera.service'; import { CameraService } from 'src/app/services/camera.service';
@@ -35,11 +34,10 @@ import { ChatMessageDebuggingPage } from 'src/app/shared/popover/chat-message-de
import { PermissionService } from 'src/app/services/permission.service'; import { PermissionService } from 'src/app/services/permission.service';
import { FileValidatorService } from "src/app/services/file/file-validator.service" import { FileValidatorService } from "src/app/services/file/file-validator.service"
import { RoomRepositoryService } from 'src/app/services/Repositorys/chat/repository/room-repository.service'; import { RoomRepositoryService } from 'src/app/services/Repositorys/chat/repository/room-repository.service';
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from 'src/app/services/Repositorys/chat/dto/room/roomListOutputDTO'; import { RoomListItemOutPutDTO } from 'src/app/services/Repositorys/chat/dto/room/roomListOutputDTO';
import { MessageRepositoryService } from 'src/app/services/Repositorys/chat/repository/message-respository.service'; import { MessageRepositoryService } from 'src/app/services/Repositorys/chat/repository/message-respository.service';
import { MessageInputDTO } from 'src/app/services/Repositorys/chat/dto/message/messageInputDtO'; import { MessageInputDTO } from 'src/app/services/Repositorys/chat/dto/message/messageInputDtO';
import { TableMemberList } from 'src/app/services/Repositorys/chat/data-source/room/rooom-local-data-source.service'; import { TableMemberList } from 'src/app/services/Repositorys/chat/data-source/room/rooom-local-data-source.service';
import { Observable } from 'rxjs';
import { TableMessage } from 'src/app/services/Repositorys/chat/data-source/message/message-local-data-source.service'; import { TableMessage } from 'src/app/services/Repositorys/chat/data-source/message/message-local-data-source.service';
import { ChatPopoverPage } from '../../popover/chat-popover/chat-popover.page'; import { ChatPopoverPage } from '../../popover/chat-popover/chat-popover.page';
import { Observable as DexieObservable } from 'Dexie'; import { Observable as DexieObservable } from 'Dexie';
@@ -125,7 +123,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
public popoverController: PopoverController, public popoverController: PopoverController,
private modalController: ModalController, private modalController: ModalController,
/* private navParams: NavParams, */ /* private navParams: NavParams, */
private chatService: ChatService,
private animationController: AnimationController, private animationController: AnimationController,
private toastService: ToastService, private toastService: ToastService,
private timeService: TimeService, private timeService: TimeService,
@@ -133,7 +130,6 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
private gestureController: GestureController, private gestureController: GestureController,
public ThemeService: ThemeService, public ThemeService: ThemeService,
private storage: Storage, private storage: Storage,
public ChatSystemService: ChatSystemService,
public RochetChatConnectorService: RochetChatConnectorService, public RochetChatConnectorService: RochetChatConnectorService,
private CameraService: CameraService, private CameraService: CameraService,
private sanitiser: DomSanitizer, private sanitiser: DomSanitizer,
@@ -186,7 +182,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
ngOnInit() { ngOnInit() {
this.ChatSystemService.getAllRooms(); // this.ChatSystemService.getAllRooms();
// this.chatService.refreshtoken(); // this.chatService.refreshtoken();
this.scrollToBottom(); this.scrollToBottom();
this.getChatMembers(); this.getChatMembers();
@@ -451,22 +447,22 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
this.ChatSystemService.getDmRoom(roomId).send({ // this.ChatSystemService.getDmRoom(roomId).send({
file: { // file: {
"type": "application/audio", // "type": "application/audio",
"msDuration": audioFile.value.msDuration, // "msDuration": audioFile.value.msDuration,
"mimeType": audioFile.value.mimeType, // "mimeType": audioFile.value.mimeType,
}, // },
attachments: [{ // attachments: [{
"title": fileName, // "title": fileName,
"title_link_download": true, // "title_link_download": true,
"type": "audio" // "type": "audio"
}], // }],
temporaryData: formData, // temporaryData: formData,
attachmentsModelData: { // attachmentsModelData: {
fileBase64: encodedData, // fileBase64: encodedData,
} // }
}) // })
}); });
this.deleteRecording(); this.deleteRecording();
@@ -474,7 +470,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
deleteMessage(msgId: string, msg: MessageService) { deleteMessage(msgId: string, msg: MessageService) {
this.ChatSystemService.getDmRoom(this.roomId).sendDeleteRequest(msgId) // this.ChatSystemService.getDmRoom(this.roomId).sendDeleteRequest(msgId)
} }
@@ -537,7 +533,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
// this.showLoader = false; // this.showLoader = false;
// }); // });
this.dmUsers = this.ChatSystemService.getDmRoom(this.roomId).membersExcludeMe // this.dmUsers = this.ChatSystemService.getDmRoom(this.roomId).membersExcludeMe
} }
async openMessagesOptions(ev: any) { async openMessagesOptions(ev: any) {
@@ -632,7 +628,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.getRoomInfo(); this.getRoomInfo();
this.closeAllDesktopComponents.emit(); this.closeAllDesktopComponents.emit();
this.showEmptyContainer.emit(); this.showEmptyContainer.emit();
this.ChatSystemService.hidingRoom(this.roomId).catch((error) => console.error(error)); // this.ChatSystemService.hidingRoom(this.roomId).catch((error) => console.error(error));
} }
else if (res.data == 'delete') { else if (res.data == 'delete') {
this.closeAllDesktopComponents.emit(); this.closeAllDesktopComponents.emit();
@@ -713,23 +709,23 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
this.ChatSystemService.getDmRoom(roomId).send({ // this.ChatSystemService.getDmRoom(roomId).send({
file: { // file: {
"type": "application/img", // "type": "application/img",
"guid": '', // "guid": '',
}, // },
temporaryData: formData, // temporaryData: formData,
attachments: [{ // attachments: [{
"title": file.path, // "title": file.path,
// "image_url": "", // // "image_url": "",
//"image_url": 'data:image/jpeg;base64,' + file.base64String, // //"image_url": 'data:image/jpeg;base64,' + file.base64String,
"text": "description", // "text": "description",
"title_link_download": false, // "title_link_download": false,
}], // }],
attachmentsModelData: { // attachmentsModelData: {
fileBase64: base64, // fileBase64: base64,
} // }
}) // })
} }
@@ -755,21 +751,21 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
formData.append("blobFile", blob); formData.append("blobFile", blob);
this.ChatSystemService.getDmRoom(roomId).send({ // this.ChatSystemService.getDmRoom(roomId).send({
file: { // file: {
"type": "application/img", // "type": "application/img",
"guid": '' // "guid": ''
}, // },
temporaryData: formData, // temporaryData: formData,
attachments: [{ // attachments: [{
"title": "file.jpg", // "title": "file.jpg",
"text": "description", // "text": "description",
"title_link_download": false, // "title_link_download": false,
}], // }],
attachmentsModelData: { // attachmentsModelData: {
fileBase64: imageBase64, // fileBase64: imageBase64,
} // }
}) // })
} }
@@ -799,24 +795,24 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
if (data.selected) { if (data.selected) {
this.ChatSystemService.getDmRoom(roomId).send({ // this.ChatSystemService.getDmRoom(roomId).send({
file: { // file: {
"name": res.data.selected.Assunto, // "name": res.data.selected.Assunto,
"type": "application/webtrix", // "type": "application/webtrix",
"ApplicationId": res.data.selected.ApplicationType, // "ApplicationId": res.data.selected.ApplicationType,
"DocId": res.data.selected.Id, // "DocId": res.data.selected.Id,
"Assunto": res.data.selected.Assunto, // "Assunto": res.data.selected.Assunto,
}, // },
temporaryData: res, // temporaryData: res,
attachments: [{ // attachments: [{
"title": res.data.selected.Assunto, // "title": res.data.selected.Assunto,
"description": res.data.selected.DocTypeDesc, // "description": res.data.selected.DocTypeDesc,
"title_link_download": true, // "title_link_download": true,
"type": "webtrix", // "type": "webtrix",
"text": res.data.selected.DocTypeDesc, // "text": res.data.selected.DocTypeDesc,
"thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png", // "thumb_url": "https://static.ichimura.ed.jp/uploads/2017/10/pdf-icon.png",
}], // }],
}) // })
} }
@@ -859,22 +855,22 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
const formData = new FormData(); const formData = new FormData();
formData.append("blobFile", blob); formData.append("blobFile", blob);
this.ChatSystemService.getDmRoom(roomId).send({ // this.ChatSystemService.getDmRoom(roomId).send({
file: { // file: {
"type": "application/img", // "type": "application/img",
"guid": '' // "guid": ''
}, // },
temporaryData: formData, // temporaryData: formData,
attachments: [{ // attachments: [{
"title": file.path, // "title": file.path,
//"image_url": 'data:image/jpeg;base64,' + file.base64String, // //"image_url": 'data:image/jpeg;base64,' + file.base64String,
"text": "description", // "text": "description",
"title_link_download": false, // "title_link_download": false,
}], // }],
attachmentsModelData: { // attachmentsModelData: {
fileBase64: base64, // fileBase64: base64,
} // }
}) // })
} }
@@ -930,23 +926,23 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
this.ChatSystemService.getDmRoom(roomId).send({ // this.ChatSystemService.getDmRoom(roomId).send({
file: { // file: {
"type": file.type, // "type": file.type,
"guid": '', // "guid": '',
}, // },
attachments: [{ // attachments: [{
"title": file.name, // "title": file.name,
"name": file.name, // "name": file.name,
//"image_url": res, // //"image_url": res,
// "text": "description", // // "text": "description",
"title_link_download": false, // "title_link_download": false,
}], // }],
temporaryData: formData, // temporaryData: formData,
attachmentsModelData: { // attachmentsModelData: {
fileBase64: fileBase64, // fileBase64: fileBase64,
} // }
}) // })
} else { } else {
this.toastService._badRequest("Ficheiro inválido") this.toastService._badRequest("Ficheiro inválido")
} }
@@ -1257,27 +1253,27 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
} }
async getRoomInfo() { async getRoomInfo() {
let room = await this.chatService.getRoomInfo(this.roomId).toPromise(); // let room = await this.chatService.getRoomInfo(this.roomId).toPromise();
this.room = room['room']; // this.room = room['room'];
if (this.room.name) { // if (this.room.name) {
try { // try {
this.roomName = this.room.name.split('-').join(' '); // this.roomName = this.room.name.split('-').join(' ');
} catch (error) { // } catch (error) {
this.roomName = this.room.name; // this.roomName = this.room.name;
} // }
} // }
if (SessionStore.user.ChatData.data.userId == this.room.u._id) { // if (SessionStore.user.ChatData.data.userId == this.room.u._id) {
this.isAdmin = true // this.isAdmin = true
} else { // } else {
this.isAdmin = false // this.isAdmin = false
} // }
if (this.room.customFields.countDownDate) { // if (this.room.customFields.countDownDate) {
this.roomCountDownDate = this.room.customFields.countDownDate; // this.roomCountDownDate = this.room.customFields.countDownDate;
} // }
} }