Search in sources :

Example 11 with MucOptions

use of eu.siacs.conversations.entities.MucOptions in project Conversations by siacs.

the class ConferenceDetailsActivity method onMucInfoUpdated.

private void onMucInfoUpdated(String subject, String name) {
    final MucOptions mucOptions = mConversation.getMucOptions();
    if (mucOptions.canChangeSubject() && changed(mucOptions.getSubject(), subject)) {
        xmppConnectionService.pushSubjectToConference(mConversation, subject);
    }
    if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER) && changed(mucOptions.getName(), name)) {
        Bundle options = new Bundle();
        options.putString("muc#roomconfig_persistentroom", "1");
        options.putString("muc#roomconfig_roomname", StringUtils.nullOnEmpty(name));
        xmppConnectionService.pushConferenceConfiguration(mConversation, options, this);
    }
}
Also used : MucOptions(eu.siacs.conversations.entities.MucOptions) Bundle(android.os.Bundle)

Example 12 with MucOptions

use of eu.siacs.conversations.entities.MucOptions in project Conversations by siacs.

the class PresenceParser method processConferencePresence.

private void processConferencePresence(PresencePacket packet, Conversation conversation) {
    MucOptions mucOptions = conversation.getMucOptions();
    final Jid jid = conversation.getAccount().getJid();
    final Jid from = packet.getFrom();
    if (!from.isBareJid()) {
        final String type = packet.getAttribute("type");
        final Element x = packet.findChild("x", Namespace.MUC_USER);
        Avatar avatar = Avatar.parsePresence(packet.findChild("x", "vcard-temp:x:update"));
        final List<String> codes = getStatusCodes(x);
        if (type == null) {
            if (x != null) {
                Element item = x.findChild("item");
                if (item != null && !from.isBareJid()) {
                    mucOptions.setError(MucOptions.Error.NONE);
                    MucOptions.User user = parseItem(conversation, item, from);
                    if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE) || (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && jid.equals(InvalidJid.getNullForInvalid(item.getAttributeAsJid("jid"))))) {
                        if (mucOptions.setOnline()) {
                            mXmppConnectionService.getAvatarService().clear(mucOptions);
                        }
                        if (mucOptions.setSelf(user)) {
                            Log.d(Config.LOGTAG, "role or affiliation changed");
                            mXmppConnectionService.databaseBackend.updateConversation(conversation);
                        }
                        mXmppConnectionService.persistSelfNick(user);
                        invokeRenameListener(mucOptions, true);
                    }
                    boolean isNew = mucOptions.updateUser(user);
                    final AxolotlService axolotlService = conversation.getAccount().getAxolotlService();
                    Contact contact = user.getContact();
                    if (isNew && user.getRealJid() != null && mucOptions.isPrivateAndNonAnonymous() && (contact == null || !contact.mutualPresenceSubscription()) && axolotlService.hasEmptyDeviceList(user.getRealJid())) {
                        axolotlService.fetchDeviceIds(user.getRealJid());
                    }
                    if (codes.contains(MucOptions.STATUS_CODE_ROOM_CREATED) && mucOptions.autoPushConfiguration()) {
                        Log.d(Config.LOGTAG, mucOptions.getAccount().getJid().asBareJid() + ": room '" + mucOptions.getConversation().getJid().asBareJid() + "' created. pushing default configuration");
                        mXmppConnectionService.pushConferenceConfiguration(mucOptions.getConversation(), IqGenerator.defaultChannelConfiguration(), null);
                    }
                    if (mXmppConnectionService.getPgpEngine() != null) {
                        Element signed = packet.findChild("x", "jabber:x:signed");
                        if (signed != null) {
                            Element status = packet.findChild("status");
                            String msg = status == null ? "" : status.getContent();
                            long keyId = mXmppConnectionService.getPgpEngine().fetchKeyId(mucOptions.getAccount(), msg, signed.getContent());
                            if (keyId != 0) {
                                user.setPgpKeyId(keyId);
                            }
                        }
                    }
                    if (avatar != null) {
                        avatar.owner = from;
                        if (mXmppConnectionService.getFileBackend().isAvatarCached(avatar)) {
                            if (user.setAvatar(avatar)) {
                                mXmppConnectionService.getAvatarService().clear(user);
                            }
                            if (user.getRealJid() != null) {
                                final Contact c = conversation.getAccount().getRoster().getContact(user.getRealJid());
                                c.setAvatar(avatar);
                                mXmppConnectionService.syncRoster(conversation.getAccount());
                                mXmppConnectionService.getAvatarService().clear(c);
                                mXmppConnectionService.updateRosterUi();
                            }
                        } else if (mXmppConnectionService.isDataSaverDisabled()) {
                            mXmppConnectionService.fetchAvatar(mucOptions.getAccount(), avatar);
                        }
                    }
                }
            }
        } else if (type.equals("unavailable")) {
            final boolean fullJidMatches = from.equals(mucOptions.getSelf().getFullJid());
            if (x.hasChild("destroy") && fullJidMatches) {
                Element destroy = x.findChild("destroy");
                final Jid alternate = destroy == null ? null : InvalidJid.getNullForInvalid(destroy.getAttributeAsJid("jid"));
                mucOptions.setError(MucOptions.Error.DESTROYED);
                if (alternate != null) {
                    Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": muc destroyed. alternate location " + alternate);
                }
            } else if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN) && fullJidMatches) {
                mucOptions.setError(MucOptions.Error.SHUTDOWN);
            } else if (codes.contains(MucOptions.STATUS_CODE_SELF_PRESENCE)) {
                if (codes.contains(MucOptions.STATUS_CODE_KICKED)) {
                    mucOptions.setError(MucOptions.Error.KICKED);
                } else if (codes.contains(MucOptions.STATUS_CODE_BANNED)) {
                    mucOptions.setError(MucOptions.Error.BANNED);
                } else if (codes.contains(MucOptions.STATUS_CODE_LOST_MEMBERSHIP)) {
                    mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
                } else if (codes.contains(MucOptions.STATUS_CODE_AFFILIATION_CHANGE)) {
                    mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
                } else if (codes.contains(MucOptions.STATUS_CODE_SHUTDOWN)) {
                    mucOptions.setError(MucOptions.Error.SHUTDOWN);
                } else if (!codes.contains(MucOptions.STATUS_CODE_CHANGED_NICK)) {
                    mucOptions.setError(MucOptions.Error.UNKNOWN);
                    Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
                }
            } else if (!from.isBareJid()) {
                Element item = x.findChild("item");
                if (item != null) {
                    mucOptions.updateUser(parseItem(conversation, item, from));
                }
                MucOptions.User user = mucOptions.deleteUser(from);
                if (user != null) {
                    mXmppConnectionService.getAvatarService().clear(user);
                }
            }
        } else if (type.equals("error")) {
            final Element error = packet.findChild("error");
            if (error == null) {
                return;
            }
            if (error.hasChild("conflict")) {
                if (mucOptions.online()) {
                    invokeRenameListener(mucOptions, false);
                } else {
                    mucOptions.setError(MucOptions.Error.NICK_IN_USE);
                }
            } else if (error.hasChild("not-authorized")) {
                mucOptions.setError(MucOptions.Error.PASSWORD_REQUIRED);
            } else if (error.hasChild("forbidden")) {
                mucOptions.setError(MucOptions.Error.BANNED);
            } else if (error.hasChild("registration-required")) {
                mucOptions.setError(MucOptions.Error.MEMBERS_ONLY);
            } else if (error.hasChild("resource-constraint")) {
                mucOptions.setError(MucOptions.Error.RESOURCE_CONSTRAINT);
            } else if (error.hasChild("remote-server-timeout")) {
                mucOptions.setError(MucOptions.Error.REMOTE_SERVER_TIMEOUT);
            } else if (error.hasChild("gone")) {
                final String gone = error.findChildContent("gone");
                final Jid alternate;
                if (gone != null) {
                    final XmppUri xmppUri = new XmppUri(gone);
                    if (xmppUri.isValidJid()) {
                        alternate = xmppUri.getJid();
                    } else {
                        alternate = null;
                    }
                } else {
                    alternate = null;
                }
                mucOptions.setError(MucOptions.Error.DESTROYED);
                if (alternate != null) {
                    Log.d(Config.LOGTAG, conversation.getAccount().getJid().asBareJid() + ": muc destroyed. alternate location " + alternate);
                }
            } else {
                final String text = error.findChildContent("text");
                if (text != null && text.contains("attribute 'to'")) {
                    if (mucOptions.online()) {
                        invokeRenameListener(mucOptions, false);
                    } else {
                        mucOptions.setError(MucOptions.Error.INVALID_NICK);
                    }
                } else {
                    mucOptions.setError(MucOptions.Error.UNKNOWN);
                    Log.d(Config.LOGTAG, "unknown error in conference: " + packet);
                }
            }
        }
    }
}
Also used : AxolotlService(eu.siacs.conversations.crypto.axolotl.AxolotlService) MucOptions(eu.siacs.conversations.entities.MucOptions) InvalidJid(eu.siacs.conversations.xmpp.InvalidJid) Jid(eu.siacs.conversations.xmpp.Jid) XmppUri(eu.siacs.conversations.utils.XmppUri) Element(eu.siacs.conversations.xml.Element) Avatar(eu.siacs.conversations.xmpp.pep.Avatar) Contact(eu.siacs.conversations.entities.Contact)

Example 13 with MucOptions

use of eu.siacs.conversations.entities.MucOptions in project Conversations by siacs.

the class ConversationFragment method onContactPictureClicked.

@Override
public void onContactPictureClicked(Message message) {
    String fingerprint;
    if (message.getEncryption() == Message.ENCRYPTION_PGP || message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
        fingerprint = "pgp";
    } else {
        fingerprint = message.getFingerprint();
    }
    final boolean received = message.getStatus() <= Message.STATUS_RECEIVED;
    if (received) {
        if (message.getConversation() instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
            Jid tcp = message.getTrueCounterpart();
            Jid user = message.getCounterpart();
            if (user != null && !user.isBareJid()) {
                final MucOptions mucOptions = ((Conversation) message.getConversation()).getMucOptions();
                if (mucOptions.participating() || ((Conversation) message.getConversation()).getNextCounterpart() != null) {
                    if (!mucOptions.isUserInRoom(user) && mucOptions.findUserByRealJid(tcp == null ? null : tcp.asBareJid()) == null) {
                        Toast.makeText(getActivity(), activity.getString(R.string.user_has_left_conference, user.getResource()), Toast.LENGTH_SHORT).show();
                    }
                    highlightInConference(user.getResource());
                } else {
                    Toast.makeText(getActivity(), R.string.you_are_not_participating, Toast.LENGTH_SHORT).show();
                }
            }
            return;
        } else {
            if (!message.getContact().isSelf()) {
                activity.switchToContactDetails(message.getContact(), fingerprint);
                return;
            }
        }
    }
    activity.switchToAccount(message.getConversation().getAccount(), fingerprint);
}
Also used : MucOptions(eu.siacs.conversations.entities.MucOptions) Jid(eu.siacs.conversations.xmpp.Jid) Conversation(eu.siacs.conversations.entities.Conversation)

Example 14 with MucOptions

use of eu.siacs.conversations.entities.MucOptions in project Conversations by siacs.

the class ConferenceDetailsActivity method updateView.

private void updateView() {
    invalidateOptionsMenu();
    if (mConversation == null) {
        return;
    }
    final MucOptions mucOptions = mConversation.getMucOptions();
    final User self = mucOptions.getSelf();
    String account;
    if (Config.DOMAIN_LOCK != null) {
        account = mConversation.getAccount().getJid().getEscapedLocal();
    } else {
        account = mConversation.getAccount().getJid().asBareJid().toEscapedString();
    }
    setTitle(mucOptions.isPrivateAndNonAnonymous() ? R.string.action_muc_details : R.string.channel_details);
    this.binding.editMucNameButton.setVisibility((self.getAffiliation().ranks(MucOptions.Affiliation.OWNER) || mucOptions.canChangeSubject()) ? View.VISIBLE : View.GONE);
    this.binding.detailsAccount.setText(getString(R.string.using_account, account));
    if (mConversation.isPrivateAndNonAnonymous()) {
        this.binding.jid.setText(getString(R.string.hosted_on, mConversation.getJid().getDomain()));
    } else {
        this.binding.jid.setText(mConversation.getJid().asBareJid().toEscapedString());
    }
    AvatarWorkerTask.loadAvatar(mConversation, binding.yourPhoto, R.dimen.avatar_on_details_screen_size);
    String roomName = mucOptions.getName();
    String subject = mucOptions.getSubject();
    final boolean hasTitle;
    if (printableValue(roomName)) {
        this.binding.mucTitle.setText(EmojiWrapper.transform(roomName));
        this.binding.mucTitle.setVisibility(View.VISIBLE);
        hasTitle = true;
    } else if (!printableValue(subject)) {
        this.binding.mucTitle.setText(EmojiWrapper.transform(mConversation.getName()));
        hasTitle = true;
        this.binding.mucTitle.setVisibility(View.VISIBLE);
    } else {
        hasTitle = false;
        this.binding.mucTitle.setVisibility(View.GONE);
    }
    if (printableValue(subject)) {
        SpannableStringBuilder spannable = new SpannableStringBuilder(subject);
        StylingHelper.format(spannable, this.binding.mucSubject.getCurrentTextColor());
        MyLinkify.addLinks(spannable, false);
        this.binding.mucSubject.setText(EmojiWrapper.transform(spannable));
        this.binding.mucSubject.setTextAppearance(this, subject.length() > (hasTitle ? 128 : 196) ? R.style.TextAppearance_Conversations_Body1_Linkified : R.style.TextAppearance_Conversations_Subhead);
        this.binding.mucSubject.setAutoLinkMask(0);
        this.binding.mucSubject.setVisibility(View.VISIBLE);
        this.binding.mucSubject.setMovementMethod(LinkMovementMethod.getInstance());
    } else {
        this.binding.mucSubject.setVisibility(View.GONE);
    }
    this.binding.mucYourNick.setText(mucOptions.getActualNick());
    if (mucOptions.online()) {
        this.binding.usersWrapper.setVisibility(View.VISIBLE);
        this.binding.mucInfoMore.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
        this.binding.mucRole.setVisibility(View.VISIBLE);
        this.binding.mucRole.setText(getStatus(self));
        if (mucOptions.getSelf().getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
            this.binding.mucSettings.setVisibility(View.VISIBLE);
            this.binding.mucConferenceType.setText(MucConfiguration.describe(this, mucOptions));
        } else if (!mucOptions.isPrivateAndNonAnonymous() && mucOptions.nonanonymous()) {
            this.binding.mucSettings.setVisibility(View.VISIBLE);
            this.binding.mucConferenceType.setText(R.string.group_chat_will_make_your_jabber_id_public);
        } else {
            this.binding.mucSettings.setVisibility(View.GONE);
        }
        if (mucOptions.mamSupport()) {
            this.binding.mucInfoMam.setText(R.string.server_info_available);
        } else {
            this.binding.mucInfoMam.setText(R.string.server_info_unavailable);
        }
        if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
            this.binding.changeConferenceButton.setVisibility(View.VISIBLE);
        } else {
            this.binding.changeConferenceButton.setVisibility(View.INVISIBLE);
        }
    } else {
        this.binding.usersWrapper.setVisibility(View.GONE);
        this.binding.mucInfoMore.setVisibility(View.GONE);
        this.binding.mucSettings.setVisibility(View.GONE);
    }
    int ic_notifications = getThemeResource(R.attr.icon_notifications, R.drawable.ic_notifications_black_24dp);
    int ic_notifications_off = getThemeResource(R.attr.icon_notifications_off, R.drawable.ic_notifications_off_black_24dp);
    int ic_notifications_paused = getThemeResource(R.attr.icon_notifications_paused, R.drawable.ic_notifications_paused_black_24dp);
    int ic_notifications_none = getThemeResource(R.attr.icon_notifications_none, R.drawable.ic_notifications_none_black_24dp);
    long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
    if (mutedTill == Long.MAX_VALUE) {
        this.binding.notificationStatusText.setText(R.string.notify_never);
        this.binding.notificationStatusButton.setImageResource(ic_notifications_off);
    } else if (System.currentTimeMillis() < mutedTill) {
        this.binding.notificationStatusText.setText(R.string.notify_paused);
        this.binding.notificationStatusButton.setImageResource(ic_notifications_paused);
    } else if (mConversation.alwaysNotify()) {
        this.binding.notificationStatusText.setText(R.string.notify_on_all_messages);
        this.binding.notificationStatusButton.setImageResource(ic_notifications);
    } else {
        this.binding.notificationStatusText.setText(R.string.notify_only_when_highlighted);
        this.binding.notificationStatusButton.setImageResource(ic_notifications_none);
    }
    final List<User> users = mucOptions.getUsers();
    Collections.sort(users, (a, b) -> {
        if (b.getAffiliation().outranks(a.getAffiliation())) {
            return 1;
        } else if (a.getAffiliation().outranks(b.getAffiliation())) {
            return -1;
        } else {
            if (a.getAvatar() != null && b.getAvatar() == null) {
                return -1;
            } else if (a.getAvatar() == null && b.getAvatar() != null) {
                return 1;
            } else {
                return a.getComparableName().compareToIgnoreCase(b.getComparableName());
            }
        }
    });
    this.mUserPreviewAdapter.submitList(MucOptions.sub(users, GridManager.getCurrentColumnCount(binding.users)));
    this.binding.invite.setVisibility(mucOptions.canInvite() ? View.VISIBLE : View.GONE);
    this.binding.showUsers.setVisibility(users.size() > 0 ? View.VISIBLE : View.GONE);
    this.binding.showUsers.setText(getResources().getQuantityString(R.plurals.view_users, users.size(), users.size()));
    this.binding.usersWrapper.setVisibility(users.size() > 0 || mucOptions.canInvite() ? View.VISIBLE : View.GONE);
    if (users.size() == 0) {
        this.binding.noUsersHints.setText(mucOptions.isPrivateAndNonAnonymous() ? R.string.no_users_hint_group_chat : R.string.no_users_hint_channel);
        this.binding.noUsersHints.setVisibility(View.VISIBLE);
    } else {
        this.binding.noUsersHints.setVisibility(View.GONE);
    }
}
Also used : MucOptions(eu.siacs.conversations.entities.MucOptions) User(eu.siacs.conversations.entities.MucOptions.User) SpannableStringBuilder(android.text.SpannableStringBuilder)

Example 15 with MucOptions

use of eu.siacs.conversations.entities.MucOptions in project Conversations by siacs.

the class ConferenceDetailsActivity method afterTextChanged.

@Override
public void afterTextChanged(Editable s) {
    if (mConversation == null) {
        return;
    }
    final MucOptions mucOptions = mConversation.getMucOptions();
    if (this.binding.mucEditor.getVisibility() == View.VISIBLE) {
        boolean subjectChanged = changed(binding.mucEditSubject.getEditableText().toString(), mucOptions.getSubject());
        boolean nameChanged = changed(binding.mucEditTitle.getEditableText().toString(), mucOptions.getName());
        if (subjectChanged || nameChanged) {
            this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_save, R.drawable.ic_save_black_24dp));
        } else {
            this.binding.editMucNameButton.setImageResource(getThemeResource(R.attr.icon_cancel, R.drawable.ic_cancel_black_24dp));
        }
    }
}
Also used : MucOptions(eu.siacs.conversations.entities.MucOptions)

Aggregations

MucOptions (eu.siacs.conversations.entities.MucOptions)17 Conversation (eu.siacs.conversations.entities.Conversation)7 Jid (eu.siacs.conversations.xmpp.Jid)7 Account (eu.siacs.conversations.entities.Account)5 Bookmark (eu.siacs.conversations.entities.Bookmark)4 User (eu.siacs.conversations.entities.MucOptions.User)4 Contact (eu.siacs.conversations.entities.Contact)3 PresencePacket (eu.siacs.conversations.xmpp.stanzas.PresencePacket)3 Bundle (android.os.Bundle)2 SpannableStringBuilder (android.text.SpannableStringBuilder)2 MenuItem (android.view.MenuItem)2 Message (eu.siacs.conversations.entities.Message)2 EditMessage (eu.siacs.conversations.ui.widget.EditMessage)2 SuppressLint (android.annotation.SuppressLint)1 Activity (android.app.Activity)1 PendingIntent (android.app.PendingIntent)1 Context (android.content.Context)1 Intent (android.content.Intent)1 Uri (android.net.Uri)1 Editable (android.text.Editable)1