MM-41940 Gekidou Post Options menu - mark as unread (#5987)
* added marksAsUnread * code fix * correction * added some correction * modified markChannelAsUnread to accomodate isUnread field * Update app/actions/remote/post.ts Co-authored-by: Elias Nahum <nahumhbl@gmail.com> * code clean up * code fix * minor edit Co-authored-by: Elias Nahum <nahumhbl@gmail.com>
This commit is contained in:
parent
b2b7a724de
commit
860ae2ab75
5 changed files with 66 additions and 15 deletions
|
|
@ -189,7 +189,7 @@ export const markChannelAsViewed = async (serverUrl: string, channelId: string,
|
|||
}
|
||||
};
|
||||
|
||||
export const markChannelAsUnread = async (serverUrl: string, channelId: string, messageCount: number, mentionsCount: number, manuallyUnread: boolean, lastViewed: number, prepareRecordsOnly = false) => {
|
||||
export const markChannelAsUnread = async (serverUrl: string, channelId: string, messageCount: number, mentionsCount: number, lastViewed: number, prepareRecordsOnly = false) => {
|
||||
const operator = DatabaseManager.serverDatabases[serverUrl]?.operator;
|
||||
if (!operator) {
|
||||
return {error: `${serverUrl} database not found`};
|
||||
|
|
@ -201,11 +201,12 @@ export const markChannelAsUnread = async (serverUrl: string, channelId: string,
|
|||
}
|
||||
|
||||
member.prepareUpdate((m) => {
|
||||
m.viewedAt = lastViewed;
|
||||
m.viewedAt = lastViewed - 1;
|
||||
m.lastViewedAt = lastViewed;
|
||||
m.messageCount = messageCount;
|
||||
m.mentionsCount = mentionsCount;
|
||||
m.manuallyUnread = manuallyUnread;
|
||||
m.manuallyUnread = true;
|
||||
m.isUnread = true;
|
||||
});
|
||||
|
||||
try {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
|
||||
import {DeviceEventEmitter} from 'react-native';
|
||||
|
||||
import {updateLastPostAt} from '@actions/local/channel';
|
||||
import {markChannelAsUnread, updateLastPostAt} from '@actions/local/channel';
|
||||
import {processPostsFetched, removePost} from '@actions/local/post';
|
||||
import {addRecentReaction} from '@actions/local/reactions';
|
||||
import {ActionType, Events, General, ServerErrors} from '@constants';
|
||||
|
|
@ -575,3 +575,43 @@ export const deletePost = async (serverUrl: string, postId: string) => {
|
|||
return {error};
|
||||
}
|
||||
};
|
||||
|
||||
export const markPostAsUnread = async (serverUrl: string, postId: string) => {
|
||||
const database = DatabaseManager.serverDatabases[serverUrl]?.database;
|
||||
if (!database) {
|
||||
return {error: `${serverUrl} database not found`};
|
||||
}
|
||||
let client;
|
||||
try {
|
||||
client = NetworkManager.getClient(serverUrl);
|
||||
} catch (error) {
|
||||
return {error};
|
||||
}
|
||||
|
||||
try {
|
||||
const [userId, post] = await Promise.all([queryCurrentUserId(database), queryPostById(database, postId)]);
|
||||
if (post && userId) {
|
||||
await client.markPostAsUnread(userId, postId);
|
||||
const {channelId} = post;
|
||||
|
||||
const [channel, channelMember] = await Promise.all([
|
||||
client.getChannel(channelId),
|
||||
client.getChannelMember(channelId, userId),
|
||||
]);
|
||||
if (channel && channelMember) {
|
||||
const messageCount = channel.total_msg_count - channelMember.msg_count;
|
||||
const mentionCount = channelMember.mention_count;
|
||||
await markChannelAsUnread(serverUrl, channelId, messageCount, mentionCount, post.createAt);
|
||||
return {
|
||||
post,
|
||||
};
|
||||
}
|
||||
}
|
||||
return {
|
||||
post,
|
||||
};
|
||||
} catch (error) {
|
||||
forceLogoutIfNecessary(serverUrl, error as ClientErrorProps);
|
||||
return {error};
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -152,9 +152,7 @@ export async function handleNewPostEvent(serverUrl: string, msg: WebSocketMessag
|
|||
post.channel_id,
|
||||
myChannel.messageCount + 1,
|
||||
myChannel.mentionsCount + (hasMentions ? 1 : 0),
|
||||
false,
|
||||
myChannel.lastViewedAt,
|
||||
true,
|
||||
);
|
||||
if (unreadAt) {
|
||||
models.push(unreadAt);
|
||||
|
|
@ -217,5 +215,5 @@ export async function handlePostUnread(serverUrl: string, msg: WebSocketMessage)
|
|||
const channel = channels?.[0];
|
||||
const postNumber = channel?.total_msg_count;
|
||||
const delta = postNumber ? postNumber - msg.data.msg_count : msg.data.msg_count;
|
||||
markChannelAsUnread(serverUrl, msg.broadcast.channel_id, delta, msg.data.mention_count, true, msg.data.last_viewed_at);
|
||||
markChannelAsUnread(serverUrl, msg.broadcast.channel_id, delta, msg.data.mention_count, msg.data.last_viewed_at);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,24 +1,34 @@
|
|||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
|
||||
// See LICENSE.txt for license information.
|
||||
|
||||
import React from 'react';
|
||||
import React, {useCallback} from 'react';
|
||||
|
||||
import {markPostAsUnread} from '@actions/remote/post';
|
||||
import Screens from '@constants/screens';
|
||||
import {useServerUrl} from '@context/server';
|
||||
import {t} from '@i18n';
|
||||
import {dismissBottomSheet} from '@screens/navigation';
|
||||
|
||||
import BaseOption from './base_option';
|
||||
|
||||
//fixme: wire up canMarkAsUnread
|
||||
const MarkAsUnreadOption = () => {
|
||||
const handleMarkUnread = () => {
|
||||
//todo:
|
||||
};
|
||||
type Props = {
|
||||
postId: string;
|
||||
}
|
||||
|
||||
const MarkAsUnreadOption = ({postId}: Props) => {
|
||||
const serverUrl = useServerUrl();
|
||||
|
||||
const onPress = useCallback(() => {
|
||||
markPostAsUnread(serverUrl, postId);
|
||||
dismissBottomSheet(Screens.POST_OPTIONS);
|
||||
}, [serverUrl, postId]);
|
||||
|
||||
return (
|
||||
<BaseOption
|
||||
i18nId={t('mobile.post_info.mark_unread')}
|
||||
defaultMessage='Mark as Unread'
|
||||
iconName='mark-as-unread'
|
||||
onPress={handleMarkUnread}
|
||||
onPress={onPress}
|
||||
testID='post.options.mark.unread'
|
||||
/>
|
||||
);
|
||||
|
|
|
|||
|
|
@ -74,7 +74,9 @@ const PostOptions = ({
|
|||
thread={thread}
|
||||
/>
|
||||
}
|
||||
{canMarkAsUnread && !isSystemPost && (<MarkAsUnreadOption/>)}
|
||||
{canMarkAsUnread && !isSystemPost &&
|
||||
<MarkAsUnreadOption postId={post.id}/>
|
||||
}
|
||||
{canCopyPermalink && <CopyLinkOption post={post}/>}
|
||||
{!isSystemPost &&
|
||||
<SaveOption
|
||||
|
|
|
|||
Loading…
Reference in a new issue