diff --git a/app/actions/local/file.test.ts b/app/actions/local/file.test.ts index a2c0231ad..b40cb1647 100644 --- a/app/actions/local/file.test.ts +++ b/app/actions/local/file.test.ts @@ -7,6 +7,7 @@ import { updateLocalFile, updateLocalFilePath, getLocalFileInfo, + setFileAsBlocked, } from './file'; import type ServerDataOperator from '@database/operator/server_data_operator'; @@ -72,4 +73,28 @@ describe('files', () => { expect(file).toBeDefined(); expect(file!.id).toBe(fileInfo.id); }); + + it('setFileAsBlocked - handle not found database', async () => { + const {error} = await setFileAsBlocked('foo', fileInfo.id!); + expect(error).toBeTruthy(); + }); + + it('setFileAsBlocked', async () => { + await operator.handleFiles({files: [fileInfo], prepareRecordsOnly: false}); + + const {error} = await setFileAsBlocked(serverUrl, fileInfo.id!); + expect(error).toBeUndefined(); + + const {file} = await getLocalFileInfo(serverUrl, fileInfo.id!); + expect(file).toBeDefined(); + expect(file!.isBlocked).toBe(true); + }); + + it('setFileAsBlocked - no file', async () => { + const {error} = await setFileAsBlocked(serverUrl, fileInfo.id!); + expect(error).toBeUndefined(); + + const {file} = await getLocalFileInfo(serverUrl, fileInfo.id!); + expect(file).toBeUndefined(); + }); }); diff --git a/app/actions/local/file.ts b/app/actions/local/file.ts index a4fdba9a7..ba6158bd1 100644 --- a/app/actions/local/file.ts +++ b/app/actions/local/file.ts @@ -34,6 +34,24 @@ export const updateLocalFilePath = async (serverUrl: string, fileId: string, loc } }; +export const setFileAsBlocked = async (serverUrl: string, fileId: string) => { + try { + const {database} = DatabaseManager.getServerDatabaseAndOperator(serverUrl); + const file = await getFileById(database, fileId); + if (file) { + await database.write(async () => { + await file.update((r) => { + r.isBlocked = true; + }); + }); + } + return {error: undefined}; + } catch (error) { + logError('Failed setFileAsBlocked', error); + return {error}; + } +}; + export const getLocalFileInfo = async (serverUrl: string, fileId: string) => { try { const {database} = DatabaseManager.getServerDatabaseAndOperator(serverUrl); diff --git a/app/database/migration/server/index.ts b/app/database/migration/server/index.ts index 15ce11106..80a16d6ca 100644 --- a/app/database/migration/server/index.ts +++ b/app/database/migration/server/index.ts @@ -8,9 +8,20 @@ import {addColumns, createTable, schemaMigrations, unsafeExecuteSql} from '@nozb import {MM_TABLES} from '@constants/database'; -const {CHANNEL_BOOKMARK, CHANNEL_INFO, DRAFT, POST, CHANNEL, CUSTOM_PROFILE_ATTRIBUTE, CUSTOM_PROFILE_FIELD, SCHEDULED_POST} = MM_TABLES.SERVER; +const {CHANNEL_BOOKMARK, CHANNEL_INFO, DRAFT, FILE, POST, CHANNEL, CUSTOM_PROFILE_ATTRIBUTE, CUSTOM_PROFILE_FIELD, SCHEDULED_POST} = MM_TABLES.SERVER; export default schemaMigrations({migrations: [ + { + toVersion: 10, + steps: [ + addColumns({ + table: FILE, + columns: [ + {name: 'is_blocked', type: 'boolean'}, + ], + }), + ], + }, { toVersion: 9, steps: [ diff --git a/app/database/models/server/file.ts b/app/database/models/server/file.ts index 96ba7fc2a..7f689b44e 100644 --- a/app/database/models/server/file.ts +++ b/app/database/models/server/file.ts @@ -56,6 +56,9 @@ export default class FileModel extends Model implements FileModelInterface { /** width : The width of the file object/image */ @field('width') width!: number; + /** isBlocked : Whether the file is blocked and cannot be opened */ + @field('is_blocked') isBlocked!: boolean; + /** post : The related Post record for this file */ @immutableRelation(POST, 'post_id') post!: Relation; diff --git a/app/database/operator/server_data_operator/transformers/general.ts b/app/database/operator/server_data_operator/transformers/general.ts index 78fb5b270..2a709049d 100644 --- a/app/database/operator/server_data_operator/transformers/general.ts +++ b/app/database/operator/server_data_operator/transformers/general.ts @@ -157,6 +157,7 @@ export const transformFileRecord = ({action, database, value}: TransformerArgs { it('=> The SERVER SCHEMA should strictly match', () => { expect(serverSchema).toEqual({ - version: 9, + version: 10, unsafeSql: undefined, tables: { [CATEGORY]: { @@ -334,6 +334,7 @@ describe('*** Test schema for SERVER database ***', () => { post_id: {name: 'post_id', type: 'string', isIndexed: true}, size: {name: 'size', type: 'number'}, width: {name: 'width', type: 'number'}, + is_blocked: {name: 'is_blocked', type: 'boolean'}, }, columnArray: [ {name: 'extension', type: 'string'}, @@ -345,6 +346,7 @@ describe('*** Test schema for SERVER database ***', () => { {name: 'post_id', type: 'string', isIndexed: true}, {name: 'size', type: 'number'}, {name: 'width', type: 'number'}, + {name: 'is_blocked', type: 'boolean'}, ], }, [GROUP]: { diff --git a/docs/database/server/server.md b/docs/database/server/server.md index 9be88563f..8cd9e0d15 100644 --- a/docs/database/server/server.md +++ b/docs/database/server/server.md @@ -108,6 +108,7 @@ name string post_id string INDEX FK >- Post.id size number width number +is_blocked bool #Determines if a file has been blocked and cannot be opened anymore Group - diff --git a/ios/patches/SessionDelegate.patch b/ios/patches/SessionDelegate.patch deleted file mode 100644 index 2d20d1405..000000000 --- a/ios/patches/SessionDelegate.patch +++ /dev/null @@ -1,19 +0,0 @@ ---- SessionDelegate.swift.orig 2022-03-12 17:34:07.000000000 -0300 -+++ SessionDelegate.swift 2022-03-16 15:51:22.000000000 -0300 -@@ -292,6 +292,16 @@ - return - } - -+ let allHeaders = (downloadRequest.response)?.allHeaderFields as? NSDictionary ?? NSDictionary() -+ let sizeString = (allHeaders["X-Uncompressed-Content-Length"] ?? allHeaders["x-uncompressed-content-length"]) as? String -+ if (sizeString != nil) { -+ let size = Int64(sizeString!) -+ downloadRequest.updateDownloadProgress(bytesWritten: bytesWritten, -+ totalBytesExpectedToWrite: size!) -+ return -+ -+ } -+ - downloadRequest.updateDownloadProgress(bytesWritten: bytesWritten, - totalBytesExpectedToWrite: totalBytesExpectedToWrite) - } diff --git a/test/test_helper.ts b/test/test_helper.ts index 287b1be0d..2c50d2846 100644 --- a/test/test_helper.ts +++ b/test/test_helper.ts @@ -694,6 +694,7 @@ class TestHelperSingleton { postId: this.generateId(), post: this.fakeRelation(), toFileInfo: jest.fn(), + isBlocked: false, ...overwrite, }; }; diff --git a/types/database/models/servers/file.ts b/types/database/models/servers/file.ts index 1e913605c..793c3d60e 100644 --- a/types/database/models/servers/file.ts +++ b/types/database/models/servers/file.ts @@ -45,6 +45,9 @@ declare class FileModel extends Model { /** post : The related Post record for this file */ post: Relation; + /** isBlocked : Whether the file is blocked and cannot be opened */ + isBlocked: boolean; + toFileInfo: (authorId: string) => FileInfo; }