mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-18 12:37:53 +00:00
fix chat
This commit is contained in:
@@ -19,7 +19,7 @@ export abstract class IMessageSocketRepository {
|
||||
abstract sendReadAt(data: MessageMarkAsReadInput): Promise<Result<any, any>>
|
||||
abstract sendDelete(data: MessageDeleteInputDTO): Promise<Result<any, any>>
|
||||
|
||||
abstract listenToMessages(): Observable<MessageOutPutDataDTO>
|
||||
abstract listenToMessages(): Observable<SocketMessage<MessageOutPutDataDTO, MessageInputDTO>>
|
||||
abstract listenToDeleteMessages(): Observable<MessageOutPutDataDTO>
|
||||
abstract listenToUpdateMessages(): Observable<MessageOutPutDataDTO>
|
||||
|
||||
|
||||
@@ -20,7 +20,7 @@ export abstract class IDexieRepository<T, R, I = EntityTable<any, any>> {
|
||||
|
||||
abstract find(filter: Partial<T>): Promise<RepositoryResult<R[], T[]>>
|
||||
|
||||
abstract findOne(filter: Partial<T>): Promise<RepositoryResult<T & ILocalModel | undefined, T>>
|
||||
abstract findOne(filter: Partial<T>): Promise<RepositoryResult<T & ILocalModel<T, R, I> | undefined, T>>
|
||||
|
||||
abstract findAll(): Promise<RepositoryResult<T[], T>>
|
||||
|
||||
@@ -29,7 +29,7 @@ export abstract class IDexieRepository<T, R, I = EntityTable<any, any>> {
|
||||
abstract clear(): Promise<Result<any, any>>
|
||||
}
|
||||
|
||||
export abstract class ILocalModel{
|
||||
abstract save()
|
||||
export abstract class ILocalModel<T, R, I = EntityTable<any, any>>{
|
||||
abstract save() : Promise<RepositoryResult<number, T>>
|
||||
abstract delete()
|
||||
}
|
||||
|
||||
@@ -218,9 +218,14 @@ export class DexieRepository<T, R, I = EntityTable<any, any>> implements IDexieR
|
||||
}
|
||||
}
|
||||
|
||||
async findOne(filter: Partial<T>): Promise<RepositoryResult<T & ILocalModel | undefined, T>> {
|
||||
async findOne(filter: Partial<T>): Promise<RepositoryResult<T & ILocalModel<T, R, I> | undefined, T>> {
|
||||
try {
|
||||
const document = await this.table.where(filter).first();
|
||||
|
||||
if(document) {
|
||||
return ok(Object.assign(new LocalModel(this.table, this, this.db), document));
|
||||
}
|
||||
|
||||
return ok(document);
|
||||
} catch (_error) {
|
||||
const error: IDexieError = _error
|
||||
@@ -232,7 +237,7 @@ export class DexieRepository<T, R, I = EntityTable<any, any>> implements IDexieR
|
||||
}
|
||||
}
|
||||
|
||||
async findAll(): Promise<RepositoryResult<(T & ILocalModel)[], T>> {
|
||||
async findAll(): Promise<RepositoryResult<(T & ILocalModel<T, R, I>)[], T>> {
|
||||
try {
|
||||
const documents = await this.table.toArray()
|
||||
return ok(documents);
|
||||
@@ -270,7 +275,7 @@ export class DexieRepository<T, R, I = EntityTable<any, any>> implements IDexieR
|
||||
}
|
||||
}
|
||||
|
||||
export class LocalModel<T, R, I = EntityTable<any, any>> implements ILocalModel {
|
||||
export class LocalModel<T, R, I> implements ILocalModel<T, R, I> {
|
||||
|
||||
constructor(
|
||||
private table: EntityTable<any, any>,
|
||||
@@ -279,13 +284,15 @@ export class LocalModel<T, R, I = EntityTable<any, any>> implements ILocalModel
|
||||
) {}
|
||||
|
||||
save() {
|
||||
const primaryKey = this.db[this.table.name].schema.primKey.name
|
||||
return this.repository.update(primaryKey, this as any)
|
||||
const primaryKey = this.table.schema.primKey.name
|
||||
const idValue = this[primaryKey]
|
||||
return this.repository.update(idValue, this as any)
|
||||
}
|
||||
|
||||
delete() {
|
||||
const primaryKey = this.db[this.table.name].schema.primKey.name
|
||||
return this.repository.delete(primaryKey)
|
||||
const primaryKey = this.table.schema.primKey.name
|
||||
const idValue = this[primaryKey]
|
||||
return this.repository.delete(idValue)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { Plugins } from '@capacitor/core';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { err, Result } from 'neverthrow';
|
||||
import { HubConnection } from '@microsoft/signalr';
|
||||
import { ISignalRInput } from '../type';
|
||||
import { ISignalRInput, ISignalROutput } from '../type';
|
||||
|
||||
const { App } = Plugins;
|
||||
|
||||
@@ -16,7 +16,7 @@ const { App } = Plugins;
|
||||
export class SignalRService {
|
||||
private connection!: SignalRConnection;
|
||||
private connectingSubject: BehaviorSubject<boolean> = new BehaviorSubject<boolean>(null);
|
||||
private sendDataSubject: BehaviorSubject<{method: string, data: any}> = new BehaviorSubject<{method: string, data: any}>(null);
|
||||
private sendDataSubject: Subject<ISignalROutput> = new Subject<ISignalROutput>();
|
||||
|
||||
private deadConnectionBackGround: Subject<any>;
|
||||
|
||||
@@ -94,7 +94,7 @@ export class SignalRService {
|
||||
}
|
||||
|
||||
getData<T>() {
|
||||
return this.sendDataSubject.asObservable() as BehaviorSubject<{method: string, data: T}>
|
||||
return this.sendDataSubject.asObservable()
|
||||
}
|
||||
|
||||
public getConnectionState(): Observable<boolean> {
|
||||
|
||||
@@ -4,12 +4,13 @@ import { ok, Result, err } from 'neverthrow';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { filter, first, map } from 'rxjs/operators';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { ISignalRInput } from '../type';
|
||||
import { ISignalRInput, ISignalROutput } from '../type';
|
||||
import { MessageOutPutDataDTO } from 'src/app/core/chat/repository/dto/messageOutputDTO';
|
||||
import { Subject } from 'rxjs';
|
||||
export interface SocketMessage<T> {
|
||||
export interface SocketMessage<T, I = any> {
|
||||
method: string,
|
||||
data: T
|
||||
data: T,
|
||||
payload: I
|
||||
}
|
||||
|
||||
export enum EnumSocketError {
|
||||
@@ -26,10 +27,11 @@ export class SignalRConnection {
|
||||
private sendLaterSubject: BehaviorSubject<Object> = new BehaviorSubject<Object>(false);
|
||||
private reconnect = true
|
||||
|
||||
private sendDataSubject: BehaviorSubject<{method: string, data: any}> = new BehaviorSubject<{method: string, data: any}>(null);
|
||||
private sendDataSubject: Subject<ISignalROutput> = new Subject<ISignalROutput>();
|
||||
private pendingRequests: Map<string, { resolve: Function; reject: Function }> = new Map();
|
||||
url: string
|
||||
private hasConnectOnce = false
|
||||
private payload = {}
|
||||
|
||||
constructor({url}) {
|
||||
this.url = url
|
||||
@@ -125,6 +127,8 @@ export class SignalRConnection {
|
||||
|
||||
this.hubConnection.invoke(input.method, input.data)
|
||||
|
||||
this.payload[input.data.requestId] = input.data
|
||||
|
||||
this.sendDataSubject.pipe(
|
||||
filter((message) => {
|
||||
return input.data.requestId == message?.data.requestId ||
|
||||
@@ -163,7 +167,8 @@ export class SignalRConnection {
|
||||
this.hubConnection.on(method, (message: any) => {
|
||||
this.sendDataSubject.next({
|
||||
method: method,
|
||||
data: message
|
||||
data: message,
|
||||
payload: this.payload[message?.requestId]
|
||||
})
|
||||
});
|
||||
}
|
||||
|
||||
@@ -8,3 +8,23 @@ const SignalRInputSchema = z.object({
|
||||
})
|
||||
|
||||
export type ISignalRInput = z.infer<typeof SignalRInputSchema>;
|
||||
|
||||
|
||||
|
||||
const SignalROutOutSchema = z.object({
|
||||
method: z.string(),
|
||||
data: z.object({
|
||||
requestId: z.string(),
|
||||
}).catchall(z.unknown()), // Allows any additional properties with unknown values
|
||||
payload: z.object({
|
||||
// requestId: z.string(),
|
||||
}).catchall(z.unknown()),
|
||||
})
|
||||
|
||||
export interface ISignalROutput<T = any> {
|
||||
method: string;
|
||||
data: T;
|
||||
payload: {
|
||||
[key: string]: unknown; // Allows any additional properties with unknown values
|
||||
};
|
||||
}
|
||||
|
||||
+1
-3
@@ -105,9 +105,7 @@ export class MessageSocketRepositoryService implements IMessageSocketRepository
|
||||
|
||||
listenToMessages() {
|
||||
return this.socket.getData().pipe(
|
||||
filter((e) : e is SocketMessage<MessageOutPutDataDTO>=> e?.method == 'ReceiveMessage'
|
||||
),
|
||||
map((e)=> e.data)
|
||||
filter((e) : e is SocketMessage<MessageOutPutDataDTO>=> e?.method == 'ReceiveMessage')
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -41,6 +41,8 @@ export class RoomLocalRepository extends DexieRepository<RoomTable, RoomTable> i
|
||||
// (modifications as Partial<RoomTable>).messages[0].sentAt = oldValue.messages?.[0]?.sentAt
|
||||
// }
|
||||
|
||||
console.log({modifications, oldValue})
|
||||
|
||||
if((modifications as Partial<RoomTable>).id || oldValue.id) {
|
||||
(modifications as Partial<RoomTable>).local = IDBoolean.false
|
||||
} else {
|
||||
|
||||
@@ -28,7 +28,7 @@ import { SocketConnectUseCaseService } from './use-case/socket-connect-use-case.
|
||||
import { MessageMarkAsReadUseCaseService } from './use-case/message/message-mark-as-read-use-case.service'
|
||||
import { MessageMarkAllMessageAsReadByRoomIdInputSchema, MessageMarkAllMessageAsReadByRoomIdService } from './use-case/message/message-mark-all-message-as-read-by-room-id.service'
|
||||
import { GetRoomListUseCaseService } from 'src/app/module/chat/domain/use-case/room/room-get-list-use-case.service';
|
||||
import { filter } from 'rxjs/operators';
|
||||
import { filter, map } from 'rxjs/operators';
|
||||
import { v4 as uuidv4 } from 'uuid'
|
||||
import { IMessage, MessageEntity } from '../../../core/chat/entity/message';
|
||||
import { MessageAttachmentByMessageIdInput, MessageAttachmentByMessageIdUseCase } from './use-case/message/message-attachment-by-message-id.service';
|
||||
@@ -138,6 +138,7 @@ export class ChatServiceService {
|
||||
})
|
||||
|
||||
this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
map(message => message.data),
|
||||
filter((message) => {
|
||||
if(!message?.requestId?.startsWith(InstanceId) == false) {
|
||||
// console.log('exclude my message---')
|
||||
|
||||
@@ -19,6 +19,7 @@ export class RoomLastMessageService {
|
||||
|
||||
listenToIncomingMessage() {
|
||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
map(message => message.data),
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId)),
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
).subscribe(async (message) => {
|
||||
|
||||
@@ -24,6 +24,7 @@ export class ListenMessageByRoomIdNewUseCase {
|
||||
execute(data: ListenMessageByRoomIdNewInputDTO) {
|
||||
|
||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
map(message => message.data),
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId) && message?.roomId == data.roomId),
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
)
|
||||
|
||||
@@ -23,6 +23,7 @@ export class ListenSendMessageUseCase {
|
||||
execute({roomId}: {roomId: string}) {
|
||||
|
||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
map(message => message.data),
|
||||
filter((message) => {
|
||||
|
||||
return message?.requestId?.startsWith(InstanceId) && message?.roomId == roomId
|
||||
|
||||
@@ -39,6 +39,7 @@ export class RoomBoldSyncUseCaseService {
|
||||
*/
|
||||
private listenToIncomingMessage() {
|
||||
return this.MessageSocketRepositoryService.listenToMessages().pipe(
|
||||
map(message => message.data),
|
||||
filter((message) => !message?.requestId?.startsWith(InstanceId)),
|
||||
map(message => Object.assign(new MessageEntity(), message)),
|
||||
filter((message) => !message.meSender())
|
||||
|
||||
@@ -9,6 +9,7 @@ import { RoomEntity } from 'src/app/core/chat/entity/group';
|
||||
import { RoomTable } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
||||
import { IMessageLocalRepository } from 'src/app/core/chat/repository/message/message-local-repository';
|
||||
import { messageListDetermineChanges } from '../../../data/async/list/rooms/messageListChangedetector';
|
||||
import { IDBoolean } from 'src/app/infra/database/dexie/type';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
@@ -80,9 +81,10 @@ export class RoomSetLastMessageService {
|
||||
}
|
||||
|
||||
private listenToIncomingMessage() {
|
||||
return this.messageSocketRepository.listenToMessages().pipe(
|
||||
map(message => Object.assign(new MessageEntity(), message))
|
||||
).subscribe(async (message) => {
|
||||
return this.messageSocketRepository.listenToMessages()
|
||||
.subscribe(async (e) => {
|
||||
|
||||
const message = Object.assign(new MessageEntity(), e.data)
|
||||
if(message?.roomId) {
|
||||
console.log('listenToIncomingMessage', message.roomId)
|
||||
|
||||
@@ -100,6 +102,18 @@ export class RoomSetLastMessageService {
|
||||
} else {
|
||||
console.log('set last message')
|
||||
}
|
||||
} else if (findRoom.isOk() && !findRoom.value && e.payload.receiverId) {
|
||||
// console.log('new room', e)
|
||||
const findLocalDirectRoom = await this.roomLocalRepository.findOne({
|
||||
receiverId: e.payload.receiverId
|
||||
})
|
||||
|
||||
if(findLocalDirectRoom.isOk() && findLocalDirectRoom.value) {
|
||||
findLocalDirectRoom.value.id = message.roomId
|
||||
findLocalDirectRoom.value.local = IDBoolean.false
|
||||
findLocalDirectRoom.value.messages = [message];
|
||||
await findLocalDirectRoom.value.save()
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
@@ -51,6 +51,9 @@ const routes: Routes = [
|
||||
{
|
||||
path: 'edit-message',
|
||||
loadChildren: () => import('./modal/edit-message/edit-message.module').then( m => m.EditMessagePageModule)
|
||||
}, {
|
||||
path: 'chat-popover',
|
||||
loadChildren: () => import('./modal/chat-popover/chat-popover.module').then( m => m.ChatPopoverPageModule)
|
||||
}
|
||||
];
|
||||
|
||||
|
||||
@@ -42,7 +42,7 @@
|
||||
<ion-checkbox disabled checked color="primary"></ion-checkbox>
|
||||
<p class="ma-0">{{user.wxFullName }}</p>
|
||||
<ion-icon name="ellipse"></ion-icon>
|
||||
<button (click)="deleteMember(user)" class="btn-no-color detele-item-icon">
|
||||
<button (click)="deleteMember(user)" *ngIf="SessionStore.user.UserId != user.wxUserId" class="btn-no-color detele-item-icon">
|
||||
<ion-icon color="danger" name="close"></ion-icon>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
<!-- <button (click)="ChatMessageDebuggingPage()">Dev</button> -->
|
||||
<span *ngIf="roomStatus$ | async as roomStatus"><ion-icon *ngIf="roomStatus" class="online" name="ellipse"></ion-icon></span>
|
||||
</div>
|
||||
<div class="right" *ngIf="roomType == RoomTypeEnum.Group">
|
||||
<div class="right" >
|
||||
<button title="Menu" class="btn-no-color" (click)="_openMessagesOptions()" >
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " src="assets/images/theme/blue/icons-menu.svg"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " src="assets/images/theme/gov/icons-menu.svg">
|
||||
|
||||
@@ -209,6 +209,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
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)
|
||||
@@ -223,7 +224,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
|
||||
setTimeout(() => {
|
||||
this.subscribeToChanges()
|
||||
}, 500);
|
||||
}, 500)
|
||||
|
||||
|
||||
})
|
||||
}
|
||||
@@ -827,21 +829,21 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
async messageResult(result: Promise<Result<MessageOutPutDataDTO, any>> ) {
|
||||
let message = await result
|
||||
// let message = await result
|
||||
|
||||
|
||||
if(message.isOk() && this.room.local == IDBoolean.true) {
|
||||
this.room.local = IDBoolean.false;
|
||||
// if(message.isOk() && this.room.local == IDBoolean.true) {
|
||||
// this.room.local = IDBoolean.false;
|
||||
|
||||
console.log('enter')
|
||||
await this.chatServiceService.roomSetLocalToFalseById({
|
||||
$roomId: this.room.$id,
|
||||
roomId: message.value.roomId
|
||||
})
|
||||
// console.log('enter')
|
||||
// // await this.chatServiceService.roomSetLocalToFalseById({
|
||||
// // $roomId: this.room.$id,
|
||||
// // roomId: message.value.roomId
|
||||
// // })
|
||||
|
||||
this.room.id = message.value.roomId
|
||||
this.subscribeToChanges()
|
||||
}
|
||||
// this.room.id = message.value.roomId
|
||||
// //this.subscribeToChanges()
|
||||
// }
|
||||
}
|
||||
|
||||
async sendAudio(fileName) {
|
||||
@@ -1007,7 +1009,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
componentProps: {
|
||||
roomId: this.room.id,
|
||||
members: [],
|
||||
isAdmin: true,
|
||||
isAdmin: this.isAdmin,
|
||||
roomType: this.roomType
|
||||
}
|
||||
});
|
||||
|
||||
@@ -3,7 +3,7 @@
|
||||
<ion-toolbar>
|
||||
<ion-title class="title" *ngIf="roomData$ | async as roomData"> {{ roomData.roomName }}</ion-title>
|
||||
</ion-toolbar>
|
||||
<div class="btn-close d-flex cursor-pointer pr-20 align-center" >
|
||||
<div class="btn-close d-flex cursor-pointer pr-20 align-center" (click)="close()" >
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'default' " class="icon font-30-em"
|
||||
src="assets/images/icons-search-close.svg"></ion-icon>
|
||||
<ion-icon *ngIf="ThemeService.currentTheme == 'gov' " class="icon font-30-em"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { Component, OnInit } from '@angular/core';
|
||||
import { NavParams } from '@ionic/angular';
|
||||
import { ModalController, NavParams } from '@ionic/angular';
|
||||
import { Observable } from 'rxjs';
|
||||
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
|
||||
import { RoomLocalRepository } from 'src/app/module/chat/data/repository/room/room-local-repository.service'
|
||||
@@ -27,6 +27,7 @@ export class RoomInfoPage implements OnInit {
|
||||
private RoomLocalRepository: RoomLocalRepository,
|
||||
private ChatServiceService: ChatServiceService,
|
||||
public ThemeService: ThemeService,
|
||||
private modalController: ModalController,
|
||||
) {
|
||||
this.roomId = this.navParams.get('roomId');
|
||||
}
|
||||
@@ -55,4 +56,8 @@ export class RoomInfoPage implements OnInit {
|
||||
this.roomData$ = this.RoomLocalRepository.getRoomByIdLive(this.roomId)
|
||||
}
|
||||
|
||||
close() {
|
||||
this.modalController.dismiss();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -416,21 +416,21 @@ export class RoomStore {
|
||||
}
|
||||
|
||||
async messageResult(result: Promise<Result<MessageOutPutDataDTO, any>> ) {
|
||||
let message = await result
|
||||
// let message = await result
|
||||
|
||||
|
||||
if(message.isOk() && this.room.local == IDBoolean.true) {
|
||||
this.room.local = IDBoolean.false;
|
||||
// if(message.isOk() && this.room.local == IDBoolean.true) {
|
||||
// this.room.local = IDBoolean.false;
|
||||
|
||||
console.log('enter')
|
||||
await this.chatServiceService.roomSetLocalToFalseById({
|
||||
$roomId: this.room.$id,
|
||||
roomId: message.value.roomId
|
||||
})
|
||||
// console.log('enter')
|
||||
// await this.chatServiceService.roomSetLocalToFalseById({
|
||||
// $roomId: this.room.$id,
|
||||
// roomId: message.value.roomId
|
||||
// })
|
||||
|
||||
this.room.id = message.value.roomId
|
||||
this.subscribeToChanges()
|
||||
}
|
||||
// this.room.id = message.value.roomId
|
||||
// this.subscribeToChanges()
|
||||
// }
|
||||
}
|
||||
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
Reference in New Issue
Block a user