Skip to content

Commit

Permalink
fix(moderation): correctly handle missing hashes when checking blockl…
Browse files Browse the repository at this point in the history
…ist PE-3769

When the cache and DB are empty, we try to lookup a null hash in the
blocklist. This change adjusts the SQLite DB methods to handle that case
without throwing an error.
  • Loading branch information
djwhitt committed Jun 6, 2023
1 parent a338119 commit c8b982f
Showing 1 changed file with 18 additions and 12 deletions.
30 changes: 18 additions & 12 deletions src/database/standalone-sqlite.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1356,18 +1356,24 @@ export class StandaloneSqliteDatabaseWorker {
return block;
}

isIdBlocked(id: string): boolean {
const row = this.stmts.moderation.isIdBlocked.get({
id: fromB64Url(id),
});
return row?.is_blocked === 1;
isIdBlocked(id: string | undefined): boolean {
if (typeof id === 'string' && id.length > 0) {
const row = this.stmts.moderation.isIdBlocked.get({
id: fromB64Url(id),
});
return row?.is_blocked === 1;
}
return false
}

isHashBlocked(hash: string): boolean {
const row = this.stmts.moderation.isHashBlocked.get({
hash: fromB64Url(hash),
});
return row?.is_blocked === 1;
isHashBlocked(hash: string | undefined): boolean {
if (typeof hash === 'string' && hash.length > 0) {
const row = this.stmts.moderation.isHashBlocked.get({
hash: fromB64Url(hash),
});
return row?.is_blocked === 1;
}
return false;
}

blockData({
Expand Down Expand Up @@ -1779,11 +1785,11 @@ export class StandaloneSqliteDatabase
return this.queueRead('gql', 'getGqlBlock', [{ id }]);
}

async isIdBlocked(id: string): Promise<boolean> {
async isIdBlocked(id: string | undefined): Promise<boolean> {
return this.queueRead('moderation', 'isIdBlocked', [id]);
}

async isHashBlocked(hash: string): Promise<boolean> {
async isHashBlocked(hash: string | undefined): Promise<boolean> {
return this.queueRead('moderation', 'isHashBlocked', [hash]);
}

Expand Down

0 comments on commit c8b982f

Please sign in to comment.