Repository navigation
feat: new composer thread #5223
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
Merged
Merged
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
475d546
Nav to empty thread on "reply in thread" instead of quote layout
diegolmello fbccbf8
Fetch thread header from messages
diegolmello d6781e5
SendThreadToChannel
diegolmello c618818
Add thread reply
diegolmello 96e0581
Fix unselected checkbox color
diegolmello 8a967b2
AlsoSendThreadToChannel user pref
diegolmello 24675d9
Cleanup
diegolmello a5f3242
Reply in dm
diegolmello 8fe36ad
lint
diegolmello 5ae561b
Fix tests
diegolmello File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
89 changes: 89 additions & 0 deletions
89
app/containers/MessageComposer/components/SendThreadToChannel.tsx
This file contains hidden or 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,89 @@ | ||
| import { TouchableWithoutFeedback } from 'react-native-gesture-handler'; | ||
| import { Text } from 'react-native'; | ||
| import React, { useEffect, useRef } from 'react'; | ||
| import { Subscription } from 'rxjs'; | ||
| import { Q } from '@nozbe/watermelondb'; | ||
|
|
||
| import { useRoomContext } from '../../../views/RoomView/context'; | ||
| import { useAlsoSendThreadToChannel, useMessageComposerApi } from '../context'; | ||
| import { CustomIcon } from '../../CustomIcon'; | ||
| import { useTheme } from '../../../theme'; | ||
| import sharedStyles from '../../../views/Styles'; | ||
| import I18n from '../../../i18n'; | ||
| import { useAppSelector } from '../../../lib/hooks'; | ||
| import database from '../../../lib/database'; | ||
| import { compareServerVersion } from '../../../lib/methods/helpers'; | ||
|
|
||
| export const SendThreadToChannel = (): React.ReactElement | null => { | ||
| const alsoSendThreadToChannel = useAlsoSendThreadToChannel(); | ||
| const { setAlsoSendThreadToChannel } = useMessageComposerApi(); | ||
| const { tmid } = useRoomContext(); | ||
| const { colors } = useTheme(); | ||
| const subscription = useRef<Subscription>(); | ||
| const alsoSendThreadToChannelUserPref = useAppSelector(state => state.login.user.alsoSendThreadToChannel); | ||
| const serverVersion = useAppSelector(state => state.server.version); | ||
|
|
||
| useEffect(() => { | ||
| if (!tmid) { | ||
| return; | ||
| } | ||
|
|
||
| if (compareServerVersion(serverVersion, 'lowerThan', '5.0.0')) { | ||
| setAlsoSendThreadToChannel(false); | ||
| return; | ||
| } | ||
|
|
||
| if (alsoSendThreadToChannelUserPref === 'always') { | ||
| setAlsoSendThreadToChannel(true); | ||
| return; | ||
| } | ||
| if (alsoSendThreadToChannelUserPref === 'never') { | ||
| setAlsoSendThreadToChannel(false); | ||
| return; | ||
| } | ||
|
|
||
| /** | ||
| * "default" sends a to channel only in the first message of the thread. | ||
| * We check if the thread exists by observing/subscribing to the query with tmid. | ||
| * If it doesn't exist, it means that this is the first message of the thread. So it's true. | ||
| * Otherwise, it's false. | ||
| * */ | ||
| if (alsoSendThreadToChannelUserPref === 'default') { | ||
| const db = database.active; | ||
| const observable = db.get('threads').query(Q.where('tmid', tmid)).observe(); | ||
|
|
||
| subscription.current = observable.subscribe(result => { | ||
| setAlsoSendThreadToChannel(!result.length); | ||
| }); | ||
| } | ||
|
|
||
| return () => { | ||
| subscription.current?.unsubscribe(); | ||
| }; | ||
| }, [tmid, alsoSendThreadToChannelUserPref, serverVersion, setAlsoSendThreadToChannel]); | ||
|
|
||
| if (!tmid) { | ||
| return null; | ||
| } | ||
|
|
||
| return ( | ||
| <TouchableWithoutFeedback | ||
| style={{ | ||
| flexDirection: 'row', | ||
| alignItems: 'center' | ||
| }} | ||
| onPress={() => setAlsoSendThreadToChannel(!alsoSendThreadToChannel)} | ||
| testID='composer-send-to-channel' | ||
| > | ||
| <CustomIcon | ||
| testID={alsoSendThreadToChannel ? 'send-to-channel-checked' : 'send-to-channel-unchecked'} | ||
| name={alsoSendThreadToChannel ? 'checkbox-checked' : 'checkbox-unchecked'} | ||
| size={24} | ||
| color={alsoSendThreadToChannel ? colors.buttonBackgroundPrimaryDefault : colors.strokeDark} | ||
| /> | ||
| <Text style={{ fontSize: 14, marginLeft: 8, ...sharedStyles.textRegular, color: colors.fontSecondaryInfo }}> | ||
| {I18n.t('Messagebox_Send_to_channel')} | ||
| </Text> | ||
| </TouchableWithoutFeedback> | ||
| ); | ||
| }; |
This file contains hidden or 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 hidden or 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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.