Changeset View
Changeset View
Standalone View
Standalone View
lib/utils/entity-text.js
Show All 36 Lines | | { | ||||
} | } | ||||
| { | | { | ||||
+type: 'thread', | +type: 'thread', | ||||
+id: string, | +id: string, | ||||
+name?: ?string, | +name?: ?string, | ||||
// displays threadInfo.name if set, or eg. 'this thread' or 'this chat' | // displays threadInfo.name if set, or eg. 'this thread' or 'this chat' | ||||
+display: 'shortName', | +display: 'shortName', | ||||
+threadType?: ?ThreadType, | +threadType?: ?ThreadType, | ||||
+parentThreadID?: ?string, | |||||
+alwaysDisplayShortName?: ?boolean, // don't default to name | +alwaysDisplayShortName?: ?boolean, // don't default to name | ||||
+subchannel?: ?boolean, // short name should be "subchannel" | +subchannel?: ?boolean, // short name should be "subchannel" | ||||
+possessive?: ?boolean, // eg. `this thread's` instead of `this thread` | +possessive?: ?boolean, // eg. `this thread's` instead of `this thread` | ||||
}; | }; | ||||
type ColorEntity = { | type ColorEntity = { | ||||
+type: 'color', | +type: 'color', | ||||
+hex: string, | +hex: string, | ||||
▲ Show 20 Lines • Show All 56 Lines • ▼ Show 20 Lines | type EntityTextThreadInput = | ||||
| { | | { | ||||
+display: 'alwaysDisplayShortName', | +display: 'alwaysDisplayShortName', | ||||
+threadInfo: ThreadInfo | RawThreadInfo, | +threadInfo: ThreadInfo | RawThreadInfo, | ||||
+possessive?: ?boolean, | +possessive?: ?boolean, | ||||
} | } | ||||
| { | | { | ||||
+display: 'alwaysDisplayShortName', | +display: 'alwaysDisplayShortName', | ||||
+threadID: string, | +threadID: string, | ||||
+parentThreadID?: ?string, | |||||
+threadType?: ?ThreadType, | |||||
+possessive?: ?boolean, | +possessive?: ?boolean, | ||||
}; | }; | ||||
entityTextFunction.thread = (input: EntityTextThreadInput) => { | entityTextFunction.thread = (input: EntityTextThreadInput) => { | ||||
if (input.display === 'uiName') { | if (input.display === 'uiName') { | ||||
const { threadInfo } = input; | const { threadInfo } = input; | ||||
if (typeof threadInfo.uiName !== 'string') { | if (typeof threadInfo.uiName !== 'string') { | ||||
return threadInfo.uiName; | return threadInfo.uiName; | ||||
} | } | ||||
return { | return { | ||||
type: 'thread', | type: 'thread', | ||||
id: threadInfo.id, | id: threadInfo.id, | ||||
name: threadInfo.name, | name: threadInfo.name, | ||||
display: 'uiName', | display: 'uiName', | ||||
uiName: threadInfo.uiName, | uiName: threadInfo.uiName, | ||||
}; | }; | ||||
} | } | ||||
if (input.display === 'alwaysDisplayShortName' && input.threadID) { | if (input.display === 'alwaysDisplayShortName' && input.threadID) { | ||||
const { threadID, possessive } = input; | const { threadID, threadType, parentThreadID, possessive } = input; | ||||
return { | return { | ||||
type: 'thread', | type: 'thread', | ||||
id: threadID, | id: threadID, | ||||
name: undefined, | name: undefined, | ||||
display: 'shortName', | display: 'shortName', | ||||
threadType: undefined, | threadType, | ||||
parentThreadID, | |||||
alwaysDisplayShortName: true, | alwaysDisplayShortName: true, | ||||
possessive, | possessive, | ||||
}; | }; | ||||
} else if (input.display === 'alwaysDisplayShortName' && input.threadInfo) { | } else if (input.display === 'alwaysDisplayShortName' && input.threadInfo) { | ||||
const { threadInfo, possessive } = input; | const { threadInfo, possessive } = input; | ||||
return { | return { | ||||
type: 'thread', | type: 'thread', | ||||
id: threadInfo.id, | id: threadInfo.id, | ||||
name: threadInfo.name, | name: threadInfo.name, | ||||
display: 'shortName', | display: 'shortName', | ||||
threadType: threadInfo.type, | threadType: threadInfo.type, | ||||
parentThreadID: threadInfo.parentThreadID, | |||||
alwaysDisplayShortName: true, | alwaysDisplayShortName: true, | ||||
possessive, | possessive, | ||||
}; | }; | ||||
} else if (input.display === 'shortName' || !input.display) { | } else if (input.display === 'shortName' || !input.display) { | ||||
const { threadInfo, subchannel, possessive } = input; | const { threadInfo, subchannel, possessive } = input; | ||||
return { | return { | ||||
type: 'thread', | type: 'thread', | ||||
id: threadInfo.id, | id: threadInfo.id, | ||||
name: threadInfo.name, | name: threadInfo.name, | ||||
display: 'shortName', | display: 'shortName', | ||||
threadType: threadInfo.type, | threadType: threadInfo.type, | ||||
parentThreadID: threadInfo.parentThreadID, | |||||
subchannel, | subchannel, | ||||
possessive, | possessive, | ||||
}; | }; | ||||
} | } | ||||
invariant( | invariant( | ||||
false, | false, | ||||
`ET.thread passed unexpected display type: ${input.display}`, | `ET.thread passed unexpected display type: ${input.display}`, | ||||
); | ); | ||||
▲ Show 20 Lines • Show All 350 Lines • Show Last 20 Lines |