MM-49219: fixes post priority (#6880)

We have changed how priority gets saved in the server, so now instead of
post.props we are using post.metadata.priority.
This commit adds the relevant changes for posts' priority to work in the
mobile app.
This commit is contained in:
Kyriakos Z
2022-12-20 21:54:25 +02:00
committed by GitHub
parent 4206764881
commit bf5783252e
9 changed files with 49 additions and 45 deletions

View File

@@ -13,6 +13,7 @@ import {setStatus} from '@actions/remote/user';
import {canEndCall, endCall, getEndCallMessage} from '@calls/actions/calls';
import ClientError from '@client/rest/error';
import {Events, Screens} from '@constants';
import {PostPriorityType} from '@constants/post';
import {NOTIFY_ALL_MEMBERS} from '@constants/post_draft';
import {useServerUrl} from '@context/server';
import DraftUploadManager from '@managers/draft_upload_manager';
@@ -54,6 +55,10 @@ type Props = {
uploadFileError: React.ReactNode;
}
const INITIAL_PRIORITY = {
priority: PostPriorityType.STANDARD,
};
export default function SendHandler({
testID,
channelId,
@@ -83,8 +88,7 @@ export default function SendHandler({
const [channelTimezoneCount, setChannelTimezoneCount] = useState(0);
const [sendingMessage, setSendingMessage] = useState(false);
const [postProps, setPostProps] = useState<Post['props']>({});
const [postPriority, setPostPriority] = useState<PostPriorityData>(INITIAL_PRIORITY);
const canSend = useCallback(() => {
if (sendingMessage) {
@@ -120,17 +124,19 @@ export default function SendHandler({
message: value,
} as Post;
if (Object.keys(postProps).length) {
post.props = postProps;
if (Object.keys(postPriority).length) {
post.metadata = {
priority: postPriority,
};
}
createPost(serverUrl, post, postFiles);
clearDraft();
setSendingMessage(false);
setPostProps({});
setPostPriority(INITIAL_PRIORITY);
DeviceEventEmitter.emit(Events.POST_LIST_SCROLL_TO_BOTTOM, rootId ? Screens.THREAD : Screens.CHANNEL);
}, [files, currentUserId, channelId, rootId, value, clearDraft, postProps]);
}, [files, currentUserId, channelId, rootId, value, clearDraft, postPriority]);
const showSendToAllOrChannelOrHereAlert = useCallback((calculatedMembersCount: number, atHere: boolean) => {
const notifyAllMessage = DraftUtils.buildChannelWideMentionMessage(intl, calculatedMembersCount, Boolean(isTimezoneEnabled), channelTimezoneCount, atHere);
@@ -297,8 +303,8 @@ export default function SendHandler({
canSend={canSend()}
maxMessageLength={maxMessageLength}
updatePostInputTop={updatePostInputTop}
postProps={postProps}
updatePostProps={setPostProps}
postPriority={postPriority}
updatePostPriority={setPostPriority}
setIsFocused={setIsFocused}
/>
);