Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F32412207
D4941.1765346105.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D4941.1765346105.diff
View Options
diff --git a/keyserver/src/creators/message-report-creator.js b/keyserver/src/creators/message-report-creator.js
new file mode 100644
--- /dev/null
+++ b/keyserver/src/creators/message-report-creator.js
@@ -0,0 +1,68 @@
+// @flow
+
+import bots from 'lib/facts/bots';
+import { createMessageReply } from 'lib/shared/message-utils';
+import { type MessageReportCreationRequest } from 'lib/types/message-report-types';
+import { messageTypes } from 'lib/types/message-types';
+
+import { createCommbotThread } from '../bots/commbot';
+import { fetchPersonalThreadID } from '../fetchers/thread-fetchers';
+import { fetchUsername } from '../fetchers/user-fetchers';
+import { createBotViewer } from '../session/bots';
+import type { Viewer } from '../session/viewer';
+import createMessages from './message-creator';
+
+const { commbot } = bots;
+
+async function createMessageReport(
+ viewer: Viewer,
+ request: MessageReportCreationRequest,
+ recipientID: string,
+) {
+ await sendCommbotMessage(viewer, request, recipientID);
+}
+
+async function sendCommbotMessage(
+ viewer: Viewer,
+ request: MessageReportCreationRequest,
+ recipientID: string,
+) {
+ const usernamePromise = fetchUsername(viewer.id);
+
+ let threadID = await fetchPersonalThreadID(recipientID, commbot.userID);
+ if (!threadID) {
+ threadID = await createCommbotThread(recipientID);
+ }
+
+ const username = await usernamePromise;
+ const message = getCommbotMessage(request, username);
+ const time = Date.now();
+ await createMessages(createBotViewer(commbot.userID), [
+ {
+ type: messageTypes.TEXT,
+ threadID,
+ creatorID: commbot.userID,
+ time,
+ text: message,
+ },
+ ]);
+}
+
+function getCommbotMessage(
+ request: MessageReportCreationRequest,
+ reporterUsername: ?string,
+): string {
+ reporterUsername = reporterUsername ?? '[null]';
+ const messageAuthor = request.messageAuthorInfo.username
+ ? `${request.messageAuthorInfo.username}’s`
+ : 'this';
+ const thread = request.thread?.name
+ ? `chat titled "${request.thread.name}"`
+ : 'chat';
+ return (
+ `user ${reporterUsername} reported ${messageAuthor} message in ${thread}\n` +
+ createMessageReply(request.message)
+ );
+}
+
+export default createMessageReport;
diff --git a/lib/types/message-report-types.js b/lib/types/message-report-types.js
new file mode 100644
--- /dev/null
+++ b/lib/types/message-report-types.js
@@ -0,0 +1,10 @@
+// @flow
+
+import { type RawThreadInfo } from './thread-types';
+import type { UserInfo } from './user-types';
+
+export type MessageReportCreationRequest = {
+ +thread: RawThreadInfo,
+ +messageAuthorInfo: UserInfo,
+ +message: string,
+};
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Dec 10, 5:55 AM (16 h, 57 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5861588
Default Alt Text
D4941.1765346105.diff (2 KB)
Attached To
Mode
D4941: [keyserver] Add message report creator
Attached
Detach File
Event Timeline
Log In to Comment