forked from platrum/mattermost-mobile
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MM 45015 - auto follow threads (mattermost#7463)
* auto follow select option added * unused code removed * auto follow threads condition fixed on CRT enabled * error handles --------- Co-authored-by: Mattermost Build <[email protected]>
- Loading branch information
1 parent
4282941
commit 551a01f
Showing
10 changed files
with
142 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
app/screens/channel_info/options/auto_follow_threads/auto_follow_threads.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// 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 { | ||
CHANNEL_AUTO_FOLLOW_THREADS_FALSE, | ||
CHANNEL_AUTO_FOLLOW_THREADS_TRUE, | ||
} from '@constants/channel'; | ||
import {useServerUrl} from '@context/server'; | ||
import {t} from '@i18n'; | ||
import {alertErrorWithFallback} from '@utils/draft'; | ||
import {preventDoubleTap} from '@utils/tap'; | ||
|
||
type Props = { | ||
channelId: string; | ||
followedStatus: boolean; | ||
displayName: string; | ||
}; | ||
|
||
const AutoFollowThreads = ({channelId, displayName, followedStatus}: Props) => { | ||
const [autoFollow, setAutoFollow] = useState(followedStatus); | ||
const serverUrl = useServerUrl(); | ||
const intl = useIntl(); | ||
|
||
const toggleFollow = preventDoubleTap(async () => { | ||
const props: Partial<ChannelNotifyProps> = { | ||
channel_auto_follow_threads: followedStatus ? CHANNEL_AUTO_FOLLOW_THREADS_FALSE : CHANNEL_AUTO_FOLLOW_THREADS_TRUE, | ||
}; | ||
setAutoFollow((v) => !v); | ||
const result = await updateChannelNotifyProps(serverUrl, channelId, props); | ||
if (result?.error) { | ||
alertErrorWithFallback( | ||
intl, | ||
result.error, | ||
{ | ||
id: t('channel_info.channel_auto_follow_threads_failed'), | ||
defaultMessage: 'An error occurred trying to auto follow all threads in channel {displayName}', | ||
}, | ||
{displayName}, | ||
); | ||
setAutoFollow((v) => !v); | ||
} | ||
}); | ||
|
||
return ( | ||
<OptionItem | ||
action={toggleFollow} | ||
label={intl.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; |
35 changes: 35 additions & 0 deletions
35
app/screens/channel_info/options/auto_follow_threads/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
// 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 {observeChannel, 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 channel = observeChannel(database, channelId); | ||
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, | ||
displayName: channel.pipe(switchMap((c) => of$(c?.displayName))), | ||
}; | ||
}); | ||
|
||
export default withDatabase(enhanced(AutoFollowThreads)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters