mirror of
https://code.equilibrium.co.ao/ITO/doneit-web.git
synced 2026-04-21 05:45:50 +00:00
create offline direct message
This commit is contained in:
@@ -6,7 +6,7 @@ export const MessageTableSchema = z.object({
|
||||
$id: z.string().optional(),
|
||||
$createAt: z.number().optional(),
|
||||
id: z.string().uuid().optional(),
|
||||
roomId: z.string().uuid().optional(),
|
||||
roomId: z.string().optional(),
|
||||
message: z.string().nullable().optional(),
|
||||
requestId: z.string().nullable().optional(),
|
||||
messageType: z.number(),
|
||||
@@ -50,5 +50,5 @@ export const MessageTableSchema = z.object({
|
||||
|
||||
export type MessageTable = z.infer<typeof MessageTableSchema>
|
||||
export type DexieMessageTable = EntityTable<MessageTable, '$id'>;
|
||||
export const messageTableColumn = '$id, id, roomId, senderId, message, messageType, canEdit, oneShot, requireUnlock, sending'
|
||||
export const messageTableColumn = '$id, id, roomId, senderId, receiverId, message, messageType, canEdit, oneShot, requireUnlock, sending'
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { z } from "zod";
|
||||
import { EntityTable } from 'Dexie';
|
||||
import { RoomType } from "src/app/core/chat/entity/group";
|
||||
import { MessageEntity, MessageEntitySchema } from "src/app/core/chat/entity/message";
|
||||
import { MessageTableSchema } from "./message";
|
||||
import { IDBoolean } from "../../../type";
|
||||
|
||||
export const RoomTableSchema = z.object({
|
||||
id: z.string().uuid(),
|
||||
$id: z.string().optional(),
|
||||
id: z.string().optional(),
|
||||
roomName: z.string(),
|
||||
createdBy: z.object({
|
||||
wxUserId: z.number(),
|
||||
@@ -14,12 +15,14 @@ export const RoomTableSchema = z.object({
|
||||
userPhoto: z.string().nullable().optional()// api check
|
||||
}),
|
||||
createdAt: z.any(),
|
||||
expirationDate: z.any().nullable(),
|
||||
expirationDate: z.string().nullable().optional(),
|
||||
roomType: z.nativeEnum(RoomType),
|
||||
messages: MessageTableSchema.array().optional(),
|
||||
bold: z.number().optional()
|
||||
bold: z.number().optional(),
|
||||
local: z.nativeEnum(IDBoolean).optional(),
|
||||
receiverId: z.number().optional()
|
||||
})
|
||||
|
||||
export type RoomTable = z.infer<typeof RoomTableSchema>
|
||||
export type DexieRoomsTable = EntityTable<RoomTable, 'id'>;
|
||||
export const RoomTableColumn = 'id, createdBy, roomName, roomType, expirationDate, lastMessage'
|
||||
export type DexieRoomsTable = EntityTable<RoomTable, '$id'>;
|
||||
export const RoomTableColumn = '$id, id, createdBy, receiverId, roomName, roomType, expirationDate, lastMessage'
|
||||
|
||||
@@ -0,0 +1,4 @@
|
||||
export enum IDBoolean {
|
||||
false = 0,
|
||||
true = 1
|
||||
}
|
||||
@@ -3,20 +3,22 @@ import Dexie, { EntityTable, Table } from 'Dexie';
|
||||
import { ZodError, ZodObject, ZodSchema } from 'zod';
|
||||
import { Logger } from 'src/app/services/logger/main/service';
|
||||
import { IDexieRepository, RepositoryResult } from '../adapter'
|
||||
import { IDBError, IDexieError } from '../types';
|
||||
import { IDBError, IDBErrorParams, IDexieError } from '../types';
|
||||
|
||||
// Define a type for the Result of repository operations
|
||||
|
||||
class DBError<T> extends Error implements IDBError<T> {
|
||||
zodError?: ZodError<T>;
|
||||
parameters: T;
|
||||
error?: IDexieError;
|
||||
error: IDexieError;
|
||||
DBErrorName?: 'NotFoundError' | 'ConstraintError'
|
||||
|
||||
constructor(data: IDBError<T>) {
|
||||
constructor(data: IDBErrorParams<T>) {
|
||||
super(data.message);
|
||||
this.zodError = data.zodError;
|
||||
this.parameters = data.parameters;
|
||||
this.error = data.error;
|
||||
this.DBErrorName = data.error?.name as any;
|
||||
|
||||
Logger.error(data.message, {
|
||||
zodError: this.zodError,
|
||||
@@ -74,7 +76,7 @@ export class DexieRepository<T, R, I = EntityTable<any, any>> implements IDexieR
|
||||
return err(new DBError({
|
||||
message: `dexie.js failed to insert into ${this.table.name}, ${error.message}`,
|
||||
parameters: document,
|
||||
error: error
|
||||
error: error,
|
||||
}))
|
||||
}
|
||||
} else {
|
||||
|
||||
@@ -38,6 +38,14 @@ import { ZodError } from "zod"
|
||||
// };
|
||||
|
||||
export type IDBError<T> = {
|
||||
message: string,
|
||||
zodError?: ZodError<T>,
|
||||
parameters?: T,
|
||||
error?: IDexieError,
|
||||
DBErrorName?: 'NotFoundError' | 'ConstraintError'
|
||||
}
|
||||
|
||||
export type IDBErrorParams<T> = {
|
||||
message: string,
|
||||
zodError?: ZodError<T>,
|
||||
parameters?: T,
|
||||
|
||||
@@ -4,7 +4,7 @@ import { Platform } from '@ionic/angular';
|
||||
import { SignalRConnection, SocketMessage } from './signalR';
|
||||
import { Plugins } from '@capacitor/core';
|
||||
import { switchMap } from 'rxjs/operators';
|
||||
import { Result } from 'neverthrow';
|
||||
import { err, Result } from 'neverthrow';
|
||||
import { HubConnection } from '@microsoft/signalr';
|
||||
import { ISignalRInput } from '../type';
|
||||
|
||||
@@ -81,8 +81,12 @@ export class SignalRService {
|
||||
}
|
||||
}
|
||||
|
||||
sendData<T>(input: ISignalRInput) {
|
||||
return this.connection.sendData<T>(input)
|
||||
async sendData<T>(input: ISignalRInput) {
|
||||
try {
|
||||
return await this.connection.sendData<T>(input)
|
||||
} catch (e) {
|
||||
return err('havent connected yet')
|
||||
}
|
||||
}
|
||||
|
||||
join() {
|
||||
|
||||
@@ -145,7 +145,7 @@ export class SignalRConnection {
|
||||
|
||||
} else {
|
||||
this.sendLaterSubject.next({method: 'SendMessage', args: input})
|
||||
return reject(err(false))
|
||||
return resolve(err(false))
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user