mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-19 04:57:52 +00:00
fix chat estracture
This commit is contained in:
@@ -106,6 +106,16 @@ import { typingReducer } from './module/chat/data/data-source/userTyping/user-ty
|
||||
import { FirebaseX } from '@ionic-native/firebase-x/ngx'; */
|
||||
//import { FCM } from 'cordova-plugin-fcm-with-dependecy-updated/ionic/ngx';
|
||||
|
||||
|
||||
// import { WebTracerProvider } from '@opentelemetry/web';
|
||||
// import { SimpleSpanProcessor } from '@opentelemetry/tracing';
|
||||
// import { ConsoleSpanExporter } from '@opentelemetry/tracing';
|
||||
|
||||
|
||||
// const provider = new WebTracerProvider();
|
||||
// provider.addSpanProcessor(new SimpleSpanProcessor(new ConsoleSpanExporter()));
|
||||
// provider.register();
|
||||
|
||||
Sentry.init(
|
||||
{
|
||||
dsn: 'https://5b345a3ae70b4e4da463da65881b4aaa@o4504340905525248.ingest.sentry.io/4504345615794176',
|
||||
|
||||
@@ -2,18 +2,18 @@ import { TableRoom } from "../../../data-source/room/rooom-local-data-source.ser
|
||||
import { RoomListItemOutPutDTO, RoomListOutPutDTO } from "../../../dto/room/roomListOutputDTO";
|
||||
|
||||
export function roomListDetermineChanges(serverRooms: RoomListItemOutPutDTO[], localRooms: TableRoom[]) {
|
||||
const serverRoomMap = new Map(serverRooms.map(room => [room.id, room]));
|
||||
const serverRoomMap = new Map(serverRooms.map(room => [room.chatRoom.id, room]));
|
||||
const localRoomMap = new Map(localRooms.map(room => [room.id, room]));
|
||||
|
||||
const roomsToInsert = serverRooms.filter(room => !localRoomMap.has(room.id));
|
||||
const roomsToInsert = serverRooms.filter(room => !localRoomMap.has(room.chatRoom.id));
|
||||
const roomsToUpdate = serverRooms.filter(room => {
|
||||
const localRoom = localRoomMap.get(room.id);
|
||||
const localRoom = localRoomMap.get(room.chatRoom.id);
|
||||
return localRoom && (
|
||||
room.roomName !== localRoom.roomName ||
|
||||
room.createdBy.wxUserId !== localRoom.createdBy.wxUserId ||
|
||||
room.createdAt !== localRoom.createdAt ||
|
||||
room.expirationDate !== localRoom.expirationDate ||
|
||||
room.roomType !== localRoom.roomType
|
||||
room.chatRoom.roomName !== localRoom.roomName ||
|
||||
room.chatRoom.createdBy.wxUserId !== localRoom.createdBy.wxUserId ||
|
||||
room.chatRoom.createdAt !== localRoom.createdAt ||
|
||||
room.chatRoom.expirationDate !== localRoom.expirationDate ||
|
||||
room.chatRoom.roomType !== localRoom.roomType
|
||||
);
|
||||
});
|
||||
const roomsToDelete = localRooms.filter(room => !serverRoomMap.has(room.id));
|
||||
|
||||
@@ -23,7 +23,7 @@ export class MessageAsyncService {
|
||||
filter((message: any) => {
|
||||
return !message?.requestId?.startsWith(InstanceId) && message?.requestId
|
||||
})
|
||||
).subscribe(async (message: any) => {
|
||||
).subscribe(async (message) => {
|
||||
|
||||
console.log('message async ', message)
|
||||
|
||||
|
||||
@@ -75,6 +75,7 @@ export class MessageLocalDataSourceService {
|
||||
|
||||
async getLastMessageByRoomId(roomId: string): Promise<Result<undefined|TableMessage, any>> {
|
||||
try {
|
||||
console.log({roomId})
|
||||
const lastMessage = await messageDataSource.message
|
||||
.where('roomId')
|
||||
.equals(roomId)
|
||||
@@ -107,7 +108,7 @@ export class MessageLocalDataSourceService {
|
||||
}
|
||||
|
||||
|
||||
// @ValidateSchema(tableSchema)
|
||||
// @ValidateSchema(tableSchema)
|
||||
async createMessage(data: MessageInputDTO) {
|
||||
|
||||
try {
|
||||
|
||||
@@ -179,6 +179,10 @@ export class RoomLocalDataSourceService {
|
||||
return await roomDataSource.room.toArray()
|
||||
}
|
||||
|
||||
getMemberLive(data: {roomId, wxUserId}) {
|
||||
const $roomIdUserId = data.roomId + data.wxUserId
|
||||
return liveQuery(() => roomDataSource.memberList.get($roomIdUserId)) as any;
|
||||
}
|
||||
|
||||
getItemsLive(): Observable<RoomListOutPutDTO[]> {
|
||||
return liveQuery(() => roomDataSource.room.toArray()) as any;
|
||||
|
||||
+6
-2
@@ -11,8 +11,12 @@ export class UserTypingLiveDataSourceService {
|
||||
private SignalRLiveDataSourceService: SignalRService
|
||||
) { }
|
||||
|
||||
sendTyping(roomId) {
|
||||
return this.SignalRLiveDataSourceService.sendTyping({roomId, UserName:SessionStore.user.FullName})
|
||||
sendTyping(roomId, ) {
|
||||
return this.SignalRLiveDataSourceService.sendTyping({
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId:SessionStore.user.UserId
|
||||
})
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -11,6 +11,7 @@ const MemberSchema = z.object({
|
||||
id: z.string(),
|
||||
user: UserSchema,
|
||||
joinAt: z.string(),
|
||||
isAdmin: z.boolean()
|
||||
});
|
||||
|
||||
export const RoomByIdOutputDTOSchema = z.object({
|
||||
@@ -27,6 +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>
|
||||
@@ -8,12 +8,16 @@ const CreatedBySchema = z.object({
|
||||
});
|
||||
|
||||
const RoomListItemOutPutDTOSchema = z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: CreatedBySchema,
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(), // api check
|
||||
roomType: z.number()
|
||||
|
||||
chatRoom: z.object({
|
||||
id: z.string(),
|
||||
roomName: z.string(),
|
||||
createdBy: CreatedBySchema,
|
||||
createdAt: z.string(),
|
||||
expirationDate: z.string().nullable(), // api check
|
||||
roomType: z.number()
|
||||
}),
|
||||
joinAt: z.string()
|
||||
})
|
||||
|
||||
|
||||
|
||||
@@ -42,7 +42,8 @@ export class MessageRepositoryService {
|
||||
|
||||
data['requestId'] = InstanceId +'@'+ uuidv4();
|
||||
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage(data)
|
||||
const localActionResult = await this.messageLocalDataSourceService.sendMessage({...data})
|
||||
console.log('create message', data)
|
||||
|
||||
// this.messageLiveDataSourceService.sendMessage({
|
||||
// type: 'sendMessage',
|
||||
@@ -63,17 +64,20 @@ export class MessageRepositoryService {
|
||||
delete sendMessageResult.value.sender
|
||||
}
|
||||
|
||||
let clone: TableMessage = {
|
||||
...sendMessageResult.value,
|
||||
messageId: sendMessageResult.value.id,
|
||||
id : localActionResult.value
|
||||
}
|
||||
// let clone: TableMessage = {
|
||||
// ...sendMessageResult.value,
|
||||
// messageId: sendMessageResult.value.id,
|
||||
// id : localActionResult.value
|
||||
// }
|
||||
|
||||
return this.messageLocalDataSourceService.update({...clone, sending: false})
|
||||
// console.log({clone})
|
||||
console.log('update message')
|
||||
//return this.messageLocalDataSourceService.update({...clone, sending: false})
|
||||
return ok(true)
|
||||
}
|
||||
|
||||
} else {
|
||||
return this.messageLocalDataSourceService.update({sending: false})
|
||||
// return this.messageLocalDataSourceService.update({sending: false})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,7 +86,7 @@ export class MessageRepositoryService {
|
||||
if(result.isOk()) {
|
||||
if(result.value) {
|
||||
|
||||
return await this.messageLiveSignalRDataSourceService.sendReadAt({roomId, memberId: SessionStore.user.UserId, chatMessageId: result.value.messageId})
|
||||
// return await this.messageLiveSignalRDataSourceService.sendReadAt({roomId, memberId: SessionStore.user.UserId, chatMessageId: result.value.messageId})
|
||||
}
|
||||
return ok(true)
|
||||
}
|
||||
@@ -116,6 +120,14 @@ export class MessageRepositoryService {
|
||||
}
|
||||
|
||||
sendTyping(roomId) {
|
||||
return this.messageLiveSignalRDataSourceService.sendTyping({roomId, UserName:SessionStore.user.FullName})
|
||||
return this.messageLiveSignalRDataSourceService.sendTyping({
|
||||
roomId,
|
||||
UserName:SessionStore.user.FullName,
|
||||
userId: SessionStore.user.UserId
|
||||
})
|
||||
}
|
||||
|
||||
getMemberByLive({roomId, userId}) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -64,7 +64,7 @@ export class RoomRepositoryService {
|
||||
// },
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.createRoom(roomData)
|
||||
this.roomLocalDataSourceService.createRoom(roomData.chatRoom)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
@@ -78,7 +78,7 @@ export class RoomRepositoryService {
|
||||
// },
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
this.roomLocalDataSourceService.updateRoom(roomData.chatRoom)
|
||||
}
|
||||
|
||||
for( const roomData of roomsToDelete) {
|
||||
@@ -105,15 +105,15 @@ export class RoomRepositoryService {
|
||||
|
||||
if(result.isOk()) {
|
||||
const localList = await this.roomLocalDataSourceService.getRoomList()
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localList)
|
||||
// const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localList)
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
if(!roomData.createdBy?.wxUserId) {
|
||||
delete roomData.createdBy;
|
||||
}
|
||||
// for( const roomData of roomsToUpdate) {
|
||||
// if(!roomData.chatRoom.createdBy?.wxUserId) {
|
||||
// delete roomData.chatRoom.createdBy;
|
||||
// }
|
||||
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
}
|
||||
// this.roomLocalDataSourceService.updateRoom(roomData.chatRoom)
|
||||
// }
|
||||
|
||||
}
|
||||
|
||||
@@ -127,10 +127,13 @@ export class RoomRepositoryService {
|
||||
if(result.isOk()) {
|
||||
|
||||
const localListRoom = await this.roomLocalDataSourceService.getRoomList()
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([result.value.data], localListRoom)
|
||||
const object = {
|
||||
chatRoom: result.value.data
|
||||
}
|
||||
const { roomsToDelete, roomsToInsert, roomsToUpdate } = roomListDetermineChanges([object], localListRoom)
|
||||
|
||||
for( const roomData of roomsToUpdate) {
|
||||
this.roomLocalDataSourceService.updateRoom(roomData)
|
||||
this.roomLocalDataSourceService.updateRoom(roomData.chatRoom)
|
||||
}
|
||||
|
||||
// ============================
|
||||
|
||||
@@ -88,8 +88,8 @@ export class SignalRService {
|
||||
this.establishConnection()
|
||||
}
|
||||
|
||||
async sendTyping({roomId, UserName}) {
|
||||
return await this.connection.typing({ roomId, UserName})
|
||||
async sendTyping({roomId, UserName, userId}) {
|
||||
return await this.connection.typing({ roomId, UserName, userId})
|
||||
}
|
||||
|
||||
async sendReadAt({ roomId, memberId, chatMessageId}) {
|
||||
|
||||
@@ -108,14 +108,20 @@ export class SignalRConnection {
|
||||
})
|
||||
}
|
||||
|
||||
public async typing(data: Object & { roomId, UserName}):Promise<Result<any, any>> {
|
||||
public async typing(data: Object & { roomId, UserName, userId }):Promise<Result<any, any>> {
|
||||
return new Promise((resolve, reject) => {
|
||||
|
||||
const requestId = uuidv4()
|
||||
if(this.connectionStateSubject.value == true) {
|
||||
console.log('send typing', data)
|
||||
|
||||
try {
|
||||
this.hubConnection.invoke("Typing", {userName: data.UserName, roomId: data.roomId, requestId} as any)
|
||||
this.hubConnection.invoke("Typing", {
|
||||
userName: data.UserName,
|
||||
roomId: data.roomId,
|
||||
userId: data.userId +'',
|
||||
requestId
|
||||
} as any)
|
||||
|
||||
} catch (error) {}
|
||||
|
||||
|
||||
@@ -1,6 +1,8 @@
|
||||
import { metrics } from '@opentelemetry/api';
|
||||
import { OTLPMetricExporter } from '@opentelemetry/exporter-metrics-otlp-http';
|
||||
import { MeterProvider, PeriodicExportingMetricReader } from '@opentelemetry/sdk-metrics';
|
||||
import { Subject } from 'rxjs';
|
||||
import { throttleTime } from 'rxjs/operators';
|
||||
import { environment } from 'src/environments/environment';
|
||||
|
||||
// Initialize OpenTelemetry metrics
|
||||
@@ -10,15 +12,28 @@ metrics.setGlobalMeterProvider(meterProvider);
|
||||
if (window.location.protocol !== 'https:' && environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
|
||||
const metricReader = new PeriodicExportingMetricReader({
|
||||
exporter: new OTLPMetricExporter({
|
||||
url: 'http://5-180-182-151.cloud-xip.com:4318/v1/metrics',
|
||||
url: 'https://5-180-182-151.cloud-xip.com:85/collector2/v1/metrics',
|
||||
// headers: {
|
||||
// 'Authorization': 'Basic ' + btoa('tabteste@006:tabteste@006'),
|
||||
// }
|
||||
}),
|
||||
exportIntervalMillis: 3000,
|
||||
exportIntervalMillis: 30000,
|
||||
});
|
||||
|
||||
meterProvider.addMetricReader(metricReader);
|
||||
|
||||
const subject = new Subject()
|
||||
|
||||
subject
|
||||
.pipe(
|
||||
throttleTime(5000) // 5000 milliseconds = 5 seconds
|
||||
)
|
||||
.subscribe(() => {
|
||||
metricReader.forceFlush().then(() => {
|
||||
console.log('Metrics exported');
|
||||
});
|
||||
});
|
||||
|
||||
}
|
||||
export const meter = meterProvider.getMeter('example-exporter-collector');
|
||||
export const RequestCounter = meter.createCounter('post_requests', {
|
||||
|
||||
@@ -3,6 +3,7 @@ import { WebTracerProvider } from '@opentelemetry/sdk-trace-web';
|
||||
import { ZipkinExporter } from '@opentelemetry/exporter-zipkin';
|
||||
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'
|
||||
import { Resource } from '@opentelemetry/resources';
|
||||
import { OTLPTraceExporter } from '@opentelemetry/exporter-otlp-http';
|
||||
import { context, trace, propagation } from '@opentelemetry/api';
|
||||
|
||||
function createProvider(serviceName) {
|
||||
@@ -35,7 +36,6 @@ export const OpentelemetryInterceptorProvider = createProvider('FO-interceptor')
|
||||
export const OpentelemetryPublicationProvider = createProvider('FO-publication-service');
|
||||
export const OpentelemetryLogging = createProvider('logging');
|
||||
|
||||
|
||||
const tracerInstance = OpentelemetryAgendaProvider.getTracer('example-tracer-hole', '111', {})
|
||||
|
||||
|
||||
@@ -84,4 +84,4 @@ function childSpanExample(parentContext) {
|
||||
}, 500);
|
||||
}
|
||||
|
||||
parentSpanExample()
|
||||
// parentSpanExample()
|
||||
|
||||
@@ -8,7 +8,9 @@ import { environment } from 'src/environments/environment';
|
||||
import { UseCaseCounter } from './matrix';
|
||||
import { openTelemetryLogging } from './logging';
|
||||
// import { context, propagation } from '@opentelemetry/api';
|
||||
|
||||
import {
|
||||
SpanStatus, SpanStatusCode
|
||||
} from '@opentelemetry/api';
|
||||
const tracerInstance = OpentelemetryAgendaProvider.getTracer('example-tracer-hole', '111', {})
|
||||
const tracerNotificationInstance = OpentelemetryNotificationProvider.getTracer('example-tracer-hole', '111', {})
|
||||
// const logger: ILoggerAdapter = new ColoredLoggerService()
|
||||
@@ -53,15 +55,16 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
|
||||
|
||||
const data = {
|
||||
event: {},
|
||||
tags: {}
|
||||
tags: {},
|
||||
status: {} as any,
|
||||
}
|
||||
|
||||
return {
|
||||
const returnObject = {
|
||||
span: span as any,
|
||||
tracer: tracerInstance,
|
||||
tracerId: requestId,
|
||||
attributes: SemanticAttributes,
|
||||
setStatus: (status: any) => {
|
||||
setStatus: (status: SpanStatus) => {
|
||||
span.setStatus(status);
|
||||
},
|
||||
addEvent: (context: string, message?: any, obj?: any) => {
|
||||
@@ -79,7 +82,7 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
|
||||
span.setAttribute(key, value);
|
||||
|
||||
if(key =='outcome' && value == 'failed') {
|
||||
span.setAttribute('error', 'true')
|
||||
returnObject.hasError('error')
|
||||
}
|
||||
},
|
||||
log(message: string, data: Object) {
|
||||
@@ -110,18 +113,25 @@ const createTracingInstance = ({bugPrint, name, module, autoFinish}): TracingTyp
|
||||
finish: () => {
|
||||
if(environment.apiURL != 'https://gdqas-api.oapr.gov.ao/api/') {
|
||||
span.end();
|
||||
UseCaseCounter.add(1, {user: SessionStore?.user?.FullName, outcome:data.tags['outcome'], usecase: name})
|
||||
UseCaseCounter.add(1, {user: SessionStore?.user?.FullName, outcome:data.tags['outcome'] || data.status?.code , usecase: name})
|
||||
}
|
||||
|
||||
if(bugPrint && data.tags['outcome'] == 'failed') {
|
||||
if(bugPrint && (data.tags['outcome'] == 'failed' || data.status?.code == SpanStatusCode.ERROR)) {
|
||||
console.error(name, data)
|
||||
}
|
||||
},
|
||||
bugFlag:() => {},
|
||||
hasError:(message: string) => {
|
||||
if(data.status?.code != SpanStatusCode.ERROR) {
|
||||
data.status = {code: SpanStatusCode.ERROR, message}
|
||||
span.setStatus({code: SpanStatusCode.ERROR, message})
|
||||
span.setAttribute('outcome','failed')
|
||||
}
|
||||
},
|
||||
createSpan: (name, parent?: any) => {
|
||||
return tracerInstance.startSpan(name, { root: false }, parent) as Span;
|
||||
}
|
||||
}
|
||||
return returnObject
|
||||
}
|
||||
|
||||
export function XTracerAsync({ name, bugPrint, module = null, autoFinish = true, daley =0 }) {
|
||||
@@ -221,7 +231,7 @@ export type TracingType = {
|
||||
getAttribute: (key: string) => string;
|
||||
LocalLogEvent: (name: string, attributesOrStartTime: any, obj?:any) => void;
|
||||
finish: () => void;
|
||||
bugFlag:() => void;
|
||||
hasError:(message: string) => void;
|
||||
createSpan:(name, parent?: any) => Span;
|
||||
};
|
||||
|
||||
|
||||
@@ -153,6 +153,7 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
}
|
||||
|
||||
ngOnChanges(changes: SimpleChanges): void {
|
||||
console.log('change ¬!!')
|
||||
this.roomData$ = this.roomRepositoryService.getItemByIdLive(this.roomId)
|
||||
this.roomMessage$ = this.messageRepositoryService.getItemsLive(this.roomId)
|
||||
this.roomMembers$ = this.roomRepositoryService.getRoomMemberByIdLive(this.roomId) as any
|
||||
@@ -179,9 +180,10 @@ export class MessagesPage implements OnInit, OnChanges, AfterViewInit, OnDestroy
|
||||
this.scrollToBottomClicked()
|
||||
}, 200)
|
||||
|
||||
this.messageRepositoryService.sendReadAt({roomId: this.roomId}).then((e) => {
|
||||
console.log(e)
|
||||
})
|
||||
console.log('new message==============')
|
||||
// this.messageRepositoryService.sendReadAt({roomId: this.roomId}).then((e) => {
|
||||
// console.log(e)
|
||||
// })
|
||||
|
||||
})
|
||||
|
||||
|
||||
Reference in New Issue
Block a user