1515import io .micronaut .core .io .Readable ;
1616import io .micronaut .core .io .IOUtils ;
1717
18+ import org .jetbrains .annotations .NotNull ;
1819import org .slf4j .Logger ;
1920import org .slf4j .LoggerFactory ;
2021
@@ -97,27 +98,19 @@ private MemberProfile lookupUser(String userId) {
9798
9899 private String processText (String text , List <UUID > recipients ) {
99100 // First, process user references.
100- StringBuffer buffer = new StringBuffer (text .length ());
101- Pattern userRef = Pattern .compile ("<@([^>]+)>" );
102- Matcher action = userRef .matcher (StringEscapeUtils .unescapeHtml4 (text ));
103- while (action .find ()) {
104- // Pull out the recipient user id, get the profile and add it to
105- // the list of recipients.
106- String userId = action .group (1 );
107- MemberProfile profile = lookupUser (userId );
108- recipients .add (profile .getId ());
109-
110- // Replace the user reference with their full name.
111- action .appendReplacement (buffer , Matcher .quoteReplacement (
112- MemberProfileUtils .getFullName (profile )));
113- }
114- action .appendTail (buffer );
115- text = buffer .toString ();
101+ text = populateRecipientNames (text , recipients );
116102
117103 // Next, translate channel references to channel names.
104+ text = populateChannelNames (text );
105+
106+ return text ;
107+ }
108+
109+ @ NotNull
110+ private String populateChannelNames (String text ) {
118111 Pattern channelRef = Pattern .compile ("<#([^>]+)\\ |>" );
119- buffer = new StringBuffer (text .length ());
120- action = channelRef .matcher (text );
112+ StringBuffer buffer = new StringBuffer (text .length ());
113+ Matcher action = channelRef .matcher (text );
121114 while (action .find ()) {
122115 // Get the name of the channel.
123116 String channelId = action .group (1 );
@@ -131,7 +124,29 @@ private String processText(String text, List<UUID> recipients) {
131124 action .appendReplacement (buffer , Matcher .quoteReplacement (name ));
132125 }
133126 action .appendTail (buffer );
134- return buffer .toString ();
127+ text = buffer .toString ();
128+ return text ;
129+ }
130+
131+ @ NotNull
132+ private String populateRecipientNames (String text , List <UUID > recipients ) {
133+ StringBuffer buffer = new StringBuffer (text .length ());
134+ Pattern userRef = Pattern .compile ("<@([^>]+)>" );
135+ Matcher action = userRef .matcher (StringEscapeUtils .unescapeHtml4 (text ));
136+ while (action .find ()) {
137+ // Pull out the recipient user id, get the profile and add it to
138+ // the list of recipients.
139+ String userId = action .group (1 );
140+ MemberProfile profile = lookupUser (userId );
141+ recipients .add (profile .getId ());
142+
143+ // Replace the user reference with their full name.
144+ action .appendReplacement (buffer , Matcher .quoteReplacement (
145+ MemberProfileUtils .getFullName (profile )));
146+ }
147+ action .appendTail (buffer );
148+ text = buffer .toString ();
149+ return text ;
135150 }
136151
137152 private void requestAction () {
0 commit comments