Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MM 45015 - auto follow threads #7463

Merged
merged 7 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/constants/channel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,15 @@ export const MAX_CHANNEL_NAME_LENGTH = 64;
export const IGNORE_CHANNEL_MENTIONS_ON = 'on';
export const IGNORE_CHANNEL_MENTIONS_OFF = 'off';
export const IGNORE_CHANNEL_MENTIONS_DEFAULT = 'default';
export const CHANNEL_AUTO_FOLLOW_THREADS_TRUE = 'on';
export const CHANNEL_AUTO_FOLLOW_THREADS_FALSE = 'off';

export default {
IGNORE_CHANNEL_MENTIONS_ON,
IGNORE_CHANNEL_MENTIONS_OFF,
IGNORE_CHANNEL_MENTIONS_DEFAULT,
MAX_CHANNEL_NAME_LENGTH,
MIN_CHANNEL_NAME_LENGTH,
CHANNEL_AUTO_FOLLOW_THREADS_TRUE,
CHANNEL_AUTO_FOLLOW_THREADS_FALSE,
};
3 changes: 3 additions & 0 deletions app/screens/channel_info/channel_info.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Props = {
canEnableDisableCalls: boolean;
isCallsEnabledInChannel: boolean;
canManageMembers: boolean;
isCRTEnabled: boolean;
}

const edges: Edge[] = ['bottom', 'left', 'right'];
Expand All @@ -50,6 +51,7 @@ const getStyleSheet = makeStyleSheetFromTheme((theme: Theme) => ({
}));

const ChannelInfo = ({
isCRTEnabled,
channelId,
closeButtonId,
componentId,
Expand Down Expand Up @@ -103,6 +105,7 @@ const ChannelInfo = ({
type={type}
callsEnabled={callsAvailable}
canManageMembers={canManageMembers}
isCRTEnabled={isCRTEnabled}
/>
<View style={styles.separator}/>
{canEnableDisableCalls &&
Expand Down
2 changes: 2 additions & 0 deletions app/screens/channel_info/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import {
observeCurrentTeamId,
observeCurrentUserId,
} from '@queries/servers/system';
import {observeIsCRTEnabled} from '@queries/servers/thread';
import {observeCurrentUser, observeUserIsChannelAdmin, observeUserIsTeamAdmin} from '@queries/servers/user';
import {isTypeDMorGM} from '@utils/channel';
import {isMinimumServerVersion} from '@utils/helpers';
Expand Down Expand Up @@ -110,6 +111,7 @@ const enhanced = withObservables([], ({serverUrl, database}: Props) => {
canEnableDisableCalls,
isCallsEnabledInChannel,
canManageMembers,
isCRTEnabled: observeIsCRTEnabled(database),
};
});

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import React, {useState} from 'react';
import {useIntl} from 'react-intl';

import {updateChannelNotifyProps} from '@actions/remote/channel';
import OptionItem from '@components/option_item';
import {useServerUrl} from '@context/server';
import {preventDoubleTap} from '@utils/tap';

type Props = {
channelId: string;
followedStatus: boolean;
};

const AutoFollowThreads = ({channelId, followedStatus}: Props) => {
const [autoFollow, setAutoFollow] = useState(followedStatus);
const serverUrl = useServerUrl();
const {formatMessage} = useIntl();

const toggleFollow = preventDoubleTap(() => {
const props: Partial<ChannelNotifyProps> = {
channel_auto_follow_threads: followedStatus ? 'off' : 'on',
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you should be using the constants declared in the constants/channel file

};
setAutoFollow(!autoFollow);
updateChannelNotifyProps(serverUrl, channelId, props);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what happens if this fails? I know is the same with other options, just want to see what would be the consequence and if we should also thing about this for the other options as well.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay need to add checks for this and other option as well

});

return (
<OptionItem
action={toggleFollow}
label={formatMessage({id: 'channel_info.channel_auto_follow_threads', defaultMessage: 'Follow all threads in this channel'})}
icon='message-plus-outline'
type='toggle'
selected={autoFollow}
testID={`channel_info.options.channel_auto_follow_threads.option.toggled.${autoFollow}`}
/>
);
};

export default AutoFollowThreads;
33 changes: 33 additions & 0 deletions app/screens/channel_info/options/auto_follow_threads/index.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {withDatabase} from '@nozbe/watermelondb/DatabaseProvider';
import withObservables from '@nozbe/with-observables';
import {of as of$} from 'rxjs';
import {switchMap} from 'rxjs/operators';

import {Channel} from '@constants';
import {observeChannelSettings} from '@queries/servers/channel';

import AutoFollowThreads from './auto_follow_threads';

import type {WithDatabaseArgs} from '@typings/database/database';

type Props = WithDatabaseArgs & {
channelId: string;
}

const enhanced = withObservables(['channelId'], ({channelId, database}: Props) => {
const settings = observeChannelSettings(database, channelId);
const followedStatus = settings.pipe(
switchMap((s) => {
return of$(s?.notifyProps?.channel_auto_follow_threads === Channel.CHANNEL_AUTO_FOLLOW_THREADS_TRUE);
}),
);

return {
followedStatus,
};
});

export default withDatabase(enhanced(AutoFollowThreads));
10 changes: 8 additions & 2 deletions app/screens/channel_info/options/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {General} from '@constants';
import {isTypeDMorGM} from '@utils/channel';

import AddMembers from './add_members';
import AutoFollowThreads from './auto_follow_threads';
import ChannelFiles from './channel_files';
import EditChannel from './edit_channel';
import IgnoreMentions from './ignore_mentions';
Expand All @@ -20,21 +21,26 @@ type Props = {
type?: ChannelType;
callsEnabled: boolean;
canManageMembers: boolean;
isCRTEnabled: boolean;
}

const Options = ({
channelId,
type,
callsEnabled,
canManageMembers,
isCRTEnabled,
}: Props) => {
const isDMorGM = isTypeDMorGM(type);

return (
<>
{type !== General.DM_CHANNEL &&
{isCRTEnabled && (
<AutoFollowThreads channelId={channelId}/>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does this also apply to DM's ?

)}
{type !== General.DM_CHANNEL && (
<IgnoreMentions channelId={channelId}/>
}
)}
<NotificationPreference channelId={channelId}/>
<PinnedMessages channelId={channelId}/>
<ChannelFiles channelId={channelId}/>
Expand Down
1 change: 1 addition & 0 deletions types/api/channels.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type ChannelNotifyProps = {
mark_unread: 'all' | 'mention';
push: NotificationLevel;
ignore_channel_mentions: 'default' | 'off' | 'on';
channel_auto_follow_threads: 'on' | 'off';
push_threads: 'all' | 'mention';
};
type Channel = {
Expand Down