Skip to content

Commit

Permalink
[keyserver][lib] Allow not specifying messageID in message report res…
Browse files Browse the repository at this point in the history
…ponder

Summary:
We want to allow reporting E2EE messages, but without the contents.

Depends on D13459

Test Plan: Confirm that pressing "Report" on a thick thread message no longer leads to an error, and confirm that the authoritative keyserver admin gets a message that looks like this: {F2805570}

Reviewers: kamil, tomek

Reviewed By: tomek

Differential Revision: https://phab.comm.dev/D13460
  • Loading branch information
Ashoat committed Sep 25, 2024
1 parent ee4699a commit 81307fb
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 10 deletions.
11 changes: 7 additions & 4 deletions keyserver/src/creators/message-report-creator.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,13 @@ async function fetchMessageReportData(
request: MessageReportCreationRequest,
): Promise<MessageReportData> {
const keyserverAdminIDPromise = fetchKeyserverAdminID();
const reportedMessagePromise = fetchMessageInfoByID(
viewer,
request.messageID,
);
const reportedMessagePromise = (async () => {
const { messageID } = request;
if (!messageID) {
return null;
}
return await fetchMessageInfoByID(viewer, messageID);
})();
const viewerUsernamePromise = fetchUsername(viewer.id);

const keyserverAdminID = await keyserverAdminIDPromise;
Expand Down
4 changes: 2 additions & 2 deletions keyserver/src/responders/message-report-responder.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// @flow

import type { TInterface } from 'tcomb';
import t, { type TInterface } from 'tcomb';

import {
type MessageReportCreationRequest,
Expand All @@ -13,7 +13,7 @@ import type { Viewer } from '../session/viewer.js';

export const messageReportCreationRequestInputValidator: TInterface<MessageReportCreationRequest> =
tShape<MessageReportCreationRequest>({
messageID: tID,
messageID: t.maybe(tID),
});

async function messageReportCreationResponder(
Expand Down
12 changes: 9 additions & 3 deletions lib/actions/message-report-actions.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
// @flow

import { extractKeyserverIDFromID } from '../keyserver-conn/keyserver-call-utils.js';
import { extractKeyserverIDFromIDOptional } from '../keyserver-conn/keyserver-call-utils.js';
import { useKeyserverCall } from '../keyserver-conn/keyserver-call.js';
import type { CallKeyserverEndpoint } from '../keyserver-conn/keyserver-conn-types.js';
import type {
MessageReportCreationRequest,
MessageReportCreationResult,
} from '../types/message-report-types.js';
import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js';

const sendMessageReportActionTypes = Object.freeze({
started: 'SEND_MESSAGE_REPORT_STARTED',
Expand All @@ -20,8 +21,13 @@ const sendMessageReport =
input: MessageReportCreationRequest,
) => Promise<MessageReportCreationResult>) =>
async input => {
const keyserverID = extractKeyserverIDFromID(input.messageID);
const requests = { [keyserverID]: input };
const messageKeyserverID = input.messageID
? extractKeyserverIDFromIDOptional(input.messageID)
: null;
const keyserverID: string =
messageKeyserverID ?? authoritativeKeyserverID();
const messageID = messageKeyserverID ? input.messageID : null;
const requests = { [keyserverID]: { messageID } };

const responses = await callKeyserverEndpoint(
'create_message_report',
Expand Down
2 changes: 1 addition & 1 deletion lib/types/message-report-types.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import type { RawMessageInfo } from './message-types.js';

export type MessageReportCreationRequest = {
+messageID: string,
+messageID: ?string,
};

export type MessageReportCreationResult = {
Expand Down

0 comments on commit 81307fb

Please sign in to comment.