-
Notifications
You must be signed in to change notification settings - Fork 298
feat: allow to send thread reply to channel #2733
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 1 commit
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
39831cc
feat: allow to send thread reply to channel
MartinCupela 6dab139
feat: add error handling for thread search in MessageThreadReplyInCha…
MartinCupela 5a13b72
chore(deps): upgrade stream-chat-css to v5.11.0
MartinCupela dbcc3f8
chore(deps): upgrade stream-chat to v9.6.0
MartinCupela efa00c4
test: adjust test to stream-chat changes
MartinCupela 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
68 changes: 68 additions & 0 deletions
68
src/components/Message/MessageIsThreadReplyInChannelButtonIndicator.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,68 @@ | ||
| import React, { useEffect, useRef } from 'react'; | ||
| import type { LocalMessage } from 'stream-chat'; | ||
| import { formatMessage } from 'stream-chat'; | ||
| import { | ||
| useChannelActionContext, | ||
| useChannelStateContext, | ||
| useMessageContext, | ||
| useTranslationContext, | ||
| } from '../../context'; | ||
|
|
||
| export const MessageIsThreadReplyInChannelButtonIndicator = () => { | ||
| const { t } = useTranslationContext(); | ||
| const { channel } = useChannelStateContext(); | ||
| const { openThread } = useChannelActionContext(); | ||
| const { message } = useMessageContext(); | ||
| const parentMessageRef = useRef<LocalMessage | null | undefined>(undefined); | ||
|
|
||
| const querySearchParent = () => | ||
| channel | ||
| .getClient() | ||
| .search({ cid: channel.cid }, { id: message.parent_id }) | ||
| .then(({ results }) => { | ||
| if (!results.length) return; | ||
| parentMessageRef.current = formatMessage(results[0].message); | ||
| }); | ||
|
|
||
| useEffect(() => { | ||
| if ( | ||
| parentMessageRef.current || | ||
| parentMessageRef.current === null || | ||
| !message.parent_id | ||
| ) | ||
| return; | ||
| const localMessage = channel.state.findMessage(message.parent_id); | ||
| if (localMessage) { | ||
| parentMessageRef.current = localMessage; | ||
| return; | ||
| } | ||
| }, [channel, message]); | ||
|
|
||
| if (!message.parent_id) return null; | ||
|
|
||
| return ( | ||
| <div className='str-chat__message-is-thread-reply-button-wrapper'> | ||
| <button | ||
| className='str-chat__message-is-thread-reply-button' | ||
| data-testid='message-is-thread-reply-button' | ||
| onClick={async () => { | ||
| if (!parentMessageRef.current) { | ||
| // search query is performed here in order to prevent multiple search queries in useEffect | ||
| // due to the message list 3x remounting its items | ||
| await querySearchParent(); | ||
| if (parentMessageRef.current) { | ||
| openThread(parentMessageRef.current); | ||
| } else { | ||
| // prevent further search queries if the message is not found in the DB | ||
| parentMessageRef.current = null; | ||
| } | ||
| return; | ||
| } | ||
| openThread(parentMessageRef.current); | ||
| }} | ||
| > | ||
| {t<string>('Thread reply')} | ||
| </button> | ||
| </div> | ||
| ); | ||
| }; | ||
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
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,35 @@ | ||
| import { useMessageComposer } from './hooks'; | ||
| import React from 'react'; | ||
| import type { MessageComposerState } from 'stream-chat'; | ||
| import { useStateStore } from '../../store'; | ||
| import { useTranslationContext } from '../../context'; | ||
|
|
||
| const stateSelector = (state: MessageComposerState) => ({ | ||
| showReplyInChannel: state.showReplyInChannel, | ||
| }); | ||
|
|
||
| export const SendToChannelCheckbox = () => { | ||
| const { t } = useTranslationContext(); | ||
| const messageComposer = useMessageComposer(); | ||
| const { showReplyInChannel } = useStateStore(messageComposer.state, stateSelector); | ||
|
|
||
| if (messageComposer.editedMessage || !messageComposer.threadId) return null; | ||
|
|
||
| return ( | ||
| <div className='str-chat__send-to-channel-checkbox__container'> | ||
| <div className='str-chat__send-to-channel-checkbox__field'> | ||
| <input | ||
| id='send-to-channel-checkbox' | ||
| onClick={messageComposer.toggleShowReplyInChannel} | ||
| type='checkbox' | ||
| value={showReplyInChannel.toString()} | ||
| /> | ||
| <label htmlFor='send-to-channel-checkbox'> | ||
| {Object.keys(messageComposer.channel.state.members).length === 2 | ||
| ? t<string>('Also send as a direct message') | ||
| : t<string>('Also send in channel')} | ||
| </label> | ||
| </div> | ||
| </div> | ||
| ); | ||
| }; | ||
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.
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.
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.
To prevent surprises with forms, can you please add a
type="buttonprop to the<button />element?Also, please add error handling around
await querySearchParent(), as in case it fails, the failure will be reported as "Unhandled Promise Rejection" in customer apps, and there is nothing they can do about it.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.
Also, didn't we get rid of the generics of
t<string>()?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.
type='button'added