-
-
Notifications
You must be signed in to change notification settings - Fork 672
narrow [nfc]: Cut Narrow from the Outbox type.
#3889
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
060751e
23ad3c1
31dfe88
55da6ea
f09a0f2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -64,17 +64,16 @@ export const trySendMessages = (dispatch: Dispatch, getState: GetState): boolean | |
| return; // i.e., continue | ||
| } | ||
|
|
||
| const to = ((): string => { | ||
| const { narrow } = item; | ||
| // TODO: can this test be `if (item.type === private)`? | ||
| if (isPrivateOrGroupNarrow(narrow)) { | ||
| return narrow[0].operand; | ||
| } else { | ||
| // HACK: the server attempts to interpret this argument as JSON, then | ||
| // CSV, then a literal. To avoid misparsing, always use JSON. | ||
| return JSON.stringify([item.display_recipient]); | ||
| } | ||
| })(); | ||
| // prettier-ignore | ||
| const to = | ||
| item.type === 'private' | ||
| // This will include the self user, possibly twice. That's | ||
| // fine; on send, the server (since at least 2013) drops dupes | ||
| // and normalizes whether to include the sender. | ||
| ? item.display_recipient.map(r => r.email).join(',') | ||
|
Comment on lines
+70
to
+73
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I wouldn't want to just Also, if these are emails rather than IDs, we should probably use JSON rather than CSV. (If I'd realized that's what they were, I would have done the additional testing on #3734. 😞) I'm not about to ask you to do that for this PR, but tagging it with an inline
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #4299 I ended up taking care of that duplicate self-user by fixing how we construct |
||
| // HACK: the server attempts to interpret this argument as JSON, then | ||
| // CSV, then a literal. To avoid misparsing, always use JSON. | ||
| : JSON.stringify([item.display_recipient]); | ||
|
|
||
| await api.sendMessage(auth, { | ||
| type: item.type, | ||
|
|
@@ -164,7 +163,6 @@ export const addToOutbox = (narrow: Narrow, content: string) => async ( | |
| const localTime = Math.round(new Date().getTime() / 1000); | ||
| dispatch( | ||
| messageSendStart({ | ||
| narrow, | ||
| isSent: false, | ||
| ...extractTypeToAndSubjectFromNarrow(narrow, getUsersByEmail(state), userDetail), | ||
| markdownContent: content, | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -248,19 +248,24 @@ export const canSendToNarrow = (narrow: Narrow): boolean => | |
| search: () => false, | ||
| }); | ||
|
|
||
| /** True just if `haystack` contains all possible messages in `needle`. */ | ||
| export const narrowContains = (haystack: Narrow, needle: Narrow): boolean => { | ||
| if (isHomeNarrow(haystack)) { | ||
| return true; | ||
| } | ||
| if (isAllPrivateNarrow(haystack) && isPrivateOrGroupNarrow(needle)) { | ||
| return true; | ||
| } | ||
| if (isStreamNarrow(haystack) && needle[0].operand === haystack[0].operand) { | ||
| return true; | ||
| } | ||
| return JSON.stringify(needle) === JSON.stringify(haystack); | ||
| }; | ||
| export const narrowContainsOutbox = (haystack: Narrow, needle: Outbox): boolean => | ||
|
gnprice marked this conversation as resolved.
|
||
| caseNarrowPartial(haystack, { | ||
| stream: name => needle.type === 'stream' && needle.display_recipient === name, | ||
| topic: (streamName, topic) => | ||
| needle.type === 'stream' | ||
| && needle.display_recipient === streamName | ||
| && needle.subject === topic, | ||
| pm: emails => emails === needle.display_recipient.map(r => r.email).join(','), | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This line (
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Eek, good catch re: missing the I suspect what happened there is that this change (and the others in this branch) was originally taken from a longer
Yeah, and I believe that's already the case in the existing version of this code, as a result of just string-comparing the results of
Hmm. Will check on these. And probably write some unit tests for this function, as I seem to have demonstrated the need for them >_>
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ah, no, here it is more directly:
narrow[0].operand
.split(',')
.map(item => {
const user = usersByEmail.get(item) || NULL_USER;
return { email: item, id: user.user_id, full_name: user.full_name };
})
.concat({ email: selfDetail.email, id: selfDetail.user_id, full_name: selfDetail.full_name });So yep, we've been counting on the order of these. I think that same look at the code also confirms that the display_recipient will have the self user added at the end, like you said, while the narrow's list of emails won't.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In #4299 I ended up dropping this implementation entirely... because there's already an |
||
|
|
||
| home: () => true, | ||
| allPrivate: () => needle.type === 'private', | ||
| starred: () => false, | ||
|
|
||
| // These two are uncommon cases it'd take some work to get right; just | ||
| // leave the outbox messages out. | ||
|
Comment on lines
+264
to
+265
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's almost certainly not worth the trouble to fix at the moment, but I'd suggest explicitly marking this as a |
||
| mentioned: () => false, | ||
| search: () => false, | ||
| }); | ||
|
|
||
| export const getNarrowFromMessage = (message: Message | Outbox, ownEmail: string) => { | ||
| if (Array.isArray(message.display_recipient)) { | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🎉