Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F33017539
D5673.1768380470.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
D5673.1768380470.diff
View Options
diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js
--- a/lib/shared/thread-utils.js
+++ b/lib/shared/thread-utils.js
@@ -209,6 +209,15 @@
.map(memberInfo => memberInfo.id);
}
+function threadOtherMembers<T: MemberInfo | RelativeMemberInfo>(
+ memberInfos: $ReadOnlyArray<T>,
+ viewerID: ?string,
+): $ReadOnlyArray<T> {
+ return memberInfos.filter(
+ memberInfo => memberInfo.role && memberInfo.id !== viewerID,
+ );
+}
+
function threadMembersWithoutAddedAshoat<T: ThreadInfo | RawThreadInfo>(
threadInfo: T,
): $PropertyType<T, 'members'> {
@@ -239,20 +248,6 @@
return !!threadID?.startsWith('pending');
}
-function getThreadOtherUsers(
- threadInfo: ThreadInfo | RawThreadInfo,
- viewerID: ?string,
-): string[] {
- const otherUserIDs = [];
- for (const member of threadInfo.members) {
- if (!member.role || member.id === viewerID) {
- continue;
- }
- otherUserIDs.push(member.id);
- }
- return otherUserIDs;
-}
-
function getSingleOtherUser(
threadInfo: ThreadInfo | RawThreadInfo,
viewerID: ?string,
@@ -260,11 +255,11 @@
if (!viewerID) {
return undefined;
}
- const otherMemberIDs = getThreadOtherUsers(threadInfo, viewerID);
- if (otherMemberIDs.length !== 1) {
+ const otherMembers = threadOtherMembers(threadInfo.members, viewerID);
+ if (otherMembers.length !== 1) {
return undefined;
}
- return otherMemberIDs[0];
+ return otherMembers[0].id;
}
function getPendingThreadID(
@@ -524,7 +519,9 @@
return threadInfo.id;
}
- const otherMemberIDs = getThreadOtherUsers(threadInfo, viewerID);
+ const otherMemberIDs = threadOtherMembers(threadInfo.members, viewerID).map(
+ member => member.id,
+ );
let resultPromise;
if (threadInfo.type !== threadTypes.SIDEBAR) {
invariant(
@@ -700,8 +697,8 @@
viewerID: ?string,
userInfos: UserInfos,
): string {
- const threadUsernames = getThreadOtherUsers(threadInfo, viewerID)
- .map(memberID => userInfos[memberID] && userInfos[memberID].username)
+ const threadUsernames = threadOtherMembers(threadInfo.members, viewerID)
+ .map(member => userInfos[member.id] && userInfos[member.id].username)
.filter(Boolean);
if (threadUsernames.length === 0) {
return 'just you';
@@ -1414,6 +1411,7 @@
threadInFilterList,
userIsMember,
threadActualMembers,
+ threadOtherMembers,
threadIsGroupChat,
threadIsPending,
getSingleOtherUser,
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Wed, Jan 14, 8:47 AM (8 h, 27 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5928709
Default Alt Text
D5673.1768380470.diff (2 KB)
Attached To
Mode
D5673: [lib] Refactor getThreadOtherUsers and all its occurrences
Attached
Detach File
Event Timeline
Log In to Comment