diff --git a/src/api/messages/sendMessage.js b/src/api/messages/sendMessage.js index 371027ad715..390c69f1848 100644 --- a/src/api/messages/sendMessage.js +++ b/src/api/messages/sendMessage.js @@ -7,7 +7,7 @@ import { apiPost } from '../apiFetch'; export default async ( auth: Auth, params: {| - type: 'private' | 'stream', + type: 'direct' | 'stream', to: string, // TODO(server-2.0): Say "topic", not "subject" subject?: string, @@ -15,12 +15,19 @@ export default async ( localId?: number, eventQueueId?: string, |}, -): Promise => - apiPost(auth, 'messages', { - type: params.type, + zulipFeatureLevel: number, // TODO(#4659): Don't get this from callers. +): Promise => { + let { type } = params; + if (type === 'direct' && zulipFeatureLevel < 174) { + // TODO(server-7.0): Simplify. + type = 'private'; + } + return apiPost(auth, 'messages', { + type, to: params.to, subject: params.subject, content: params.content, local_id: params.localId, queue_id: params.eventQueueId, }); +}; diff --git a/src/outbox/outboxActions.js b/src/outbox/outboxActions.js index ce7720c5553..d56f2c025ea 100644 --- a/src/outbox/outboxActions.js +++ b/src/outbox/outboxActions.js @@ -30,6 +30,7 @@ import { makeUserId } from '../api/idTypes'; import { caseNarrowPartial, isConversationNarrow } from '../utils/narrow'; import { BackoffMachine } from '../utils/async'; import { recipientsOfPrivateMessage, streamNameOfStreamMessage } from '../utils/recipient'; +import { getZulipFeatureLevel } from '../account/accountsSelectors'; export const messageSendStart = (outbox: Outbox): PerAccountAction => ({ type: MESSAGE_SEND_START, @@ -54,6 +55,7 @@ export const messageSendComplete = (localMessageId: number): PerAccountAction => const trySendMessages = (dispatch, getState): boolean => { const state = getState(); const auth = getAuth(state); + const zulipFeatureLevel = getZulipFeatureLevel(state); const outboxToSend = state.outbox.filter(outbox => !outbox.isSent); const oneWeekAgoTimestamp = Date.now() / 1000 - 60 * 60 * 24 * 7; try { @@ -69,6 +71,8 @@ const trySendMessages = (dispatch, getState): boolean => { return; // i.e., continue } + const type = item.type === 'private' ? 'direct' : item.type; + // prettier-ignore const to = item.type === 'private' @@ -79,14 +83,18 @@ const trySendMessages = (dispatch, getState): boolean => { // CSV, then a literal. To avoid misparsing, always use JSON. : JSON.stringify([streamNameOfStreamMessage(item)]); - await api.sendMessage(auth, { - type: item.type, - to, - subject: item.subject, - content: item.markdownContent, - localId: item.timestamp, - eventQueueId: state.session.eventQueueId ?? undefined, - }); + await api.sendMessage( + auth, + { + type, + to, + subject: item.subject, + content: item.markdownContent, + localId: item.timestamp, + eventQueueId: state.session.eventQueueId ?? undefined, + }, + zulipFeatureLevel, + ); dispatch(messageSendComplete(item.timestamp)); }); return true; diff --git a/src/sharing/ShareWrapper.js b/src/sharing/ShareWrapper.js index 01c5fe671c0..920e91c70d8 100644 --- a/src/sharing/ShareWrapper.js +++ b/src/sharing/ShareWrapper.js @@ -23,6 +23,7 @@ import { ensureUnreachable } from '../generics'; import { IconAttachment, IconCancel } from '../common/Icons'; import type { AppNavigationMethods } from '../nav/AppNavigator'; import { ApiError, RequestError } from '../api/apiErrors'; +import { getZulipFeatureLevel } from '../account/accountsSelectors'; type SendTo = | {| type: 'pm', selectedRecipients: $ReadOnlyArray |} @@ -80,6 +81,7 @@ type OuterProps = $ReadOnly<{| type SelectorProps = $ReadOnly<{| auth: Auth, ownUserId: UserId, + zulipFeatureLevel: number, |}>; type Props = $ReadOnly<{| @@ -124,7 +126,7 @@ class ShareWrapperInner extends React.PureComponent { */ handleSend = async () => { const _ = this.context; - const { auth, sendTo, sharedData, getValidationErrors } = this.props; + const { auth, sendTo, sharedData, getValidationErrors, zulipFeatureLevel } = this.props; let messageToSend = this.state.message; const validationErrors = getValidationErrors(messageToSend); @@ -193,7 +195,7 @@ class ShareWrapperInner extends React.PureComponent { sendTo.type === 'pm' ? { content: messageToSend, - type: 'private', + type: 'direct', to: JSON.stringify(sendTo.selectedRecipients), } : { @@ -206,7 +208,7 @@ class ShareWrapperInner extends React.PureComponent { }; try { - await api.sendMessage(auth, messageData); + await api.sendMessage(auth, messageData, zulipFeatureLevel); } catch (err) { showToast(_('Failed to send message')); logging.error(err); @@ -333,6 +335,7 @@ class ShareWrapperInner extends React.PureComponent { const ShareWrapper: ComponentType = connect(state => ({ auth: getAuth(state), ownUserId: getOwnUserId(state), + zulipFeatureLevel: getZulipFeatureLevel(state), }))(ShareWrapperInner); export default ShareWrapper;