-
-
Notifications
You must be signed in to change notification settings - Fork 649
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support to getNarrowFromNotificationData for group narrows
For this to work we need to parse a string of comma delimited numbers of the recipients. This data is not yet passed to the function; we keep the function flexible and functional by making the parameter of `usersById` optional.`
- Loading branch information
1 parent
02088d9
commit 343dd7d
Showing
3 changed files
with
47 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,26 @@ | ||
/* @flow */ | ||
import { homeNarrow, topicNarrow, privateNarrow } from '../utils/narrow'; | ||
import type { Notification } from '../types'; | ||
|
||
export const getNarrowFromNotificationData = (data: Notification) => | ||
!data || !data.recipient_type | ||
? homeNarrow | ||
: data.recipient_type === 'stream' | ||
? topicNarrow(data.stream, data.topic) | ||
: privateNarrow(data.sender_email); | ||
import type { Notification, NotificationGroup, UserIdMap } from '../types'; | ||
import { homeNarrow, topicNarrow, privateNarrow, groupNarrow } from '../utils/narrow'; | ||
|
||
const getGroupNarrowFromNotificationData = (data: NotificationGroup, usersById: UserIdMap = {}) => { | ||
const userIds = data.pm_users.split(','); | ||
const userEmails = userIds.map(x => usersById[x].email); | ||
return groupNarrow(userEmails); | ||
}; | ||
|
||
export const getNarrowFromNotificationData = (data: Notification, usersById: UserIdMap = {}) => { | ||
if (!data || !data.recipient_type) { | ||
return homeNarrow; | ||
} | ||
|
||
if (data.recipient_type === 'stream') { | ||
return topicNarrow(data.stream, data.topic); | ||
} | ||
|
||
// $FlowFixMe | ||
if (!data.pm_users) { | ||
return privateNarrow(data.sender_email); | ||
} | ||
|
||
return getGroupNarrowFromNotificationData(data, usersById); | ||
}; |