add database fields

This commit is contained in:
Peter Maquiran
2024-06-14 09:30:14 +01:00
parent f6dc118fe4
commit 3da412eef6
7 changed files with 49 additions and 389 deletions
@@ -16,6 +16,7 @@ const tableSchema = z.object({
messageType: z.number(),
canEdit: z.boolean(),
oneShot: z.boolean(),
sentAt: z.string().optional(),
requireUnlock: z.boolean(),
sender: z.object({
wxUserId: z.number(),
@@ -49,7 +50,7 @@ export class MessageLocalDataSourceService {
messageDataSource.message.hook('creating', (primKey, obj, trans) => {
// const newMessage = await trans.table('message').get(primKey);
this.messageSubject.next(obj);
this.messageSubject.next(obj);
// return newMessage
})
}
@@ -103,8 +104,8 @@ export class MessageLocalDataSourceService {
}
}
getItemsLive(roomId: string) {
return liveQuery(() =>
getItemsLive(roomId: string) {
return liveQuery(() =>
messageDataSource.message.where('roomId').equals(roomId).sortBy('id')
)
}
@@ -12,7 +12,7 @@ const tableSchema = z.object({
wxUserId: z.number(),
wxFullName: z.string(),
wxeMail: z.string().email(),
userPhoto: z.string().nullable()// api check
userPhoto: z.string().nullable().optional()// api check
}),
createdAt: z.any(),
expirationDate: z.any(),
@@ -30,6 +30,14 @@ const TableMemberListSchema = z.object({
userPhoto: z.string().nullable(),
}),
joinAt: z.string(),
// lastMessage: z.object({
// sentAt: z.string(),
// message: z.string(),
// sender: z.object({
// wxUserId: z.number(),
// wxFullName: z.string(),
// }).optional(),
// })
})
export type TableRoom = z.infer<typeof tableSchema>
@@ -35,12 +35,12 @@ export class WebSocketService {
this.connect('http://5.180.182.151:8080/')
this.messages$.subscribe(({payload, requestId}) => {
this.messages$.subscribe(({payload, requestId, type}) => {
if(this.callback[requestId]) {
this.callback[requestId]({payload, requestId})
this.callback[requestId]({payload, requestId, type})
delete this.callback[requestId]
}
})
}
@@ -89,7 +89,7 @@ export class WebSocketService {
public sendMessage(message: WebSocketMessage): Observable<any> {
return new Observable<void>(observer => {
if(typeof message == 'object') {
message.requestId = uuidv4()
@@ -107,7 +107,7 @@ export class WebSocketService {
}
}).pipe(
catchError(err => {
console.error('Send message error:', err);
@@ -126,4 +126,4 @@ export class WebSocketService {
public get connectionStatus(): Observable<boolean> {
return this.connectionStatus$.asObservable();
}
}
}
@@ -15,28 +15,27 @@ export class MessageRepositoryService {
private messageLiveDataSourceService: MessageLiveDataSourceService,
private messageLocalDataSourceService: MessageLocalDataSourceService
) {
this.messageLiveDataSourceService.socket.messages$.subscribe(({payload, requestId}) => {
this.messageLiveDataSourceService.socket.messages$.subscribe(({payload, requestId, type}) => {
if(payload.sender == null) {
delete payload.sender
}
if(payload) {
if(type == 'sendMessage') {
let clone: TableMessage = {
...payload,
messageId: payload.id,
}
delete clone.id
try {
if(clone.sender.wxUserId != SessionStore.user.UserId) {
this.messageLocalDataSourceService.createMessage(clone)
}
this.messageLocalDataSourceService.createMessage(clone)
} catch (e) {
//console.log('error', {payload})
}
} else if (type == 'deleteMessage') {
}
@@ -107,6 +106,6 @@ export class MessageRepositoryService {
subscribeToNewMessages(roomId: any) {
return this.messageLocalDataSourceService.subscribeToNewMessage(roomId)
return this.messageLocalDataSourceService.subscribeToNewMessage(roomId)
}
}
@@ -14,6 +14,7 @@ import { RoomUpdateInputDTO } from '../dto/room/roomUpdateInputDTO';
import { SessionStore } from 'src/app/store/session.service';
import { RoomLiveDataSourceService } from '../data-source/room/room-live-data-source.service';
import { isHttpResponse } from 'src/app/services/http.service';
import { value } from '../../../../../../../_________________/src/plugin/src/sql/Operators/args-attributes';
@Injectable({
providedIn: 'root'
@@ -144,12 +145,14 @@ export class RoomRepositoryService {
result.value.data.createdBy = {
wxeMail: SessionStore.user.Email,
wxFullName: SessionStore.user.FullName,
wxUserId: SessionStore.user.UserId
wxUserId: SessionStore.user.UserId,
}
}
this.roomMemoryDataSourceService.dispatch(addRoom(result.value))
this.roomLocalDataSourceService.createRoom(result.value.data)
const localResult = await this.roomLocalDataSourceService.createRoom(result.value.data)
return localResult.map(e => result.value)
}
return result