Skip to content

Commit

Permalink
Ozone: temporary workaround for message refs on createReport (#2521)
Browse files Browse the repository at this point in the history
* ozone: temporary workaround for message refs on createReport

* ozone: defensive around query label failure
  • Loading branch information
devinivy authored May 24, 2024
1 parent 7e37fd3 commit 75b7848
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 15 deletions.
16 changes: 12 additions & 4 deletions packages/ozone/src/mod-service/subject.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,21 @@ export const subjectFromInput = (
) {
return new RecordSubject(subject.uri, subject.cid, blobs)
}
// @NOTE #messageRef is not a report input for com.atproto.moderation.createReport.
// we are taking advantage of the open union in order for bsky.chat to interoperate here.
if (
subject.$type === 'chat.bsky.convo.defs#messageRef' &&
typeof subject.did === 'string' &&
typeof subject.convoId === 'string' &&
(typeof subject.convoId === 'string' || subject.convoId === undefined) &&
typeof subject.messageId === 'string'
) {
return new MessageSubject(subject.did, subject.convoId, subject.messageId)
// @TODO we should start to require subject.convoId is a string in order to properly validate
// the #messageRef. temporarily allowing it to be optional as a stopgap for rollout.
return new MessageSubject(
subject.did,
subject.convoId ?? '',
subject.messageId,
)
}

throw new InvalidRequestError('Invalid subject')
Expand Down Expand Up @@ -87,7 +95,7 @@ type SubjectInfo = {
subjectCid: string | null
subjectBlobCids: string[] | null
subjectMessageId: string | null
meta: Record<string, string> | null
meta: Record<string, string | undefined> | null
}

export interface ModSubject {
Expand Down Expand Up @@ -200,7 +208,7 @@ export class MessageSubject implements ModSubject {
subjectCid: null,
subjectBlobCids: null,
subjectMessageId: this.messageId,
meta: { convoId: this.convoId },
meta: { convoId: this.convoId || undefined },
}
}
lex(): MessageRef {
Expand Down
24 changes: 15 additions & 9 deletions packages/ozone/src/mod-service/views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -338,15 +338,21 @@ export class ModerationViews {
labelers?: ParsedLabelers,
): Promise<Label[]> {
if (!labelers?.dids.length && !labelers?.redact.size) return []

const {
data: { labels },
} = await this.appviewAgent.api.com.atproto.label.queryLabels({
uriPatterns: subjects,
sources: labelers.dids,
})

return labels
try {
const {
data: { labels },
} = await this.appviewAgent.api.com.atproto.label.queryLabels({
uriPatterns: subjects,
sources: labelers.dids,
})
return labels
} catch (err) {
httpLogger.error(
{ err, subjects, labelers },
'failed to resolve labels from appview',
)
return []
}
}

formatReport(report: ModerationEventRowWithHandle): ReportOutput {
Expand Down
2 changes: 1 addition & 1 deletion packages/ozone/tests/__snapshots__/moderation.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ Array [
"reportedBy": "user(1)",
"subject": Object {
"$type": "chat.bsky.convo.defs#messageRef",
"convoId": "testconvoid2",
"convoId": "",
"did": "user(1)",
"messageId": "testmessageid2",
},
Expand Down
2 changes: 1 addition & 1 deletion packages/ozone/tests/moderation.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ describe('moderation', () => {
$type: 'chat.bsky.convo.defs#messageRef',
did: sc.dids.carol,
messageId: messageId2,
convoId: 'testconvoid2',
// @TODO convoId intentionally missing, restore once this behavior is deprecated
},
})
expect(forSnapshot([reportA, reportB])).toMatchSnapshot()
Expand Down

0 comments on commit 75b7848

Please sign in to comment.