~singpolyma/cheogram-android

f9a3194f4568287c7839cebd33c6a556468dfa21 — Stephen Paul Weber 9 months ago 481dbc5
Re-send presence to a MUC if sending custom emoji

To try to bump us up in terms of which client gets IQs so the bob
queries are more likely to come to us.
M src/main/java/eu/siacs/conversations/entities/Message.java => src/main/java/eu/siacs/conversations/entities/Message.java +10 -0
@@ 1233,6 1233,16 @@ public class Message extends AbstractEntity implements AvatarService.Avatarable 
        return treatAsDownloadable;
    }

    public synchronized boolean hasCustomEmoji() {
        if (getHtml() != null) {
            SpannableStringBuilder spannable = getSpannableBody(null, null);
            ImageSpan[] imageSpans = spannable.getSpans(0, spannable.length(), ImageSpan.class);
            return imageSpans.length > 0;
        }

        return false;
    }

    public synchronized boolean bodyIsOnlyEmojis() {
        if (isEmojisOnly == null) {
            isEmojisOnly = Emoticons.isOnlyEmoji(getBody().replaceAll("\\s", ""));

M src/main/java/eu/siacs/conversations/services/XmppConnectionService.java => src/main/java/eu/siacs/conversations/services/XmppConnectionService.java +15 -6
@@ 1964,6 1964,9 @@ public class XmppConnectionService extends Service {
                }
            }
            sendMessagePacket(account, packet);
            if (message.getConversation().getMode() == Conversation.MODE_MULTI && message.hasCustomEmoji()) {
                if (message.getConversation() instanceof Conversation) presenceToMuc((Conversation) message.getConversation());
            }
        }
    }



@@ 3526,6 3529,17 @@ public class XmppConnectionService extends Service {
        }
    }

    public void presenceToMuc(final Conversation conversation) {
        final MucOptions options = conversation.getMucOptions();
        if (options.online()) {
            Account account = conversation.getAccount();
            final Jid joinJid = options.getSelf().getFullJid();
            final PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, options.nonanonymous(), options.getSelf().getNick());
            packet.setTo(joinJid);
            sendPresencePacket(account, packet);
        }
    }

    public boolean renameInMuc(final Conversation conversation, final String nick, final UiCallback<Conversation> callback) {
        final MucOptions options = conversation.getMucOptions();
        final Jid joinJid = options.createJoinJid(nick);


@@ 4397,12 4411,7 @@ public class XmppConnectionService extends Service {
            Log.d(Config.LOGTAG, account.getJid().asBareJid() + ": avatar changed. resending presence to online group chats");
            for (Conversation conversation : conversations) {
                if (conversation.getAccount() == account && conversation.getMode() == Conversational.MODE_MULTI) {
                    final MucOptions mucOptions = conversation.getMucOptions();
                    if (mucOptions.online()) {
                        PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous(), mucOptions.getSelf().getNick());
                        packet.setTo(mucOptions.getSelf().getFullJid());
                        connection.sendPresencePacket(packet);
                    }
                    presenceToMuc(conversation);
                }
            }
        }