Page MenuHomePhabricator

[keyserver] Add message report creator
ClosedPublic

Authored by inka on Aug 24 2022, 4:37 AM.
Tags
None
Referenced Files
F3388002: D4941.id15916.diff
Fri, Nov 29, 12:15 PM
F3387941: D4941.id16096.diff
Fri, Nov 29, 11:54 AM
F3387768: D4941.id15953.diff
Fri, Nov 29, 11:05 AM
Unknown Object (File)
Wed, Nov 27, 8:42 AM
Unknown Object (File)
Tue, Nov 26, 4:06 PM
Unknown Object (File)
Tue, Nov 26, 7:51 AM
Unknown Object (File)
Tue, Nov 26, 7:04 AM
Unknown Object (File)
Tue, Nov 26, 5:12 AM
Subscribers

Details

Summary

Linear issue: ENG-160, ENG-1700. We need the keyserver to send a message report to the keyserver admin from the commbot user when a user
reports a message. This diff introduces functions for creating such report.

Test Plan

Add the following to the textMessageCreationResponder in keyserver/src/responders/message-responders.js, right before return:

const reportedMessageID = rawMessageInfos[0].id;
if(reportedMessageID){
  await createMessageReport(viewer, { messageID: reportedMessageID });
}

And see that when a user sends a text message, ashoat user recievies a message from commbot saying

user user_name reported user_name’s message in chat titled chat_name

message

Add this to legacyMultimediaMessageCreationResponder right before return:

await createMessageReport(viewer, { messageID: id });

And see that when a user sends a multimedia message, ashoat user recievies a message from commbot saying

user user_name reported user_name’s message in chat titled chat_name
non-text message

So basically the message that is sent is also reported by the author
See that when chat between commbot and ashoat user doesn't exists it gets created, and when it exists it isn't created again, just a new message appears in the chat.

I also checked that when fetching the keyserver admin or creating the message with the report fail the creator throws an error. I did that by setting keyserverAdminID = null, result = [] (in createMessageReport), respectively, by hand. This error will be handled on the client side and is meant to be an indicator of whether the report was successful or not. In all other cases the report should succeed.

Diff Detail

Repository
rCOMM Comm
Branch
inka/message_report
Lint
No Lint Coverage
Unit
No Test Coverage

Event Timeline

There are a very large number of changes, so older changes are hidden. Show Older Changes
keyserver/src/creators/message-report-creator.js
42 ↗(On Diff #16155)

We shouldn't replace falsy threadID by [null] because that would result in a query with t.id = [null] which shouldn't be executed at all - we know that there are no such threads.

45–48 ↗(On Diff #16155)
53–54 ↗(On Diff #16155)

In the proposed approach it might be easier to use promiseAll from promises.js

This revision now requires changes to proceed.Sep 1 2022, 2:27 AM
inka edited the test plan for this revision. (Show Details)

Addressing Tomek's comments.
In the process I realized that the responder will need the message info as well, so it will fetch it and pass it to the creator

inka edited the test plan for this revision. (Show Details)

The reducer will need the threadInfo as well, although probably only as long as hack from ENG-1707 doesn't get reverted. For now we'll pass it to the creator to avoid multiple database calls for the same data.

tomek requested changes to this revision.Sep 2 2022, 1:53 AM

Looks great! Added just a couple of small comments.

keyserver/src/creators/message-report-creator.js
33–35 ↗(On Diff #16196)

We can start by assigning it

43 ↗(On Diff #16196)

It's better to keep it null / undefined here and deal with it in getCommbotMessage

73–83 ↗(On Diff #16196)

Maybe something like this?

This revision now requires changes to proceed.Sep 2 2022, 1:53 AM
keyserver/src/creators/message-report-creator.js
33–35 ↗(On Diff #16196)

I don't think I actually can, since I want to add something to it later. From Flow documentation:

When you create an object with its properties, you create a sealed object type in Flow. (...) But when objects are sealed, Flow will not allow you to add new properties to them.

link
And indeed when I try it Flow doesn't allow me to add new fields.

Address Tomek's comments

tomek added inline comments.
keyserver/src/creators/message-report-creator.js
33–35 ↗(On Diff #16196)

Ok, that makes sense

This revision is now accepted and ready to land.Sep 2 2022, 6:32 AM

Refactoring to match the projects convention of reponder/creator responsibilities

inka requested review of this revision.Sep 7 2022, 3:51 AM
inka planned changes to this revision.Sep 8 2022, 12:51 AM
inka edited the test plan for this revision. (Show Details)
inka edited the test plan for this revision. (Show Details)

Change copy after consulting Ashoat

tomek requested changes to this revision.Sep 13 2022, 2:47 AM
tomek added inline comments.
keyserver/src/creators/message-report-creator.js
46 ↗(On Diff #16579)

Could you check what we usually do with the result of createMessages call? And what is the meaning of the third parameter of this function?

63 ↗(On Diff #16579)

This might be really confusing to use because it's not obvious what is the meaning of the following array elements. A lot better approach would be to return an object, because it has named fields.

106–110 ↗(On Diff #16579)

We try to use two good practices: returning early if possible and avoiding mutability. In this case, you could return if fetchPersonalThreadID returned truthy value and then return the result of createCommbotThread.

keyserver/src/fetchers/thread-fetchers.js
245 ↗(On Diff #16579)

Why do we allow optional RawMessageInfo but use required MessageInfo? It this case it shouldn't matter that much, but if the function body had more complicated logic, this type might cause issues. You can also consider having an if and assign to promises conditionally, instead of introducing this function.

if (reportedMessage) {
  promises.reportedThread = await fetchServerThreadInfos(SQL`t.id = ${reportedMessage.threadID}`);
}
This revision now requires changes to proceed.Sep 13 2022, 2:47 AM
ashoat requested changes to this revision.Sep 15 2022, 6:52 PM
ashoat added inline comments.
keyserver/src/creators/message-report-creator.js
63 ↗(On Diff #16579)

Definitely agree with @tomek here

124 ↗(On Diff #16579)

This appends newlines to the end, which I don't think is necessary

126 ↗(On Diff #16579)

I'd like to keep the 's, but agree on removing user

keyserver/src/creators/message-report-creator.js
63 ↗(On Diff #16579)

Right, sorry, forgot to clean this up

106–110 ↗(On Diff #16579)

I'll change it to

return commbotThreadID ?? createCommbotThread(userID);

I checked what happens with this code:

let a = 0;
const b = null ?? (a=1);
console.log(a);

const c = 1 ?? (a=2);
console.log(a);

and it logs

1
1

So it seems if the left operator is not null or unndefined then the right side is not run. (from MDN docs:

returns its right-hand side operand when its left-hand side operand is null or undefined, and otherwise returns its left-hand side operand.

)

124 ↗(On Diff #16579)

Sorry, I don't understand. Do you mean that createMessageReply appends '\n\n'? Because it also adds > so that the text is displayed as a markdown quote... And the '\n\n' are as far as I understand our way of determining the end of the quote. From native/markdown/rules.react.js:

// match end of blockQuote by either \n\n or end of string
126 ↗(On Diff #16579)

The 's is added in lines 120-122 (if we successfully fetched the username). Is this what you meant?

keyserver/src/fetchers/thread-fetchers.js
245 ↗(On Diff #16579)

I'd rather leave this function. I feel like having to unpack the threadInfos array returned by the fetchServerThreadInfos in the creator is messy. It seems to me like this is what the '-fetchers' files are for? To provide some abstraction over this kind of actions? I don't know, I'm open to discussion.

ashoat requested changes to this revision.Sep 22 2022, 5:40 AM
ashoat added inline comments.
keyserver/src/creators/message-report-creator.js
124 ↗(On Diff #16579)
  1. To learn how quotes can end, you can just play around with Markdown in the chat while chatting with a test user. You'll find that \n\n is not necessary to end a quote if the quote is the last thing in the message
  2. If you want to understand why we append \n\n in createMessageReply, you should look at how it's used. It's used in the UI when the user presses "Reply" on a message. \n\n is appended so that the user can start writing their response right away

If the last thing in the message is the quote, there is no reason to append \n\n

126 ↗(On Diff #16579)

Oops, I missed that! Thanks for pointing it out

This revision now requires changes to proceed.Sep 22 2022, 5:40 AM
keyserver/src/creators/message-report-creator.js
124 ↗(On Diff #16579)

Oh, I understand now. I created D5212 extracting logic responsible for adding the > so it can be used here

Great, thank you!! Assuming you'll update this to use your new function before landing

keyserver/src/creators/message-report-creator.js
134 ↗(On Diff #16974)

Update to createMessageQuote before landing

This revision now requires review to proceed.Sep 22 2022, 6:29 AM

Remove unnecessary endlines

This revision is now accepted and ready to land.Sep 23 2022, 8:59 AM