@@ -87,6 +87,7 @@ public class CustomHtmlToSpannedConverter implements ContentHandler {
87
87
private String mBaseUri ;
88
88
private boolean isCode ;
89
89
private boolean isStreamLink ;
90
+ private static boolean isEmoji ;
90
91
91
92
public CustomHtmlToSpannedConverter (String source ,
92
93
Html .ImageGetter imageGetter , Html .TagHandler tagHandler ,
@@ -174,7 +175,8 @@ private static void end(SpannableStringBuilder text, Class kind, Object repl) {
174
175
175
176
private static void startImg (SpannableStringBuilder text ,
176
177
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" );
178
180
Drawable d = null ;
179
181
180
182
if (img != null ) {
@@ -268,6 +270,10 @@ private static void endSpan(SpannableStringBuilder text) {
268
270
int where = text .getSpanStart (obj );
269
271
text .removeSpan (obj );
270
272
if (where != len ) {
273
+ if (isEmoji ) {
274
+ text .delete (where , len );
275
+ return ;
276
+ }
271
277
Href h = (Href ) obj ;
272
278
if (h != null && h .mHref != null ) {
273
279
if (ZulipApp .get ().getEmail ().equals (h .mHref )) {
@@ -556,7 +562,13 @@ private void handleStartTag(String tag, Attributes attributes) {
556
562
} else if (tag .equalsIgnoreCase ("span" )
557
563
&& "user-mention" .equals (attributes .getValue ("class" ))) {
558
564
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" )) {
560
572
start (mSpannableStringBuilder , new Underline ());
561
573
} else if (tag .equalsIgnoreCase ("sup" )) {
562
574
start (mSpannableStringBuilder , new Super ());
@@ -580,6 +592,7 @@ private void handleStartTag(String tag, Attributes attributes) {
580
592
handleP (mSpannableStringBuilder );
581
593
start (mSpannableStringBuilder , new Header (tag .charAt (1 ) - '1' ));
582
594
} else if (tag .equalsIgnoreCase ("img" )) {
595
+ // makes emojis backward compatible
583
596
String cssClass = attributes .getValue ("" , "class" );
584
597
if (cssClass != null && cssClass .equals ("emoji" )) {
585
598
startImg (mSpannableStringBuilder , attributes , mEmojiGetter );
@@ -639,6 +652,7 @@ private void handleEndTag(String tag) {
639
652
}
640
653
} else if (tag .equalsIgnoreCase ("span" )) {
641
654
endSpan (mSpannableStringBuilder );
655
+ isEmoji = false ;
642
656
} else if (tag .equalsIgnoreCase ("u" )) {
643
657
end (mSpannableStringBuilder , Underline .class , new UnderlineSpan ());
644
658
} else if (tag .equalsIgnoreCase ("sup" )) {
0 commit comments