-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Changes from 4 commits
a4417dd
d71b440
a870b65
bb8fb35
3bf2a2c
59d4d4d
65ce9d7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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', | ||
}; | ||
setAutoFollow(!autoFollow); | ||
updateChannelNotifyProps(serverUrl, channelId, props); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; |
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)); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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'; | ||
|
@@ -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}/> | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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}/> | ||
|
There was a problem hiding this comment.
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