mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-20 21:35:50 +00:00
notification and chat slow
This commit is contained in:
@@ -95,9 +95,11 @@ export class MessageEntity {
|
||||
|
||||
constructor() {}
|
||||
|
||||
get messageStatus() {
|
||||
get messageHasId() {
|
||||
if(this.id) {
|
||||
return 'send'
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,236 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { IMessage, MessageAttachmentSource, MessageEntity, MessageEntitySchema, } from '../../entity/message';
|
||||
import { z } from 'zod';
|
||||
import { v4 as uuidv4 } from 'uuid';
|
||||
import { InstanceId } from '../../../../module/chat/domain/chat-service.service';
|
||||
import { createBlobFromBase64, createDataURL } from 'src/app/utils/ToBase64';
|
||||
import { zodSafeValidation } from 'src/app/utils/zodValidation';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { err, Result } from 'neverthrow';
|
||||
import { MessageMapper } from '../../mapper/messageMapper';
|
||||
import { RoomType } from "src/app/core/chat/entity/group";
|
||||
import { TracingType, XTracerAsync } from 'src/app/services/monitoring/opentelemetry/tracer';
|
||||
import { MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
import { MessageAttachmentFileType, MessageOutPutDataDTO } from 'src/app/core/chat/repository/dto/messageOutputDTO';
|
||||
import { IMessageLocalRepository } from 'src/app/core/chat/repository/message/message-local-repository';
|
||||
import { IMessageSocketRepository } from 'src/app/core/chat/repository/message/message-socket-repository';
|
||||
import { IMemberLocalRepository } from 'src/app/core/chat/repository/member/member-local-repository';
|
||||
import { IAttachmentLocalRepository } from 'src/app/core/chat/repository/typing/typing-local-repository';
|
||||
import { base64Schema } from 'src/app/utils/zod';
|
||||
|
||||
|
||||
export const MessageInputDTOSchema = z.object({
|
||||
roomId: z.string().uuid().optional(),
|
||||
receiverId: z.number().optional(),
|
||||
senderId: z.number(),
|
||||
message: z.string().nullable().optional(),
|
||||
messageType: z.number(),
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
requireUnlock: z.boolean(),
|
||||
requestId: z.string(),
|
||||
attachment: z.object({
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType),
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
file: base64Schema.optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.number().optional(),
|
||||
mimeType: z.string().nullable().optional(),
|
||||
description: z.string().optional()
|
||||
}).optional()
|
||||
});
|
||||
export type MessageInputDTO = z.infer<typeof MessageInputDTOSchema>
|
||||
|
||||
|
||||
|
||||
export const MessageCreatePutDataDTOSchema = z.object({
|
||||
id: z.string(),
|
||||
roomId: z.string(),
|
||||
sender: z.object({
|
||||
wxUserId: z.number(),
|
||||
wxFullName: z.string(),
|
||||
wxeMail: z.string(),
|
||||
userPhoto: z.string().optional()
|
||||
}),
|
||||
message: z.string().nullable().optional(),
|
||||
messageType: z.number(),
|
||||
sentAt: z.string(),
|
||||
canEdit: z.boolean(),
|
||||
oneShot: z.boolean(),
|
||||
requireUnlock: z.boolean(),
|
||||
requestId: z.string().optional().nullable(),
|
||||
reactions: z.object({
|
||||
id: z.string(),
|
||||
reactedAt: z.string(),
|
||||
reaction: z.string(),
|
||||
sender: z.object({}),
|
||||
}).array(),
|
||||
info: z.array(z.object({
|
||||
memberId: z.number(),
|
||||
readAt: z.string().nullable(),
|
||||
deliverAt: z.string().nullable()
|
||||
})),
|
||||
attachments: z.array(z.object({
|
||||
fileType: z.nativeEnum(MessageAttachmentFileType),
|
||||
source: z.nativeEnum(MessageAttachmentSource),
|
||||
file: z.string().optional(),
|
||||
fileName: z.string().optional(),
|
||||
applicationId: z.number().optional(),
|
||||
docId: z.number().optional(),
|
||||
id: z.string().optional()
|
||||
}))
|
||||
});
|
||||
|
||||
export type MessageCreateOutPutDataDTO = z.infer<typeof MessageCreatePutDataDTOSchema>
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root'
|
||||
})
|
||||
export class MessageCreateUseCaseService {
|
||||
|
||||
constructor(
|
||||
private AttachmentLocalRepositoryService: IAttachmentLocalRepository,
|
||||
private messageLocalDataSourceService: IMessageLocalRepository,
|
||||
private messageSocketRepositoryService: IMessageSocketRepository,
|
||||
private MemberListLocalRepository: IMemberLocalRepository
|
||||
) { }
|
||||
|
||||
|
||||
@XTracerAsync({name:'MessageCreateUseCaseService', module:'chat', bugPrint: true, waitNThrow: 5000})
|
||||
async execute(message: IMessage, messageEnum: RoomType, tracing?: TracingType) {
|
||||
|
||||
const validation = zodSafeValidation<IMessage>(MessageEntitySchema, message)
|
||||
|
||||
if(validation.isOk()) {
|
||||
message.sendAttemp++;
|
||||
|
||||
message.requestId = InstanceId +'@'+ uuidv4();
|
||||
message.sending = true;
|
||||
|
||||
const createMessageLocally = this.messageLocalDataSourceService.insert(message)
|
||||
|
||||
createMessageLocally.then(async (value) => {
|
||||
if(value.isOk()) {
|
||||
|
||||
const localId = value.value
|
||||
message.$id = localId
|
||||
|
||||
if(message.hasAttachment) {
|
||||
|
||||
for (const attachment of message.attachments) {
|
||||
|
||||
if(attachment.source != MessageAttachmentSource.Webtrix) {
|
||||
|
||||
this.AttachmentLocalRepositoryService.insert({
|
||||
$messageId: localId,
|
||||
file: createBlobFromBase64(attachment.file, attachment.mimeType),
|
||||
fileType: attachment.fileType,
|
||||
source: attachment.source,
|
||||
fileName: attachment.fileName,
|
||||
applicationId: attachment.applicationId,
|
||||
docId: attachment.docId,
|
||||
mimeType: attachment.mimeType,
|
||||
base64: createDataURL(attachment.file, attachment.mimeType)
|
||||
}).then((e) => {
|
||||
if(e.isErr()) {
|
||||
Logger.error('failed to create attachment locally on send message', {
|
||||
error: e.error,
|
||||
data: createDataURL(attachment.file, attachment.mimeType).slice(0, 100) +'...'
|
||||
})
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
attachment.safeFile = createDataURL(attachment.file, attachment.mimeType)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
Logger.error('failed to insert locally', {
|
||||
error: value.error.message
|
||||
})
|
||||
}
|
||||
|
||||
}).catch((error) => {
|
||||
Logger.error('failed to insert catch', {
|
||||
//error: createMessageLocally.error.message
|
||||
})
|
||||
})
|
||||
|
||||
|
||||
let sendMessageResult: Result<MessageOutPutDataDTO, any>
|
||||
|
||||
if(messageEnum == RoomType.Group) {
|
||||
const DTO = MessageMapper.fromDomain(message, message.requestId)
|
||||
message.sending = true
|
||||
sendMessageResult = await this.messageSocketRepositoryService.sendGroupMessage(DTO)
|
||||
} else {
|
||||
const DTO = MessageMapper.fromDomain(message, message.requestId)
|
||||
delete DTO.roomId
|
||||
message.sending = true
|
||||
sendMessageResult = await this.messageSocketRepositoryService.sendDirectMessage(DTO)
|
||||
}
|
||||
|
||||
// return this sendMessageResult
|
||||
|
||||
if(sendMessageResult.isOk()) {
|
||||
|
||||
message.id = sendMessageResult.value.id
|
||||
|
||||
console.log('sendMessageResult', sendMessageResult.value.id)
|
||||
|
||||
if(sendMessageResult.value.sender == undefined || sendMessageResult.value.sender == null) {
|
||||
|
||||
delete sendMessageResult.value.sender
|
||||
}
|
||||
|
||||
let clone: MessageTable = {
|
||||
...sendMessageResult.value,
|
||||
id: sendMessageResult.value.id,
|
||||
$id : message.$id
|
||||
}
|
||||
|
||||
createMessageLocally.then(() => {
|
||||
this.messageLocalDataSourceService.update(message.$id, {...clone, sending: false, roomId: clone.roomId}).then((data)=> {
|
||||
if(data.isOk()) {
|
||||
|
||||
} else {
|
||||
tracing.hasError('failed to update send message')
|
||||
console.log(sendMessageResult)
|
||||
console.log(data.error)
|
||||
}
|
||||
})
|
||||
})
|
||||
|
||||
return sendMessageResult
|
||||
} else {
|
||||
Logger.error('failed to send message to the server', {
|
||||
error: sendMessageResult.error
|
||||
})
|
||||
await this.messageLocalDataSourceService.update(message.$id, {sending: false, $id: message.$id})
|
||||
return err('no connection')
|
||||
}
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
if(validation.error.formErrors.fieldErrors.attachments) {
|
||||
Logger.error('failed to send message doe to invalid attachment', {
|
||||
zodErrorList: validation.error.errors,
|
||||
data: message.attachments
|
||||
})
|
||||
} else {
|
||||
Logger.error('failed to send message, validation failed', {
|
||||
zodErrorList: validation.error.errors,
|
||||
data: message
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
import { RemoteNotificationService } from 'src/app/module/notification/data/datasource/remote-notification.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { z } from 'zod';
|
||||
|
||||
const NotificationDeleteAllByUserIdSchema = z.any()
|
||||
@@ -14,8 +15,7 @@ export class NotificationDeleteAllServiceUseCase {
|
||||
private RemoteNotificationService:RemoteNotificationService
|
||||
) { }
|
||||
|
||||
async execute(userId: INotificationDeleteAllByUserId) {
|
||||
|
||||
return this.RemoteNotificationService.notificationDeleteAll(userId)
|
||||
async execute() {
|
||||
return this.RemoteNotificationService.notificationDeleteAll(SessionStore.user.UserId)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -7,12 +7,7 @@ const routes: Routes = [
|
||||
{
|
||||
path: '',
|
||||
component: IndexPage,
|
||||
/* canActivate: [IndexGuard], */
|
||||
children: [
|
||||
/*{
|
||||
path: '',
|
||||
loadChildren: ()=> import('../pages/welcome/welcome.module').then(m => m.WelcomePageModule)
|
||||
}, */
|
||||
{
|
||||
path: '',
|
||||
loadChildren: ()=> import('../pages/login/login.module').then(m => m.LoginPageModule),
|
||||
|
||||
@@ -1,22 +1,22 @@
|
||||
|
||||
import { Dexie } from 'Dexie';
|
||||
import { DexieMessageTable, messageTableColumn, MessageTable } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
import { DexieMessageTable, messageTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/message';
|
||||
import { DexieMembersTableSchema, MemberTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/members';
|
||||
import { DexieRoomsTable, RoomTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/room';
|
||||
import { DexieTypingsTable, TypingTableColumn } from 'src/app/infra/database/dexie/instance/chat/schema/typing';
|
||||
import { MessageEntity } from 'src/app/core/chat/entity/message';
|
||||
import { AttachmentTableColumn, DexieAttachmentsTableSchema } from 'src/app/infra/database/dexie/instance/chat/schema/attachment';
|
||||
import { DexieDistributionTable, DistributionTable, DistributionTableColumn } from './schema/destribution';
|
||||
import { DexieDistributionTable, DistributionTableColumn } from './schema/destribution';
|
||||
import { BoldTableColumn, DexieBoldTable } from './schema/bold';
|
||||
import { DexieUserPhotoTable, UserPhotoTable, UserPhotoTableColumn } from './schema/user-foto';
|
||||
// import FDBFactory from 'fake-indexeddb/lib/FDBFactory';
|
||||
// import FDBKeyRange from 'fake-indexeddb/lib/FDBKeyRange';
|
||||
import { DexieUserPhotoTable, UserPhotoTableColumn } from './schema/user-foto';
|
||||
import FDBFactory from 'fake-indexeddb/lib/FDBFactory';
|
||||
import FDBKeyRange from 'fake-indexeddb/lib/FDBKeyRange';
|
||||
|
||||
|
||||
// Database declaration (move this to its own module also)
|
||||
export const chatDatabase = new Dexie('chat-database-v4',{
|
||||
// indexedDB: new FDBFactory,
|
||||
// IDBKeyRange: FDBKeyRange, // Mocking IDBKeyRange
|
||||
//indexedDB: new FDBFactory,
|
||||
//IDBKeyRange: FDBKeyRange, // Mocking IDBKeyRange
|
||||
}) as Dexie & {
|
||||
message: DexieMessageTable,
|
||||
members: DexieMembersTableSchema,
|
||||
|
||||
@@ -85,19 +85,23 @@
|
||||
<div class="line"></div>
|
||||
<ion-progress-bar type="indeterminate" *ngIf="isloading"></ion-progress-bar>
|
||||
<!-- <ion-label (click)="asyncNotification()" *ngIf="NotificationHolderService.notificationList">{{notificationStatus}}</ion-label> -->
|
||||
|
||||
<button *ngIf="(notificationList$ | async) as notificationList" style="background: transparent; padding-top: 5px; float: right;" (click)="deleteAllNotification()" class="pointer cursor-pointer">
|
||||
<ion-icon *ngIf="notificationList.length >= 1" (click)="deleteAllNotification()" style="height: 25px;width: 25px;float: right;" class="delete" src='assets/images/theme/gov/icons-delete.svg'></ion-icon>
|
||||
</button>
|
||||
|
||||
</div>
|
||||
</ion-header>
|
||||
|
||||
<ion-content class=" bg-blue">
|
||||
<div class="d-flex flex-column height-100 overflow-y-auto">
|
||||
|
||||
<div class="notifications-content height-100">
|
||||
|
||||
<ion-list *ngIf="(notificationList$ | async) as notificationList">
|
||||
<div class=" cursor-pointer ion-no-padding ion-no-margin" lines="none"
|
||||
*ngFor="let item of notificationList; let i = index">
|
||||
|
||||
<div *ngIf="item.status==false " class="item" (click)="notificatinsRoutes(item.index, item)">
|
||||
<div class="item" (click)="notificatinsRoutes(item.index, item)">
|
||||
<div *ngIf="objectRead[item.notificationId] != true" class="item-conten1 item-conten-{{item.service}}-{{item.typeAgenda}}-{{item.role}} llll" >
|
||||
|
||||
<div class="notification-item">
|
||||
|
||||
@@ -77,6 +77,7 @@
|
||||
}
|
||||
.profile-content {
|
||||
padding: 20px 20px;
|
||||
padding-bottom: 5px;
|
||||
//color: var(--profile-text-color) !important;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,6 @@ import { AnimationController, ModalController } from '@ionic/angular';
|
||||
import { AuthService } from 'src/app/services/auth.service';
|
||||
import { EditProfilePage } from './edit-profile/edit-profile.page';
|
||||
import { StorageService } from '../../services/storage.service';
|
||||
import { NotificationsService } from '../../services/notifications.service';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { ThemeService } from 'src/app/services/theme.service'
|
||||
import { environment } from 'src/environments/environment';
|
||||
@@ -20,7 +19,7 @@ import { isHttpError } from 'src/app/services/http.service';
|
||||
import { UserRepositoryService } from 'src/app/module/user/data/user-repository.service';
|
||||
import { UserProfilePicture } from 'src/app/module/user/data/datasource/user-local-repository.service';
|
||||
import { UserService } from 'src/app/module/user/domain/user.service'
|
||||
|
||||
import { NotificationService } from 'src/app/module/notification/domain/notification.service'
|
||||
|
||||
@Component({
|
||||
selector: 'app-profile',
|
||||
@@ -63,7 +62,7 @@ export class ProfilePage implements OnInit {
|
||||
private router: Router,
|
||||
private zone: NgZone,
|
||||
public ThemeService: ThemeService,
|
||||
private notificationService: NotificationsService,
|
||||
private NotificationService: NotificationService,
|
||||
private processesService: ProcessesService,
|
||||
private storageService: StorageService,
|
||||
public NotificationHolderService: NotificationHolderService,
|
||||
@@ -72,7 +71,7 @@ export class ProfilePage implements OnInit {
|
||||
private toastService: ToastService,
|
||||
private notificationRepositoryService: NotificationRepositoryService,
|
||||
private UserRepositoryService: UserRepositoryService,
|
||||
private UserService:UserService
|
||||
private UserService:UserService,
|
||||
) {
|
||||
|
||||
this.profilePictureSubject = this.UserRepositoryService.getProfilePictureLive() as any
|
||||
@@ -417,4 +416,11 @@ export class ProfilePage implements OnInit {
|
||||
this.deleteNotification(item);
|
||||
}
|
||||
|
||||
|
||||
async deleteAllNotification() {
|
||||
console.log('nice job')
|
||||
await this.NotificationService.deleteAllNotificationByUserId()
|
||||
this.notificationRepositoryService.init()
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,7 @@ export function NotificationListChanges(
|
||||
const localItem = localMap.get(id);
|
||||
if (!localItem) {
|
||||
changes.insert.push(serverItem);
|
||||
} else if (localItem.status !== serverItem.status) {
|
||||
} else if (localItem.viewDate !== serverItem.viewDate) {
|
||||
changes.update.push(serverItem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -122,7 +122,7 @@ export class LocalNotificationService {
|
||||
return from(liveQuery( () => {
|
||||
return NotificationDataSource.notification.orderBy('createdAt').reverse().toArray()
|
||||
.then(notifications => {
|
||||
return notifications.filter(notification => notification.status === false)
|
||||
return notifications.filter(notification => notification.viewDate == null)
|
||||
})
|
||||
}))
|
||||
}
|
||||
@@ -132,7 +132,7 @@ export class LocalNotificationService {
|
||||
return NotificationDataSource.notification
|
||||
.toArray()
|
||||
.then(notifications => {
|
||||
return notifications.filter(notification => notification.status === false).length
|
||||
return notifications.filter(notification => notification.viewDate == null).length
|
||||
})
|
||||
}))
|
||||
}
|
||||
|
||||
@@ -22,7 +22,7 @@ export class RemoteNotificationService {
|
||||
}
|
||||
|
||||
|
||||
async notificationStatus(id: string) {
|
||||
async notificationStatus(id: number) {
|
||||
return await this.httpService.patch<NotificationOutputDTO>(`${this.baseUrl}/Notifications/${id}/status`);
|
||||
}
|
||||
|
||||
@@ -30,5 +30,4 @@ export class RemoteNotificationService {
|
||||
async notificationDeleteAll(userId: any) {
|
||||
return await this.httpService.delete<NotificationOutputDTO>(`${this.baseUrl}/Notifications/${userId}`);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ export const NotificationOutputDTOSchema = z.object({
|
||||
total: z.number(),
|
||||
result: z.array(
|
||||
z.object({
|
||||
id: z.string(),
|
||||
id: z.number(),
|
||||
service: z.string(),
|
||||
title: z.string(),
|
||||
body: z.string(),
|
||||
@@ -17,7 +17,6 @@ export const NotificationOutputDTOSchema = z.object({
|
||||
folderId: z.string().nullable(),
|
||||
createdAt: z.string(),
|
||||
viewDate: z.string().nullable(),
|
||||
status: z.boolean(),
|
||||
startDate: z.string().nullable(),
|
||||
endDate: z.string().nullable(),
|
||||
bodyEvent: z.string().nullable(),
|
||||
|
||||
@@ -2,16 +2,16 @@ import { Dexie, EntityTable, liveQuery } from 'Dexie';
|
||||
import { z } from 'zod';
|
||||
|
||||
export const NotificationTableSchema = z.object({
|
||||
notificationId: z.string().nullable(),
|
||||
notificationId: z.number().nullable(),
|
||||
title: z.string().optional().nullable(),
|
||||
service: z.string().nullable(),
|
||||
object: z.string().optional().nullable(),
|
||||
idObject: z.string().nullable(),
|
||||
viewDate: z.string().nullable(),
|
||||
folderId: z.string().optional().nullable(),
|
||||
dateInit: z.string().optional().nullable(),
|
||||
dateEnd: z.string().optional().nullable(),
|
||||
location: z.string().optional().nullable(),
|
||||
status: z.boolean().optional(),
|
||||
notificationBody: z.any().optional()
|
||||
})
|
||||
export type NotificationTable = z.infer<typeof NotificationTableSchema>
|
||||
|
||||
@@ -83,7 +83,7 @@ export class NotificationRepositoryService {
|
||||
|
||||
async notificationStatus(item: NotificationTable) {
|
||||
await this.RemoteNotificationService.notificationStatus(item.notificationId)
|
||||
item.status = true
|
||||
item.viewDate = new Date().toUTCString()
|
||||
this.LocalNotificationService.updateNotification(item)
|
||||
this
|
||||
this.init()
|
||||
@@ -93,14 +93,14 @@ export class NotificationRepositoryService {
|
||||
|
||||
async RemoveNotificationStatus(item: NotificationTable) {
|
||||
await this.RemoteNotificationService.notificationStatus(item.notificationId)
|
||||
item.status = true
|
||||
item.viewDate = new Date().toUTCString()
|
||||
this.LocalNotificationService.updateNotification(item)
|
||||
this.init()
|
||||
return
|
||||
}
|
||||
|
||||
async localNotificationStatus(item: NotificationTable) {
|
||||
item.status = true
|
||||
item.viewDate = new Date().toUTCString()
|
||||
this.LocalNotificationService.updateNotification(item)
|
||||
this.init()
|
||||
return
|
||||
|
||||
@@ -14,9 +14,9 @@ export function NotificationListMapper(NotificationOutputDTO: NotificationOutput
|
||||
dateInit: e.startDate,
|
||||
dateEnd: e.endDate,
|
||||
createdAt: e.createdAt,
|
||||
status: e.status,
|
||||
location: e.location,
|
||||
notificationBody: e.body
|
||||
notificationBody: e.body,
|
||||
viewDate: e.viewDate
|
||||
}
|
||||
))
|
||||
}
|
||||
|
||||
@@ -11,8 +11,8 @@ export class NotificationService {
|
||||
) { }
|
||||
|
||||
|
||||
deleteAllNotificationByUserId(userId: INotificationDeleteAllByUserId) {
|
||||
this.NotificationDeleteAllServiceUseCase.execute(userId)
|
||||
deleteAllNotificationByUserId() {
|
||||
return this.NotificationDeleteAllServiceUseCase.execute()
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -3,7 +3,7 @@ import { ProcessesService } from 'src/app/services/processes.service';
|
||||
import { ActivatedRoute } from '@angular/router';
|
||||
import { Event } from '../../../../models/event.model';
|
||||
import { MenuController, ModalController, PopoverController } from '@ionic/angular';
|
||||
import { momentG } from 'src/plugin/momentG'
|
||||
import { momentG } from 'src/plugin/momentG';
|
||||
import { DiscartExpedientModalPage } from '../../discart-expedient-modal/discart-expedient-modal.page';
|
||||
import { BookMeetingModalPage } from '../../expediente/book-meeting-modal/book-meeting-modal.page';
|
||||
import { CreateProcessPage } from 'src/app/modals/create-process/create-process.page';
|
||||
|
||||
@@ -189,40 +189,38 @@ export class GroupContactsPage implements OnInit {
|
||||
|
||||
|
||||
async deleteMember(user: UserContacts) {
|
||||
this.showLoader = true;
|
||||
|
||||
// this.chatServiceService.removeMember({
|
||||
// roomId: this.roomId,
|
||||
// members: [ user.wxUserId]
|
||||
// })
|
||||
// if(this.currentMembers.length >= 3) {
|
||||
this.showLoader = true;
|
||||
|
||||
// this.currentMembers = this.currentMembers.filter( e => e.wxUserId != user.wxUserId)
|
||||
const result = await this.chatServiceService.removeMemberToRoom({
|
||||
id: this.roomId,
|
||||
members: [ user.wxUserId]
|
||||
})
|
||||
|
||||
const result = await this.chatServiceService.removeMemberToRoom({
|
||||
id: this.roomId,
|
||||
members: [ user.wxUserId]
|
||||
})
|
||||
if(result.isOk()) {
|
||||
this.currentMembers = this.currentMembers.filter( e => e.wxUserId != user.wxUserId)
|
||||
|
||||
if(result.isOk()) {
|
||||
this.currentMembers = this.currentMembers.filter( e => e.wxUserId != user.wxUserId)
|
||||
const firstLetter = user.wxFullName.charAt(0)
|
||||
|
||||
const firstLetter = user.wxFullName.charAt(0)
|
||||
if(!this.userContainer[firstLetter]) {
|
||||
user['isChecked'] = false
|
||||
this.userContainer[firstLetter] = [user as any]
|
||||
} else {
|
||||
user['isChecked'] = false
|
||||
this.userContainer[firstLetter].push(user as any)
|
||||
}
|
||||
|
||||
if(!this.userContainer[firstLetter]) {
|
||||
user['isChecked'] = false
|
||||
this.userContainer[firstLetter] = [user as any]
|
||||
} else {
|
||||
user['isChecked'] = false
|
||||
this.userContainer[firstLetter].push(user as any)
|
||||
} else if(result.error instanceof HttpRequest) {
|
||||
this.httpErrorHandle.httpStatusHandle(result.error)
|
||||
} else if(result.error instanceof ZodError) {
|
||||
console.log(result.error.issues)
|
||||
}
|
||||
|
||||
} else if(result.error instanceof HttpRequest) {
|
||||
this.httpErrorHandle.httpStatusHandle(result.error)
|
||||
} else if(result.error instanceof ZodError) {
|
||||
console.log(result.error.issues)
|
||||
}
|
||||
|
||||
this.showLoader = false;
|
||||
this.showLoader = false;
|
||||
//} else {
|
||||
// alert('---')
|
||||
//}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -59,6 +59,11 @@
|
||||
</div>
|
||||
|
||||
<div class="message-container rotate-div" *ngIf="message.showMessage">
|
||||
<div *ngIf="message.sender.wxUserId != SessionStore.user.UserId && roomType == RoomTypeEnum.Group">
|
||||
<b>
|
||||
{{ message.sender.wxFullName }}
|
||||
</b>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<div style="white-space: pre-line;">
|
||||
@@ -125,8 +130,8 @@
|
||||
<div class="message-item-options d-flex justify-content-end">
|
||||
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon>
|
||||
<mat-menu class="d-block" #beforeMenu="matMenu" xPosition="before">
|
||||
<button (click)="messageDelete(message)" class="menuButton d-block py-2 px-10">Apagar mensagem</button>
|
||||
<button *ngIf="!message.hasAttachment" (click)="editMessage(message)" class="menuButton d-block py-2 px-10">Editar mensagem</button>
|
||||
<button *ngIf="message.sender.wxUserId == SessionStore.user.UserId" (click)="messageDelete(message)" class="menuButton d-block py-2 px-10">Apagar mensagem</button>
|
||||
<button *ngIf="!message.hasAttachment && message.sender.wxUserId == SessionStore.user.UserId" (click)="editMessage(message)" class="menuButton d-block py-2 px-10">Editar mensagem</button>
|
||||
<button (click)="toggleEmojiPicker(message)" class="menuButton d-block py-2 px-10">Reagir mensagem</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
|
||||
@@ -300,7 +300,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
return 'allViewed'
|
||||
} else if(this.allReceived(message)) {
|
||||
return 'allReceived'
|
||||
} else if (message.messageStatus == 'send') {
|
||||
} else if (message.messageHasId) {
|
||||
return 'enviado'
|
||||
} else {
|
||||
return 'enviar'
|
||||
|
||||
@@ -5,12 +5,17 @@ import { ThemeService } from 'src/app/services/theme.service'
|
||||
import { SetRoomOwnerPage } from 'src/app/ui/chat/modal/set-room-owner/set-room-owner.page';
|
||||
import { SessionStore } from 'src/app/store/session.service';
|
||||
import { ZodError } from 'zod';
|
||||
|
||||
import { MemberListLocalRepository } from 'src/app/module/chat/data/repository/member/member-list-local-repository.service'
|
||||
import { ChatServiceService } from 'src/app/module/chat/domain/chat-service.service'
|
||||
import { RoomInfoPage } from '../room-info/room-info.page';
|
||||
import { RoomType } from 'src/app/core/chat/entity/group';
|
||||
import { isHttpResponse } from 'src/app/infra/http/http.service';
|
||||
|
||||
|
||||
interface ISetRoomOwner {
|
||||
addAdminBeforeLeave: null | boolean
|
||||
}
|
||||
|
||||
@Component({
|
||||
selector: 'app-chat-popover',
|
||||
templateUrl: './chat-popover.page.html',
|
||||
@@ -31,7 +36,8 @@ export class ChatPopoverPage implements OnInit {
|
||||
private navParams: NavParams,
|
||||
private toastService: ToastService,
|
||||
public ThemeService: ThemeService,
|
||||
private ChatServiceService: ChatServiceService
|
||||
private ChatServiceService: ChatServiceService,
|
||||
private MemberListLocalRepository: MemberListLocalRepository
|
||||
) {
|
||||
this.roomId = this.navParams.get('roomId');
|
||||
this.isAdmin = this.navParams.get('isAdmin');
|
||||
@@ -55,7 +61,7 @@ export class ChatPopoverPage implements OnInit {
|
||||
//Top menu options
|
||||
//Close
|
||||
|
||||
async setRoomOwner() {
|
||||
async setRoomOwner({addAdminBeforeLeave = null}: ISetRoomOwner) {
|
||||
let classs;
|
||||
if (window.innerWidth < 701) {
|
||||
classs = 'modal modal-desktop'
|
||||
@@ -68,26 +74,36 @@ export class ChatPopoverPage implements OnInit {
|
||||
backdropDismiss: true,
|
||||
componentProps: {
|
||||
roomId: this.roomId,
|
||||
isAdmin: this.isAdmin
|
||||
isAdmin: this.isAdmin,
|
||||
addAdminBeforeLeave
|
||||
}
|
||||
});
|
||||
await modal.present();
|
||||
modal.onDidDismiss().then((res)=>{
|
||||
modal.onDidDismiss().then((res) => {
|
||||
if(res.data == 'success'){
|
||||
this.leaveGroup();
|
||||
//this.ChatSystemService.hidingRoom(this.roomId);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
setAdmin() {
|
||||
this.setRoomOwner();
|
||||
setAdmin(data:ISetRoomOwner) {
|
||||
this.setRoomOwner(data);
|
||||
}
|
||||
|
||||
async leaveGroup() {
|
||||
|
||||
//this.setRoomOwner();
|
||||
if(this.isAdmin) {
|
||||
const currentMemberToMap = await this.MemberListLocalRepository.getRoomMemberById(this.roomId)
|
||||
const adminCount = currentMemberToMap.filter(e => e.isAdmin);
|
||||
this.toastService._badRequest("É necessário adicionar um administrador");
|
||||
if(adminCount.length <= 1) {
|
||||
this.setAdmin({addAdminBeforeLeave: true});
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.showLoader = true
|
||||
const result = await this.ChatServiceService.leaveRoom({
|
||||
id: this.roomId,
|
||||
|
||||
@@ -68,6 +68,11 @@
|
||||
</div>
|
||||
|
||||
<div class="message-container rotate-div" *ngIf="message.showMessage">
|
||||
<div *ngIf="message.sender.wxUserId != SessionStore.user.UserId && RoomStore.room.roomType == RoomTypeEnum.Group">
|
||||
<b>
|
||||
{{ message.sender.wxFullName }}
|
||||
</b>
|
||||
</div>
|
||||
<div class="d-flex justify-content-between">
|
||||
<div>
|
||||
<div style="white-space: pre-line;">
|
||||
@@ -142,8 +147,8 @@
|
||||
<div class="message-item-options d-flex justify-content-end">
|
||||
<fa-icon [matMenuTriggerFor]="beforeMenu" icon="chevron-down" class="message-options-icon cursor-pointer"></fa-icon>
|
||||
<mat-menu class="custom-menu d-block" #beforeMenu="matMenu" xPosition="before">
|
||||
<button (click)="messageDelete(message)" class="menuButton d-block py-2 px-10">Apagar mensagem</button>
|
||||
<button *ngIf="!message.hasAttachment" (click)="editMessage(message)" class="menuButton d-block py-2 px-10">Editar mensagem</button>
|
||||
<button *ngIf="message.sender.wxUserId == SessionStore.user.UserId" (click)="messageDelete(message)" class="menuButton d-block py-2 px-10">Apagar mensagem</button>
|
||||
<button *ngIf="!message.hasAttachment && message.sender.wxUserId == SessionStore.user.UserId" (click)="editMessage(message)" class="menuButton d-block py-2 px-10">Editar mensagem</button>
|
||||
<button (click)="toggleEmojiPicker(message)" class="menuButton d-block py-2 px-10">Reagir mensagem</button>
|
||||
</mat-menu>
|
||||
</div>
|
||||
|
||||
@@ -149,7 +149,7 @@ export class MessagesPage implements OnInit, AfterViewInit, OnDestroy {
|
||||
return 'allViewed'
|
||||
} else if(this.allReceived(message)) {
|
||||
return 'allReceived'
|
||||
} else if (message.messageStatus == 'send') {
|
||||
} else if (message.messageHasId) {
|
||||
return 'enviado'
|
||||
} else {
|
||||
return 'enviar'
|
||||
|
||||
@@ -19,6 +19,7 @@ export class SetRoomOwnerPage implements OnInit {
|
||||
textSearch:string = "";
|
||||
roomId:any;
|
||||
members:any;
|
||||
addAdminBeforeLeave: boolean | null;
|
||||
roomMembers$!: DexieObservable<MemberTable[] | undefined>
|
||||
|
||||
constructor(
|
||||
@@ -31,6 +32,7 @@ export class SetRoomOwnerPage implements OnInit {
|
||||
) {
|
||||
this.roomId = this.navParams.get('roomId');
|
||||
this.members = this.navParams.get('members');
|
||||
this.addAdminBeforeLeave = this.navParams.get('addAdminBeforeLeave');
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
@@ -68,8 +70,10 @@ export class SetRoomOwnerPage implements OnInit {
|
||||
});
|
||||
|
||||
if(result.isOk()) {
|
||||
this.chatServiceService.getRoomById(this.roomId);
|
||||
// this.modalController.dismiss('success');
|
||||
await this.chatServiceService.getRoomById(this.roomId);
|
||||
if(this.addAdminBeforeLeave) {
|
||||
this.modalController.dismiss('success');
|
||||
}
|
||||
} else {
|
||||
this.toastService._badRequest('Não foi possível completar a ação, por favor tente novamente.');
|
||||
}
|
||||
|
||||
@@ -99,9 +99,11 @@ export class MessageViewModal {
|
||||
}
|
||||
|
||||
|
||||
get messageStatus() {
|
||||
get messageHasId() {
|
||||
if(this.id) {
|
||||
return 'send'
|
||||
return true
|
||||
} else {
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user