@@ -25,14 +25,15 @@ import * as ContentHelpers from 'matrix-js-sdk/src/content-helpers';
2525import  {  Element  as  ChildElement ,  parseFragment  as  parseHtml  }  from  "parse5" ; 
2626import  {  logger  }  from  "matrix-js-sdk/src/logger" ; 
2727import  {  IContent  }  from  'matrix-js-sdk/src/models/event' ; 
28+ import  {  MRoomTopicEventContent  }  from  'matrix-js-sdk/src/@types/topic' ; 
2829import  {  SlashCommand  as  SlashCommandEvent  }  from  "matrix-analytics-events/types/typescript/SlashCommand" ; 
2930
3031import  {  MatrixClientPeg  }  from  './MatrixClientPeg' ; 
3132import  dis  from  './dispatcher/dispatcher' ; 
3233import  {  _t ,  _td ,  ITranslatableError ,  newTranslatableError  }  from  './languageHandler' ; 
3334import  Modal  from  './Modal' ; 
3435import  MultiInviter  from  './utils/MultiInviter' ; 
35- import  {  linkifyAndSanitizeHtml  }  from  './HtmlUtils' ; 
36+ import  {  linkifyElement ,   topicToHtml  }  from  './HtmlUtils' ; 
3637import  QuestionDialog  from  "./components/views/dialogs/QuestionDialog" ; 
3738import  WidgetUtils  from  "./utils/WidgetUtils" ; 
3839import  {  textToHtmlRainbow  }  from  "./utils/colour" ; 
@@ -66,6 +67,7 @@ import { XOR } from "./@types/common";
6667import  {  PosthogAnalytics  }  from  "./PosthogAnalytics" ; 
6768import  {  ViewRoomPayload  }  from  "./dispatcher/payloads/ViewRoomPayload" ; 
6869import  VoipUserMapper  from  './VoipUserMapper' ; 
70+ import  {  htmlSerializeFromMdIfNeeded  }  from  './editor/serialize' ; 
6971import  {  leaveRoomBehaviour  }  from  "./utils/leave-behaviour" ; 
7072
7173// XXX: workaround for https://github.com/microsoft/TypeScript/issues/31816 
@@ -463,7 +465,8 @@ export const Commands = [
463465        runFn : function ( roomId ,  args )  { 
464466            const  cli  =  MatrixClientPeg . get ( ) ; 
465467            if  ( args )  { 
466-                 return  success ( cli . setRoomTopic ( roomId ,  args ) ) ; 
468+                 const  html  =  htmlSerializeFromMdIfNeeded ( args ,  {  forceHTML : false  } ) ; 
469+                 return  success ( cli . setRoomTopic ( roomId ,  args ,  html ) ) ; 
467470            } 
468471            const  room  =  cli . getRoom ( roomId ) ; 
469472            if  ( ! room )  { 
@@ -472,14 +475,18 @@ export const Commands = [
472475                ) ; 
473476            } 
474477
475-             const  topicEvents  =  room . currentState . getStateEvents ( 'm.room.topic' ,  '' ) ; 
476-             const  topic  =  topicEvents  &&  topicEvents . getContent ( ) . topic ; 
477-             const  topicHtml  =  topic  ? linkifyAndSanitizeHtml ( topic )  : _t ( 'This room has no topic.' ) ; 
478+             const  content : MRoomTopicEventContent  =  room . currentState . getStateEvents ( 'm.room.topic' ,  '' ) ?. getContent ( ) ; 
479+             const  topic  =  ! ! content  ? ContentHelpers . parseTopicContent ( content ) 
480+                 : {  text : _t ( 'This room has no topic.' )  } ; 
481+ 
482+             const  ref  =  e  =>  e  &&  linkifyElement ( e ) ; 
483+             const  body  =  topicToHtml ( topic . text ,  topic . html ,  ref ,  true ) ; 
478484
479485            Modal . createTrackedDialog ( 'Slash Commands' ,  'Topic' ,  InfoDialog ,  { 
480486                title : room . name , 
481-                 description : < div  dangerouslySetInnerHTML = { {   __html :  topicHtml   } }   / >, 
487+                 description : < div  ref = { ref } > {   body   } </ div > , 
482488                hasCloseButton : true , 
489+                 className : "markdown-body" , 
483490            } ) ; 
484491            return  success ( ) ; 
485492        } , 
0 commit comments