Changeset View
Changeset View
Standalone View
Standalone View
lib/shared/messages/create-sidebar-message-spec.js
// @flow | // @flow | ||||
import invariant from 'invariant'; | import invariant from 'invariant'; | ||||
import { | import { | ||||
pushTypes, | pushTypes, | ||||
type CreateMessageInfoParams, | type CreateMessageInfoParams, | ||||
type MessageSpec, | type MessageSpec, | ||||
} from './message-spec.js'; | } from './message-spec.js'; | ||||
import { assertSingleMessageInfo } from './utils.js'; | |||||
import type { PlatformDetails } from '../../types/device-types.js'; | import type { PlatformDetails } from '../../types/device-types.js'; | ||||
import { messageTypes } from '../../types/message-types.js'; | import { messageTypes } from '../../types/message-types.js'; | ||||
import type { | import type { | ||||
MessageInfo, | MessageInfo, | ||||
ClientDBMessageInfo, | ClientDBMessageInfo, | ||||
} from '../../types/message-types.js'; | } from '../../types/message-types.js'; | ||||
import type { | import type { | ||||
CreateSidebarMessageData, | CreateSidebarMessageData, | ||||
▲ Show 20 Lines • Show All 129 Lines • ▼ Show 20 Lines | robotext(messageInfo: CreateSidebarMessageInfo): EntityText { | ||||
const creator = ET.user({ userInfo: messageInfo.creator }); | const creator = ET.user({ userInfo: messageInfo.creator }); | ||||
return ET`${creator} ${text}`; | return ET`${creator} ${text}`; | ||||
}, | }, | ||||
shimUnsupportedMessageInfo( | shimUnsupportedMessageInfo( | ||||
rawMessageInfo: RawCreateSidebarMessageInfo, | rawMessageInfo: RawCreateSidebarMessageInfo, | ||||
platformDetails: ?PlatformDetails, | platformDetails: ?PlatformDetails, | ||||
): RawCreateSidebarMessageInfo | RawUnsupportedMessageInfo { | ): RawCreateSidebarMessageInfo | RawUnsupportedMessageInfo { | ||||
// TODO determine min code version | |||||
if (hasMinCodeVersion(platformDetails, 75)) { | if (hasMinCodeVersion(platformDetails, 75)) { | ||||
return rawMessageInfo; | return rawMessageInfo; | ||||
} | } | ||||
const { id } = rawMessageInfo; | const { id } = rawMessageInfo; | ||||
invariant(id !== null && id !== undefined, 'id should be set on server'); | invariant(id !== null && id !== undefined, 'id should be set on server'); | ||||
return { | return { | ||||
type: messageTypes.UNSUPPORTED, | type: messageTypes.UNSUPPORTED, | ||||
id, | id, | ||||
Show All 10 Lines | > = Object.freeze({ | ||||
): RawCreateSidebarMessageInfo { | ): RawCreateSidebarMessageInfo { | ||||
return unwrapped; | return unwrapped; | ||||
}, | }, | ||||
async notificationTexts( | async notificationTexts( | ||||
messageInfos: $ReadOnlyArray<MessageInfo>, | messageInfos: $ReadOnlyArray<MessageInfo>, | ||||
threadInfo: ThreadInfo, | threadInfo: ThreadInfo, | ||||
): Promise<NotifTexts> { | ): Promise<NotifTexts> { | ||||
const messageInfo = assertSingleMessageInfo(messageInfos); | const firstMessageInfo = messageInfos[0]; | ||||
invariant( | invariant( | ||||
messageInfo.type === messageTypes.CREATE_SIDEBAR, | firstMessageInfo.type === messageTypes.CREATE_SIDEBAR, | ||||
'messageInfo should be messageTypes.CREATE_SIDEBAR!', | 'firstMessageInfo should be messageTypes.CREATE_SIDEBAR!', | ||||
); | ); | ||||
const creator = ET.user({ userInfo: messageInfo.creator }); | const creator = ET.user({ userInfo: firstMessageInfo.creator }); | ||||
const prefix = ET`${creator}`; | const prefix = ET`${creator}`; | ||||
const initialName = messageInfo.initialThreadState.name; | const initialName = firstMessageInfo.initialThreadState.name; | ||||
const sourceMessageAuthorPossessive = ET.user({ | const sourceMessageAuthorPossessive = ET.user({ | ||||
userInfo: messageInfo.sourceMessageAuthor, | userInfo: firstMessageInfo.sourceMessageAuthor, | ||||
possessive: true, | possessive: true, | ||||
}); | }); | ||||
let body = `started a thread in response to `; | let body = `started a thread in response to `; | ||||
body = ET`${body} ${sourceMessageAuthorPossessive} message`; | body = ET`${body} ${sourceMessageAuthorPossessive} message`; | ||||
if (initialName) { | if (initialName) { | ||||
body = ET`${body} "${initialName}"`; | body = ET`${body} "${initialName}"`; | ||||
} | } | ||||
Show All 22 Lines |