Search in sources :

Example 16 with MucOptions

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

the class AvatarService method get.

public Bitmap get(Message message, int size, boolean cachedOnly) {
    final Conversational conversation = message.getConversation();
    if (message.getType() == Message.TYPE_STATUS && message.getCounterparts() != null && message.getCounterparts().size() > 1) {
        return get(message.getCounterparts(), size, cachedOnly);
    } else if (message.getStatus() == Message.STATUS_RECEIVED) {
        Contact c = message.getContact();
        if (c != null && (c.getProfilePhoto() != null || c.getAvatarFilename() != null)) {
            return get(c, size, cachedOnly);
        } else if (conversation instanceof Conversation && message.getConversation().getMode() == Conversation.MODE_MULTI) {
            final Jid trueCounterpart = message.getTrueCounterpart();
            final MucOptions mucOptions = ((Conversation) conversation).getMucOptions();
            MucOptions.User user;
            if (trueCounterpart != null) {
                user = mucOptions.findOrCreateUserByRealJid(trueCounterpart, message.getCounterpart());
            } else {
                user = mucOptions.findUserByFullJid(message.getCounterpart());
            }
            if (user != null) {
                return getImpl(user, size, cachedOnly);
            }
        } else if (c != null) {
            return get(c, size, cachedOnly);
        }
        Jid tcp = message.getTrueCounterpart();
        String seed = tcp != null ? tcp.asBareJid().toString() : null;
        return get(UIHelper.getMessageDisplayName(message), seed, size, cachedOnly);
    } else {
        return get(conversation.getAccount(), size, cachedOnly);
    }
}
Also used : Conversational(eu.siacs.conversations.entities.Conversational) MucOptions(eu.siacs.conversations.entities.MucOptions) Jid(eu.siacs.conversations.xmpp.Jid) Conversation(eu.siacs.conversations.entities.Conversation) Contact(eu.siacs.conversations.entities.Contact)

Example 17 with MucOptions

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

the class MucDetailsContextMenuHelper method configureMucDetailsContextMenu.

public static void configureMucDetailsContextMenu(Activity activity, Menu menu, Conversation conversation, User user) {
    final MucOptions mucOptions = conversation.getMucOptions();
    final boolean advancedMode = PreferenceManager.getDefaultSharedPreferences(activity).getBoolean("advanced_muc_mode", false);
    final boolean isGroupChat = mucOptions.isPrivateAndNonAnonymous();
    MenuItem sendPrivateMessage = menu.findItem(R.id.send_private_message);
    if (user != null && user.getRealJid() != null) {
        MenuItem showContactDetails = menu.findItem(R.id.action_contact_details);
        MenuItem startConversation = menu.findItem(R.id.start_conversation);
        MenuItem giveMembership = menu.findItem(R.id.give_membership);
        MenuItem removeMembership = menu.findItem(R.id.remove_membership);
        MenuItem giveAdminPrivileges = menu.findItem(R.id.give_admin_privileges);
        MenuItem giveOwnerPrivileges = menu.findItem(R.id.give_owner_privileges);
        MenuItem removeOwnerPrivileges = menu.findItem(R.id.revoke_owner_privileges);
        MenuItem removeAdminPrivileges = menu.findItem(R.id.remove_admin_privileges);
        MenuItem removeFromRoom = menu.findItem(R.id.remove_from_room);
        MenuItem managePermissions = menu.findItem(R.id.manage_permissions);
        removeFromRoom.setTitle(isGroupChat ? R.string.remove_from_room : R.string.remove_from_channel);
        MenuItem banFromConference = menu.findItem(R.id.ban_from_conference);
        banFromConference.setTitle(isGroupChat ? R.string.ban_from_conference : R.string.ban_from_channel);
        MenuItem invite = menu.findItem(R.id.invite);
        startConversation.setVisible(true);
        final Contact contact = user.getContact();
        final User self = conversation.getMucOptions().getSelf();
        if ((contact != null && contact.showInRoster()) || mucOptions.isPrivateAndNonAnonymous()) {
            showContactDetails.setVisible(contact == null || !contact.isSelf());
        }
        if ((activity instanceof ConferenceDetailsActivity || activity instanceof MucUsersActivity) && user.getRole() == MucOptions.Role.NONE) {
            invite.setVisible(true);
        }
        boolean managePermissionsVisible = false;
        if ((self.getAffiliation().ranks(MucOptions.Affiliation.ADMIN) && self.getAffiliation().outranks(user.getAffiliation())) || self.getAffiliation() == MucOptions.Affiliation.OWNER) {
            if (advancedMode) {
                if (!user.getAffiliation().ranks(MucOptions.Affiliation.MEMBER)) {
                    managePermissionsVisible = true;
                    giveMembership.setVisible(true);
                } else if (user.getAffiliation() == MucOptions.Affiliation.MEMBER) {
                    managePermissionsVisible = true;
                    removeMembership.setVisible(true);
                }
                if (!Config.DISABLE_BAN) {
                    managePermissionsVisible = true;
                    banFromConference.setVisible(true);
                }
            } else {
                if (!Config.DISABLE_BAN || conversation.getMucOptions().membersOnly()) {
                    removeFromRoom.setVisible(true);
                }
            }
        }
        if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
            if (isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.OWNER) {
                if (!user.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
                    managePermissionsVisible = true;
                    giveOwnerPrivileges.setVisible(true);
                } else if (user.getAffiliation() == MucOptions.Affiliation.OWNER) {
                    managePermissionsVisible = true;
                    removeOwnerPrivileges.setVisible(true);
                }
            }
            if (!isGroupChat || advancedMode || user.getAffiliation() == MucOptions.Affiliation.ADMIN) {
                if (!user.getAffiliation().ranks(MucOptions.Affiliation.ADMIN)) {
                    managePermissionsVisible = true;
                    giveAdminPrivileges.setVisible(true);
                } else if (user.getAffiliation() == MucOptions.Affiliation.ADMIN) {
                    managePermissionsVisible = true;
                    removeAdminPrivileges.setVisible(true);
                }
            }
        }
        managePermissions.setVisible(managePermissionsVisible);
        sendPrivateMessage.setVisible(!isGroupChat && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR));
    } else {
        sendPrivateMessage.setVisible(true);
        sendPrivateMessage.setEnabled(user != null && mucOptions.allowPm() && user.getRole().ranks(MucOptions.Role.VISITOR));
    }
}
Also used : MucUsersActivity(eu.siacs.conversations.ui.MucUsersActivity) MucOptions(eu.siacs.conversations.entities.MucOptions) User(eu.siacs.conversations.entities.MucOptions.User) ConferenceDetailsActivity(eu.siacs.conversations.ui.ConferenceDetailsActivity) MenuItem(android.view.MenuItem) Contact(eu.siacs.conversations.entities.Contact)

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