@@ -87,6 +87,7 @@ public class CustomHtmlToSpannedConverter implements ContentHandler {
8787 private String mBaseUri ;
8888 private boolean isCode ;
8989 private boolean isStreamLink ;
90+ private static boolean isEmoji ;
9091
9192 public CustomHtmlToSpannedConverter (String source ,
9293 Html .ImageGetter imageGetter , Html .TagHandler tagHandler ,
@@ -174,7 +175,8 @@ private static void end(SpannableStringBuilder text, Class kind, Object repl) {
174175
175176 private static void startImg (SpannableStringBuilder text ,
176177 Attributes attributes , Html .ImageGetter img ) {
177- String src = attributes .getValue ("" , "src" );
178+ String cssClass = attributes .getValue ("class" );
179+ String src = cssClass != null && cssClass .startsWith ("emoji" ) ? attributes .getValue ("title" ) : attributes .getValue ("" , "src" );
178180 Drawable d = null ;
179181
180182 if (img != null ) {
@@ -268,6 +270,10 @@ private static void endSpan(SpannableStringBuilder text) {
268270 int where = text .getSpanStart (obj );
269271 text .removeSpan (obj );
270272 if (where != len ) {
273+ if (isEmoji ) {
274+ text .delete (where , len );
275+ return ;
276+ }
271277 Href h = (Href ) obj ;
272278 if (h != null && h .mHref != null ) {
273279 if (ZulipApp .get ().getEmail ().equals (h .mHref )) {
@@ -556,7 +562,13 @@ private void handleStartTag(String tag, Attributes attributes) {
556562 } else if (tag .equalsIgnoreCase ("span" )
557563 && "user-mention" .equals (attributes .getValue ("class" ))) {
558564 startSpan (mSpannableStringBuilder , attributes );
559- } else if (tag .equalsIgnoreCase ("u" )) {
565+ } else if (tag .equalsIgnoreCase ("span" )
566+ && attributes .getValue ("class" ) != null && attributes .getValue ("class" ).startsWith ("emoji" )) {
567+ isEmoji = true ;
568+ startImg (mSpannableStringBuilder , attributes , mEmojiGetter );
569+ startSpan (mSpannableStringBuilder , attributes );
570+ }
571+ else if (tag .equalsIgnoreCase ("u" )) {
560572 start (mSpannableStringBuilder , new Underline ());
561573 } else if (tag .equalsIgnoreCase ("sup" )) {
562574 start (mSpannableStringBuilder , new Super ());
@@ -580,6 +592,7 @@ private void handleStartTag(String tag, Attributes attributes) {
580592 handleP (mSpannableStringBuilder );
581593 start (mSpannableStringBuilder , new Header (tag .charAt (1 ) - '1' ));
582594 } else if (tag .equalsIgnoreCase ("img" )) {
595+ // makes emojis backward compatible
583596 String cssClass = attributes .getValue ("" , "class" );
584597 if (cssClass != null && cssClass .equals ("emoji" )) {
585598 startImg (mSpannableStringBuilder , attributes , mEmojiGetter );
@@ -639,6 +652,7 @@ private void handleEndTag(String tag) {
639652 }
640653 } else if (tag .equalsIgnoreCase ("span" )) {
641654 endSpan (mSpannableStringBuilder );
655+ isEmoji = false ;
642656 } else if (tag .equalsIgnoreCase ("u" )) {
643657 end (mSpannableStringBuilder , Underline .class , new UnderlineSpan ());
644658 } else if (tag .equalsIgnoreCase ("sup" )) {
0 commit comments