Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/drawer-utils.react.js
// @flow | // @flow | ||||
import { threadIsChannel } from '../shared/thread-utils.js'; | import { values } from './objects.js'; | ||||
import { threadInFilterList, threadIsChannel } from '../shared/thread-utils.js'; | |||||
import { communitySubthreads } from '../types/thread-types-enum.js'; | import { communitySubthreads } from '../types/thread-types-enum.js'; | ||||
import { | import type { | ||||
type ThreadInfo, | RawThreadInfo, | ||||
type ResolvedThreadInfo, | ThreadInfo, | ||||
ResolvedThreadInfo, | |||||
} from '../types/thread-types.js'; | } from '../types/thread-types.js'; | ||||
export type CommunityDrawerItemData<T> = { | export type CommunityDrawerItemData<T> = { | ||||
+threadInfo: ThreadInfo, | +threadInfo: ThreadInfo, | ||||
+itemChildren?: $ReadOnlyArray<CommunityDrawerItemData<T>>, | +itemChildren?: $ReadOnlyArray<CommunityDrawerItemData<T>>, | ||||
+hasSubchannelsButton: boolean, | +hasSubchannelsButton: boolean, | ||||
+labelStyle: T, | +labelStyle: T, | ||||
}; | }; | ||||
▲ Show 20 Lines • Show All 60 Lines • ▼ Show 20 Lines | for (const chat of chats) { | ||||
if (numberOfOccurrences) { | if (numberOfOccurrences) { | ||||
name = `${name} (${numberOfOccurrences.toString()})`; | name = `${name} (${numberOfOccurrences.toString()})`; | ||||
} | } | ||||
result.push({ ...chat, uiName: name }); | result.push({ ...chat, uiName: name }); | ||||
} | } | ||||
return result; | return result; | ||||
} | } | ||||
export { createRecursiveDrawerItemsData, appendSuffix }; | function filterThreadIDsBelongingToCommunity( | ||||
communityID: string, | |||||
threadInfosObj: { +[id: string]: ThreadInfo | RawThreadInfo }, | |||||
): $ReadOnlySet<string> { | |||||
const threadInfos = values(threadInfosObj); | |||||
const threadIDs = threadInfos | |||||
.filter( | |||||
thread => | |||||
(thread.community === communityID || thread.id === communityID) && | |||||
threadInFilterList(thread), | |||||
) | |||||
.map(item => item.id); | |||||
return new Set(threadIDs); | |||||
} | |||||
export { | |||||
createRecursiveDrawerItemsData, | |||||
appendSuffix, | |||||
filterThreadIDsBelongingToCommunity, | |||||
}; |