fix chat ui details

This commit is contained in:
Peter Maquiran
2024-09-09 10:28:53 +01:00
parent e7887d4e5a
commit 96daa01f94
20 changed files with 236 additions and 108 deletions
+33
View File
@@ -0,0 +1,33 @@
import { z } from "zod";
export const MemberEntitySchema = z.object({
$roomIdUserId: z.string().optional(),
id: z.string().optional(), // useless
roomId: z.string(),
wxUserId: z.number(),
wxFullName: z.string(),
wxeMail: z.string(),
userPhoto: z.string().nullable(),
joinAt: z.string(),
status: z.string().optional(), // useless
isAdmin: z.boolean()
})
export type IMember = z.infer<typeof MemberEntitySchema>
export class MemberEntity implements IMember {
id: typeof MemberEntitySchema._type.id
roomId: typeof MemberEntitySchema._type.roomId
wxUserId: typeof MemberEntitySchema._type.wxUserId
wxFullName: typeof MemberEntitySchema._type.wxFullName
wxeMail: typeof MemberEntitySchema._type.wxeMail
userPhoto: typeof MemberEntitySchema._type.userPhoto
joinAt: typeof MemberEntitySchema._type.joinAt
status: typeof MemberEntitySchema._type.status
isAdmin: typeof MemberEntitySchema._type.isAdmin
hasPhoto() {
return typeof this.userPhoto == 'string'
}
}
@@ -0,0 +1,13 @@
import { HttpResult, IHttPReturn } from "src/app/infra/http/type"
import { UserPhotoGetByIdInputSchema } from "src/app/module/chat/domain/use-case/user-photo/user-photo-get-by-id-use-case.service"
import { z } from "zod"
export const IGetUserPhotoByAttachmentIdInputSchema = z.object({
attachmentId: z.string(),
})
export type IGetUserPhotoByAttachmentId = z.infer<typeof IGetUserPhotoByAttachmentIdInputSchema>
export abstract class IUserPhotoRemoteRepository {
abstract getUserPhotoByAttachmentId(input: IGetUserPhotoByAttachmentId): IHttPReturn<string>
}
@@ -2,9 +2,9 @@ import { EntityTable } from 'Dexie';
import { z } from 'zod';
export const UserPhotoTableSchema = z.object({
wxUserId: z.string(),
blob: z.instanceof(Blob),
attachmentId: z.string()
wxUserId: z.number(),
file: z.string(),
attachmentId: z.string().nullable()
})
export type UserPhotoTable = z.infer<typeof UserPhotoTableSchema>
+1 -1
View File
@@ -36,7 +36,7 @@ chatDatabase.version(1).stores({
attachment: AttachmentTableColumn,
distribution: DistributionTableColumn,
bold:BoldTableColumn,
userPhotoTable: UserPhotoTableColumn
userPhoto: UserPhotoTableColumn
});
chatDatabase.message.mapToClass(MessageEntity)
+4 -1
View File
@@ -1,4 +1,5 @@
import { HttpHeaders, HttpParams } from '@angular/common/http';
import { HttpErrorResponse, HttpHeaders, HttpParams } from '@angular/common/http';
import { Result } from 'neverthrow';
export interface Options {
headers?: HttpHeaders
@@ -12,3 +13,5 @@ export interface HttpResult<T> {
url: string;
method: string
}
export type IHttPReturn<T> = Promise<Result<HttpResult<T>, HttpErrorResponse>>
+14
View File
@@ -37,6 +37,10 @@ import { DistributionService } from './domain/service/distribution.service'
import { BoldLocalRepository } from './data/repository/bold/bold-local-repository';
import { IBoldLocalRepository } from 'src/app/core/chat/repository/bold/bold-local-repository';
import { RoomLastMessageService } from 'src/app/module/chat/domain/service/room-last-message.service'
import { IUserPhotoLocalRepository } from 'src/app/core/chat/repository/user-photo/user-photo-local-repository';
import { UserPhotoLocalRepository } from './data/repository/user-foto/user-photo-local-repository.service';
import { IUserPhotoRemoteRepository } from 'src/app/core/chat/repository/user-photo/user-photo-remote-repository';
import { UserPhotoRemoteRepositoryService } from './data/repository/user-foto/user-photo-remote-repository.service';
@NgModule({
imports: [HttpModule],
providers: [
@@ -100,6 +104,16 @@ import { RoomLastMessageService } from 'src/app/module/chat/domain/service/room-
{
provide: IBoldLocalRepository,
useClass: BoldLocalRepository
},
// user-photo
{
provide: IUserPhotoLocalRepository,
useClass: UserPhotoLocalRepository
},
//
{
provide: IUserPhotoRemoteRepository,
useClass: UserPhotoRemoteRepositoryService
}
],
declarations: [],
@@ -0,0 +1,15 @@
import { Injectable } from '@angular/core';
import Dexie, { PromiseExtended } from 'Dexie';
import { IUserPhotoLocalRepository } from 'src/app/core/chat/repository/user-photo/user-photo-local-repository';
import { UserPhotoTable, UserPhotoTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/user-foto';
import { chatDatabase } from 'src/app/infra/database/dexie/service';
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
@Injectable({
providedIn: 'root'
})
export class UserPhotoLocalRepository extends DexieRepository<UserPhotoTable, UserPhotoTable> implements IUserPhotoLocalRepository {
constructor() {
super(chatDatabase.userPhoto, UserPhotoTableSchema)
}
}
@@ -1,16 +0,0 @@
import { TestBed } from '@angular/core/testing';
import { UserPhotoRemoteRepositoryService } from './user-photo-remote-repository.service';
describe('UserPhotoRemoteRepositoryService', () => {
let service: UserPhotoRemoteRepositoryService;
beforeEach(() => {
TestBed.configureTestingModule({});
service = TestBed.inject(UserPhotoRemoteRepositoryService);
});
it('should be created', () => {
expect(service).toBeTruthy();
});
});
@@ -1,15 +1,24 @@
import { Injectable } from '@angular/core';
import Dexie, { PromiseExtended } from 'Dexie';
import { IUserPhotoLocalRepository } from 'src/app/core/chat/repository/user-photo/user-photo-local-repository';
import { UserPhotoTable, UserPhotoTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/user-foto';
import { chatDatabase } from 'src/app/infra/database/dexie/service';
import { DexieRepository } from 'src/app/infra/repository/dexie/dexie-repository.service';
import { IGetUserPhotoByAttachmentId, IGetUserPhotoByAttachmentIdInputSchema, IUserPhotoRemoteRepository } from 'src/app/core/chat/repository/user-photo/user-photo-remote-repository';
import { HttpAdapter } from 'src/app/infra/http/adapter';
import { SafeValidateSchema } from 'src/app/services/decorators/validate-schema.decorator';
import { environment } from 'src/environments/environment';
import { z } from 'zod';
@Injectable({
providedIn: 'root'
})
export class UserPhotoRemoteRepository extends DexieRepository<UserPhotoTable, UserPhotoTable> implements IUserPhotoLocalRepository {
constructor() {
super(chatDatabase.userPhoto, UserPhotoTableSchema)
export class UserPhotoRemoteRepositoryService implements IUserPhotoRemoteRepository{
constructor(
private http: HttpAdapter
) { }
@SafeValidateSchema(IGetUserPhotoByAttachmentIdInputSchema, 'GET/UserAuthentication/GetPhoto?UserPhoto=')
getUserPhotoByAttachmentId(input: IGetUserPhotoByAttachmentId) {
const geturl = environment.apiURL + `UserAuthentication/GetPhoto?UserPhoto=${input.attachmentId}`;
return this.http.get<string>(geturl)
}
}
@@ -41,7 +41,8 @@ import { MessageMarkAsReadInput } from "src/app/module/chat/domain/use-case/mess
import { BoldRemoveByRoomIdInput, BoldRemoveByRoomIdService } from 'src/app/module/chat/domain/use-case/bold/bold-remove-by-room-id.service';
import { MemberListHttpSyncUseCase } from 'src/app/module/chat/domain/use-case/member/member-list-http-sync-use-case.ts.service'
import { RoomBoldSyncUseCaseService } from 'src/app/module/chat/domain/use-case/room/room-bold-sync-use-case.service'
import { RoomSetLastMessageService } from 'src/app/module/chat/domain/use-case/room/room-set-last-message.service'
import { RoomSetLastMessageService } from 'src/app/module/chat/domain/use-case/room/room-set-last-message.service';
import { IUserPhotoGetByIdInput, UserPhotoGetByIdUseCase } from 'src/app/module/chat/domain/use-case/user-photo/user-photo-get-by-id-use-case.service'
export const InstanceId = uuidv4();
@Injectable({
@@ -84,7 +85,8 @@ export class ChatServiceService {
private BoldRemoveByRoomIdService: BoldRemoveByRoomIdService,
private MemberListHttpSyncUseCase: MemberListHttpSyncUseCase, // dont remove
private RoomBoldSyncUseCaseService: RoomBoldSyncUseCaseService, // dont remove
private RoomSetLastMessageService: RoomSetLastMessageService // dont remove
private RoomSetLastMessageService: RoomSetLastMessageService, // dont remove
private UserPhotoGetByIdUseCase: UserPhotoGetByIdUseCase
) {
this.MessageSocketRepositoryService.listenToDeleteMessages()
.pipe()
@@ -155,6 +157,10 @@ export class ChatServiceService {
return this.MessageDeleteLiveUseCaseService.execute(params)
}
getUserPhoto(input: IUserPhotoGetByIdInput) {
return this.UserPhotoGetByIdUseCase.execute(input)
}
reactToMessage(input: MessageReactionInput) {
return this.MessageReactionUseCaseService.execute(input);
}
@@ -0,0 +1,49 @@
import { Injectable } from '@angular/core';
import { IUserPhotoLocalRepository } from 'src/app/core/chat/repository/user-photo/user-photo-local-repository';
import { IUserPhotoRemoteRepository } from 'src/app/core/chat/repository/user-photo/user-photo-remote-repository';
import { UserPhotoTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/user-foto';
import { z } from 'zod';
export const UserPhotoGetByIdInputSchema = UserPhotoTableSchema.pick({
attachmentId: true,
wxUserId: true,
})
export type IUserPhotoGetByIdInput = z.infer<typeof UserPhotoGetByIdInputSchema>
@Injectable({
providedIn: 'root'
})
export class UserPhotoGetByIdUseCase {
constructor(
private userPhotoLocalRepository: IUserPhotoLocalRepository,
private userPhotoRemoteRepository: IUserPhotoRemoteRepository
) { }
async execute(input: IUserPhotoGetByIdInput) {
const result = await this.userPhotoLocalRepository.findOne({wxUserId: input.wxUserId})
if(result.isOk() && result.value) {
return result.map(e => {
return e.file
})
} else if(result.isOk() && !result.value) {
const remoteResult = await this.userPhotoRemoteRepository.getUserPhotoByAttachmentId({attachmentId: input.attachmentId})
if(remoteResult.isOk()) {
this.userPhotoLocalRepository.insert({
wxUserId: input.wxUserId,
file: remoteResult.value.data,
attachmentId: input.attachmentId
})
}
return remoteResult.map(e => {
return e.data
})
}
}
}
-20
View File
@@ -71,9 +71,6 @@ export class ChatPage implements OnInit {
RoomSelected!: RoomViewModel;
private worker: SharedWorker;
private port: MessagePort;
constructor(
private modalController: ModalController,
private timeService: TimeService,
@@ -105,25 +102,9 @@ export class ChatPage implements OnInit {
this.boldTable = distributionObject
})
this.worker = new SharedWorker('shared-worker.js');
// this.worker.port.start()
this.port = this.worker.port;
this.port.onmessage = (event) => {
console.log('Received from worker:', event.data);
}
//this.port.postMessage('hello');
}
// Method to update the room list
// updateRoomList(newRoomList: { id: string, name: string }[]): void {
// this.roomListSubject.next(newRoomList);
// }
// Fetch all items using useLiveQuery
updatemessage(sortedRooms) {
this.rooms = sortedRooms
@@ -358,7 +339,6 @@ export class ChatPage implements OnInit {
openMessagesPage(roomId) {
this.port.postMessage('hello');
// this.chatService.refreshtoken();
this.roomId = roomId;
this.RoomSelected = this.rooms.filter(e => e.id == roomId)[0]
@@ -9,7 +9,7 @@
<span *ngIf="roomStatus$ | async as roomStatus"><ion-icon *ngIf="roomStatus" class="online" name="ellipse"></ion-icon></span>
</div>
<div class="right">
<button title="Menu" class="btn-no-color" (click)="_openMessagesOptions()" >
<button title="Menu" class="btn-no-color" (click)="_openMessagesOptions()" *ngIf="roomType == RoomTypeEnum.Group">
<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">
</ion-icon>
@@ -186,46 +186,8 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
) {
// update
this.checkAudioPermission()
//this.sendChunks()
// this.worker = new SharedWorker('shared-worker.js');
// this.port = this.worker.port;
// this.port.onmessage = (event) => {
// console.log('Received from worker:', event.data);
// }
// this.port.postMessage('hello');
}
// sendChunks() {
// const base64String = 'data:video/mp4;base64,AAAAHGZ0eXBtcDQyAAAAAGlzb21tcDQyAAACAGlzb21tcDQyaXNvbXJtZGEAAAAHZnJlZS1ybWRhAAAAGXZmY2MtbGF2ZjU4LmEyLTkyLm12NTZjAGZyZWUtcm1kYQAAAAVyZWZsYXYAAABWZGF0YTqBgIAAAAs9AAABM/f/+6mpg6z+d0+j5adJHVD+lk75p0ntRFEyTlHT/GRYbDg4ODhISEhAQK/jMCAxCBAIEwMmJgAABNmY2MtbGF2ZjU4LmEyLTkyLm12NTZjAGZyZWUtcm1kYQAAAAVyZWZsYXY=';
// const chunkSize = Math.ceil(base64String.length / 2);
// const chunks = [
// { chunk: base64String.slice(0, chunkSize), index: 0 },
// { chunk: base64String.slice(chunkSize), index: 1 }
// ];
// const identifier = uuidv4(); // You can set a unique identifier for the file
// const totalChunks = chunks.length;
// chunks.forEach((chunkData) => {
// const payload = {
// chunk: chunkData.chunk,
// identifier,
// index: chunkData.index,
// totalChunks
// };
// this.http.post('https://gdapi-dev.dyndns.info/stage/api/v2/File/UploadBase64Chunks', payload)
// .subscribe(response => {
// console.log('Chunk sent successfully:', response);
// }, error => {
// console.error('Error sending chunk:', error);
// });
// });
// }
ngOnChanges(changes: SimpleChanges): void {
@@ -51,7 +51,7 @@
<div class="messages height-100 width-100 d-flex flex-column" #scrollMe >
<div
*ngFor="let message of messages1[roomId]" class="messages-list-item-wrapper"
*ngFor="let message of messages1[roomId]; let messageIndex = index" class="messages-list-item-wrapper"
[ngClass]="{
'info-meeting': message.messageType == IMessageType.information && !message.ballon,
'info-ballon': message.ballon == true,
@@ -24,7 +24,7 @@ import { Observable, Subscription } from 'rxjs';
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service';
import { EditMessagePage } from 'src/app/ui/chat/modal/edit-message/edit-message.page';
import { IMessageType, MessageAttachmentFileType, MessageAttachmentSource } from 'src/app/core/chat/entity/message';
import { IMessageType, MessageAttachmentFileType, MessageAttachmentSource, MessageEntity } from 'src/app/core/chat/entity/message';
import { MemberTable } from 'src/app/infra/database/dexie/instance/chat/schema/members';
import { TypingTable } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
import { compressImageBase64 } from 'src/app/utils/imageCompressore';
@@ -50,6 +50,8 @@ import { MessageViewModal } from '../../store/model/message';
import { XBallon } from '../../utils/messageBallon';
import { tap } from 'rxjs/operators';
import { ChatPopoverPage } from '../chat-popover/chat-popover.page';
import { ViewOncesImagePageInput, ViewOncesImagePage } from '../view-onces/view-onces.page';
import { LastMessage } from '../../utils/lastMessage';
@@ -887,6 +889,19 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
async onImageError() {}
async onImageLoad(message: MessageViewModal, index:number) {
if(message.attachments[0].fileName == LastMessage.attachments[0].fileName) {
this.scrollToBottom()
setTimeout(() => {
this.scrollToBottom();
}, 100)
this.messages1[this.roomId].splice(index, 1);
}
}
async takePictureMobile() {
@@ -1067,6 +1082,22 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
}
async viewOnce(event: Event, message: MessageViewModal, index:number) {
const params: ViewOncesImagePageInput = {
imageDataUrl: message.attachments[index].safeFile as any,
}
const modal = await this.modalController.create({
component: ViewOncesImagePage,
cssClass: '',
componentProps: params
});
modal.present()
return modal.onDidDismiss().then((res) => {
this.messageDelete(message)
});
}
async addFileToChat(types) {
console.log('add file ')
@@ -1,6 +1,6 @@
<ion-header>
<ion-toolbar>
<ion-title class="title" *ngIf="roomData$ | async as roomData"> Nome do grupo {{ roomData.roomName }}</ion-title>
<ion-title class="title" *ngIf="roomData$ | async as roomData"> {{ roomData.roomName }}</ion-title>
</ion-toolbar>
</ion-header>
@@ -10,9 +10,12 @@
<ion-list class="header-bottom-contacts px-20" *ngIf="roomMembers$ | async as memberList">
<div *ngFor="let user of memberList; let i = index">
<div class="py-1">
<!-- <img [src]="memberList.userPhoto" class="pa-20"> {{ user.wxFullName }} -->
{{ user.wxFullName }} <span *ngIf="user.isAdmin">(admin do group)</span>
<div class="py-1 d-flex align-center">
<div class="image-container mr-10">
<img *ngIf="ObjectURL[user.wxUserId]" [src]="ObjectURL[user.wxUserId]">
</div>
{{ user.wxFullName }} <span class="admin" *ngIf="user.isAdmin">(admin do group)</span>
</div>
</div>
</ion-list>
@@ -5,4 +5,18 @@ img {
-moz-border-radius: 20px;
-ms-border-radius: 20px;
-o-border-radius: 20px;
}
height: 35px;
width: 35px;
object-fit: cover;
}
.image-container {
height: 35px;
width: 35px;
background-color: gray;
border-radius: 20px;
}
.admin {
color: gray;
}
@@ -2,12 +2,11 @@ import { Component, OnInit } from '@angular/core';
import { NavParams } from '@ionic/angular';
import { Observable } from 'rxjs';
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
import { Observable as DexieObservable } from 'Dexie';
import { RoomLocalRepository } from 'src/app/module/chat/data/repository/room/room-local-repository.service'
import { MemberTable } from 'src/app/infra/database/dexie/instance/chat/schema/members';
import { RoomTable } from 'src/app/infra/database/dexie/instance/chat/schema/room';
import { tap } from 'rxjs/operators';
import { map, tap } from 'rxjs/operators';
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
import { MemberEntity } from 'src/app/core/chat/entity/member';
@Component({
selector: 'app-room-info',
templateUrl: './room-info.page.html',
@@ -16,13 +15,15 @@ import { tap } from 'rxjs/operators';
export class RoomInfoPage implements OnInit {
roomId:string;
roomMembers$: Observable<MemberTable[] | undefined>
roomMembers$: Observable<MemberEntity[]>
roomData$: Observable<RoomTable | undefined>
ObjectURL : {[key: string]: string} = {};
constructor(
private navParams: NavParams,
private MemberListLocalRepository: MemberListLocalRepository,
private RoomLocalRepository: RoomLocalRepository,
private ChatServiceService: ChatServiceService
) {
this.roomId = this.navParams.get('roomId');
}
@@ -31,10 +32,24 @@ export class RoomInfoPage implements OnInit {
// this.roomMessage$ = this.messageRepositoryService.getItemsLive(this.roomId)
this.roomMembers$ = this.MemberListLocalRepository.getRoomMemberByIdLive(this.roomId).pipe(
tap((data)=> {
console.log(data)
})
map((memberList) => memberList.map(e => Object.assign(new MemberEntity(), e))),
tap((members) => {
for(let member of members) {
if(!this.ObjectURL[member.wxUserId] && member.hasPhoto()) {
this.ChatServiceService.getUserPhoto({wxUserId: member.wxUserId, attachmentId: member.userPhoto}).then((result)=> {
if(result.isOk()) {
console.log('get photo', result.value)
this.ObjectURL[member.wxUserId] = 'data:image/jpeg;base64,'+result.value
}
})
}
}
}),
)
this.roomData$ = this.RoomLocalRepository.getRoomByIdLive(this.roomId)
}
-3
View File
@@ -2,9 +2,6 @@
"folders": [
{
"path": "."
},
{
"path": "../../../Downloads/nestjs-microservice-boilerplate-api-master"
}
],
"settings": {