File tree Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Expand file tree Collapse file tree 3 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -166,7 +166,7 @@ class MessageList extends PureComponent {
166166 this . setState ( { newMessagesNotification : false } ) ;
167167 } ;
168168
169- userScrolledUp = ( ) => this . scrollOffset > 200 ;
169+ userScrolledUp = ( ) => this . scrollOffset > this . props . scrolledUpThreshold ;
170170
171171 listenToScroll = ( offset , reverseOffset , threshold ) => {
172172 this . scrollOffset = offset ;
@@ -455,6 +455,8 @@ MessageList.propTypes = {
455455 * The user roles allowed to pin messages in various channel types
456456 */
457457 pinPermissions : /** @type {PropTypes.Validator<import('types').PinPermissions>> } */ ( PropTypes . object ) ,
458+ /** The pixel threshold to determine whether or not the user is scrolled up in the list */
459+ scrolledUpThreshold : PropTypes . number ,
458460} ;
459461
460462MessageList . defaultProps = {
@@ -471,6 +473,7 @@ MessageList.defaultProps = {
471473 noGroupByUser : false ,
472474 messageActions : Object . keys ( MESSAGE_ACTIONS ) ,
473475 pinPermissions : defaultPinPermissions ,
476+ scrolledUpThreshold : 200 ,
474477} ;
475478
476479export default withTranslationContext ( ( props ) => (
Original file line number Diff line number Diff line change @@ -59,6 +59,13 @@ const matchMarkdownLinks = (message) => {
5959 return links ;
6060} ;
6161
62+ /** @type {(message: string) => (string|null)[] } */
63+ const messageCodeBlocks = ( message ) => {
64+ const codeRegex = / ` ` ` [ a - z ] * \n [ \s \S ] * ?\n ` ` ` | ` [ a - z ] * [ \s \S ] * ?` / gm;
65+ const matches = message . match ( codeRegex ) ;
66+ return matches || [ ] ;
67+ } ;
68+
6269/** @type {(input: string, length: number) => string } */
6370export const truncate = ( input , length , end = '...' ) => {
6471 if ( input . length > length ) {
@@ -93,13 +100,15 @@ export const renderText = (text, mentioned_users) => {
93100
94101 let newText = text ;
95102 let markdownLinks = matchMarkdownLinks ( newText ) ;
103+ let codeBlocks = messageCodeBlocks ( newText ) ;
96104 // extract all valid links/emails within text and replace it with proper markup
97105 linkify . find ( newText ) . forEach ( ( { type, href, value } ) => {
106+ const linkIsInBlock = codeBlocks . some ( ( block ) => block ?. includes ( value ) ) ;
98107 // check if message is already markdown
99108 const noParsingNeeded =
100109 markdownLinks &&
101110 markdownLinks . filter ( ( text ) => text ?. indexOf ( href ) !== - 1 ) ;
102- if ( noParsingNeeded . length > 0 ) return ;
111+ if ( noParsingNeeded . length > 0 || linkIsInBlock ) return ;
103112
104113 const displayLink =
105114 type === 'email'
Original file line number Diff line number Diff line change @@ -673,6 +673,7 @@ export interface MessageListProps {
673673 e : React . MouseEvent ,
674674 mentioned_users : Client . UserResponse [ ] ,
675675 ) : void ;
676+ scrolledUpThreshold ?: number ;
676677}
677678
678679export interface ChannelHeaderProps {
You can’t perform that action at this time.
0 commit comments