feat: Security
This commit is contained in:
@@ -23,6 +23,8 @@ export interface MessageRow {
|
||||
linkMetadata?: string | null;
|
||||
kind?: string | null;
|
||||
systemEvent?: string | null;
|
||||
revision?: number | null;
|
||||
headHash?: string | null;
|
||||
}
|
||||
|
||||
export interface UserRow {
|
||||
@@ -102,7 +104,9 @@ export function messageToRow(message: Message): MessageRow {
|
||||
replyToId: message.replyToId ?? null,
|
||||
linkMetadata: encodeJson(message.linkMetadata),
|
||||
kind: message.kind ?? null,
|
||||
systemEvent: message.systemEvent ?? null
|
||||
systemEvent: message.systemEvent ?? null,
|
||||
revision: message.revision ?? 0,
|
||||
headHash: message.headHash ?? null
|
||||
};
|
||||
}
|
||||
|
||||
@@ -116,6 +120,8 @@ export function rowToMessage(row: MessageRow, reactions: Reaction[] = []): Messa
|
||||
content: row.content,
|
||||
timestamp: row.timestamp,
|
||||
editedAt: row.editedAt ?? undefined,
|
||||
revision: row.revision ?? 0,
|
||||
headHash: row.headHash ?? undefined,
|
||||
isDeleted: row.isDeleted === 1,
|
||||
replyToId: row.replyToId ?? undefined,
|
||||
linkMetadata: decodeJson(row.linkMetadata),
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
export const MOBILE_SQLITE_DATABASE_NAME = 'metoyou';
|
||||
|
||||
/** Bump when adding DDL statements; stored in meta table. */
|
||||
export const MOBILE_SQLITE_SCHEMA_VERSION = 2;
|
||||
export const MOBILE_SQLITE_SCHEMA_VERSION = 3;
|
||||
|
||||
const META_SCHEMA_VERSION_KEY = 'mobile_sqlite_schema_version';
|
||||
|
||||
@@ -23,7 +23,9 @@ export function buildMobileSqliteSchemaStatements(): string[] {
|
||||
replyToId TEXT,
|
||||
linkMetadata TEXT,
|
||||
kind TEXT,
|
||||
systemEvent TEXT
|
||||
systemEvent TEXT,
|
||||
revision INTEGER NOT NULL DEFAULT 0,
|
||||
headHash TEXT
|
||||
)`,
|
||||
'CREATE INDEX IF NOT EXISTS idx_messages_room_id ON messages(roomId)',
|
||||
'CREATE INDEX IF NOT EXISTS idx_messages_timestamp ON messages(timestamp)',
|
||||
@@ -136,6 +138,11 @@ const SCHEMA_V2_MESSAGE_COLUMNS = [
|
||||
'ALTER TABLE messages ADD COLUMN systemEvent TEXT'
|
||||
];
|
||||
|
||||
const SCHEMA_V3_MESSAGE_COLUMNS = [
|
||||
'ALTER TABLE messages ADD COLUMN revision INTEGER NOT NULL DEFAULT 0',
|
||||
'ALTER TABLE messages ADD COLUMN headHash TEXT'
|
||||
];
|
||||
|
||||
/** Returns DDL statements that still need to run for the stored schema version. */
|
||||
export function resolveMobileSqliteMigrationStatements(storedVersion: number): string[] {
|
||||
if (storedVersion >= MOBILE_SQLITE_SCHEMA_VERSION) {
|
||||
@@ -153,5 +160,10 @@ export function resolveMobileSqliteMigrationStatements(storedVersion: number): s
|
||||
statements.push(`INSERT OR REPLACE INTO meta (key, value) VALUES ('${META_SCHEMA_VERSION_KEY}', '2')`);
|
||||
}
|
||||
|
||||
if (storedVersion < 3) {
|
||||
statements.push(...SCHEMA_V3_MESSAGE_COLUMNS);
|
||||
statements.push(`INSERT OR REPLACE INTO meta (key, value) VALUES ('${META_SCHEMA_VERSION_KEY}', '3')`);
|
||||
}
|
||||
|
||||
return statements;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user