Search in sources :

Example 1 with MucOptions

use of de.pixart.messenger.entities.MucOptions in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method pushSubjectToConference.

public void pushSubjectToConference(final Conversation conference, final String subject) {
    MessagePacket packet = this.getMessageGenerator().conferenceSubject(conference, subject);
    this.sendMessagePacket(conference.getAccount(), packet);
    final MucOptions mucOptions = conference.getMucOptions();
    final MucOptions.User self = mucOptions.getSelf();
    if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
        Bundle options = new Bundle();
        options.putString("muc#roomconfig_persistentroom", "1");
        options.putString("muc#roomconfig_roomname", subject);
        this.pushConferenceConfiguration(conference, options, null);
    }
}
Also used : MessagePacket(de.pixart.messenger.xmpp.stanzas.MessagePacket) MucOptions(de.pixart.messenger.entities.MucOptions) Bundle(android.os.Bundle)

Example 2 with MucOptions

use of de.pixart.messenger.entities.MucOptions in project Pix-Art-Messenger by kriztan.

the class XmppConnectionService method joinMuc.

private void joinMuc(Conversation conversation, final OnConferenceJoined onConferenceJoined, final boolean followedInvite) {
    Account account = conversation.getAccount();
    account.pendingConferenceJoins.remove(conversation);
    account.pendingConferenceLeaves.remove(conversation);
    if (account.getStatus() == Account.State.ONLINE) {
        // disabled for testing strange MUC leaves
        sendPresencePacket(account, mPresenceGenerator.leave(conversation.getMucOptions()));
        conversation.resetMucOptions();
        if (onConferenceJoined != null) {
            conversation.getMucOptions().flagNoAutoPushConfiguration();
        }
        conversation.setHasMessagesLeftOnServer(false);
        fetchConferenceConfiguration(conversation, new OnConferenceConfigurationFetched() {

            private void join(Conversation conversation) {
                Account account = conversation.getAccount();
                final MucOptions mucOptions = conversation.getMucOptions();
                final Jid joinJid = mucOptions.getSelf().getFullJid();
                Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": joining conversation " + joinJid.toString());
                PresencePacket packet = mPresenceGenerator.selfPresence(account, Presence.Status.ONLINE, mucOptions.nonanonymous() || onConferenceJoined != null);
                packet.setTo(joinJid);
                Element x = packet.addChild("x", "http://jabber.org/protocol/muc");
                if (conversation.getMucOptions().getPassword() != null) {
                    x.addChild("password").setContent(mucOptions.getPassword());
                }
                if (mucOptions.mamSupport()) {
                    // Use MAM instead of the limited muc history to get history
                    x.addChild("history").setAttribute("maxchars", "0");
                } else {
                    // Fallback to muc history
                    x.addChild("history").setAttribute("since", PresenceGenerator.getTimestamp(conversation.getLastMessageTransmitted().getTimestamp()));
                }
                sendPresencePacket(account, packet);
                if (onConferenceJoined != null) {
                    onConferenceJoined.onConferenceJoined(conversation);
                }
                if (!joinJid.equals(conversation.getJid())) {
                    conversation.setContactJid(joinJid);
                    databaseBackend.updateConversation(conversation);
                }
                if (mucOptions.mamSupport()) {
                    getMessageArchiveService().catchupMUC(conversation);
                }
                if (mucOptions.isPrivateAndNonAnonymous()) {
                    fetchConferenceMembers(conversation);
                    if (followedInvite && conversation.getBookmark() == null) {
                        saveConversationAsBookmark(conversation, null);
                    }
                }
                sendUnsentMessages(conversation);
            }

            @Override
            public void onConferenceConfigurationFetched(Conversation conversation) {
                join(conversation);
            }

            @Override
            public void onFetchFailed(final Conversation conversation, Element error) {
                if (error != null && "remote-server-not-found".equals(error.getName())) {
                    conversation.getMucOptions().setError(MucOptions.Error.SERVER_NOT_FOUND);
                    updateConversationUi();
                } else {
                    join(conversation);
                    fetchConferenceConfiguration(conversation);
                }
            }
        });
        updateConversationUi();
    } else {
        account.pendingConferenceJoins.add(conversation);
        conversation.resetMucOptions();
        conversation.setHasMessagesLeftOnServer(false);
        updateConversationUi();
    }
}
Also used : Account(de.pixart.messenger.entities.Account) MucOptions(de.pixart.messenger.entities.MucOptions) Jid(de.pixart.messenger.xmpp.jid.Jid) Element(de.pixart.messenger.xml.Element) Conversation(de.pixart.messenger.entities.Conversation) PresencePacket(de.pixart.messenger.xmpp.stanzas.PresencePacket)

Example 3 with MucOptions

use of de.pixart.messenger.entities.MucOptions in project Pix-Art-Messenger by kriztan.

the class ConferenceDetailsActivity method updateView.

private void updateView() {
    invalidateOptionsMenu();
    final MucOptions mucOptions = mConversation.getMucOptions();
    final User self = mucOptions.getSelf();
    String account;
    if (Config.DOMAIN_LOCK != null) {
        account = mConversation.getAccount().getJid().getLocalpart();
    } else {
        account = mConversation.getAccount().getJid().toBareJid().toString();
    }
    if (getSupportActionBar() != null) {
        final ActionBar ab = getSupportActionBar();
        if (ab != null) {
            ab.setCustomView(R.layout.ab_title);
            ab.setDisplayShowCustomEnabled(true);
            TextView abtitle = findViewById(android.R.id.text1);
            TextView absubtitle = findViewById(android.R.id.text2);
            abtitle.setText(mConversation.getName());
            abtitle.setSelected(true);
            abtitle.setClickable(false);
            absubtitle.setVisibility(View.GONE);
            absubtitle.setClickable(false);
        }
    }
    ConferenceName.setText(mConversation.getName());
    mAccountJid.setText(getString(R.string.using_account, account));
    if (xmppConnectionService.multipleAccounts()) {
        mAccountJid.setVisibility(View.VISIBLE);
    } else {
        mAccountJid.setVisibility(View.GONE);
    }
    mYourPhoto.setImageBitmap(avatarService().get(mConversation.getAccount(), getPixel(48)));
    setTitle(mConversation.getName());
    mFullJid.setText(mConversation.getJid().toBareJid().toString());
    mYourNick.setText(mucOptions.getActualNick());
    TextView mRoleAffiliaton = findViewById(R.id.muc_role);
    if (mucOptions.online()) {
        mMoreDetails.setVisibility(View.VISIBLE);
        mMucSettings.setVisibility(View.VISIBLE);
        mConferenceInfoTable.setVisibility(this.mAdvancedMode ? View.VISIBLE : View.GONE);
        final String status = getStatus(self);
        if (status != null) {
            mRoleAffiliaton.setVisibility(View.VISIBLE);
            mRoleAffiliaton.setText(status);
        } else {
            mRoleAffiliaton.setVisibility(View.GONE);
        }
        if (mucOptions.membersOnly()) {
            mConferenceType.setText(R.string.private_conference);
        } else {
            mConferenceType.setText(R.string.public_conference);
        }
        if (mucOptions.mamSupport()) {
            mConferenceInfoMam.setText(R.string.server_info_available);
        } else {
            mConferenceInfoMam.setText(R.string.server_info_unavailable);
        }
        if (self.getAffiliation().ranks(MucOptions.Affiliation.OWNER)) {
            mDestroyButton.setVisibility(View.VISIBLE);
            mChangeConferenceSettingsButton.setVisibility(View.VISIBLE);
        } else {
            mDestroyButton.setVisibility(View.GONE);
            mChangeConferenceSettingsButton.setVisibility(View.GONE);
        }
    } else {
        mMoreDetails.setVisibility(View.GONE);
        mMucSettings.setVisibility(View.GONE);
        mConferenceInfoTable.setVisibility(View.GONE);
    }
    long mutedTill = mConversation.getLongAttribute(Conversation.ATTRIBUTE_MUTED_TILL, 0);
    if (mutedTill == Long.MAX_VALUE) {
        mNotifyStatusText.setText(R.string.notify_never);
        mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_off_grey600_24dp);
    } else if (System.currentTimeMillis() < mutedTill) {
        mNotifyStatusText.setText(R.string.notify_paused);
        mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_paused_grey600_24dp);
    } else if (mConversation.alwaysNotify()) {
        mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_grey600_24dp);
        mNotifyStatusText.setText(R.string.notify_on_all_messages);
    } else {
        mNotifyStatusButton.setImageResource(R.drawable.ic_notifications_none_grey600_24dp);
        mNotifyStatusText.setText(R.string.notify_only_when_highlighted);
    }
    final LayoutInflater inflater = (LayoutInflater) getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    membersView.removeAllViews();
    if (inflater == null) {
        return;
    }
    final ArrayList<User> users = mucOptions.getUsers();
    Collections.sort(users);
    for (final User user : users) {
        ContactBinding binding = DataBindingUtil.inflate(inflater, R.layout.contact, membersView, false);
        final Contact contact = user.getContact();
        final String name = user.getName();
        this.setListItemBackgroundOnView(binding.getRoot());
        if (contact != null && contact.showInRoster()) {
            binding.getRoot().setOnClickListener((OnClickListener) view -> switchToContactDetails(contact));
        }
        registerForContextMenu(binding.getRoot());
        binding.getRoot().setTag(user);
        if (mAdvancedMode && user.getPgpKeyId() != 0) {
            binding.key.setVisibility(View.VISIBLE);
            binding.key.setOnClickListener(v -> viewPgpKey(user));
            binding.key.setText(OpenPgpUtils.convertKeyIdToHex(user.getPgpKeyId()));
        }
        if (contact != null) {
            binding.contactDisplayName.setText(contact.getDisplayName());
            binding.contactJid.setText((name != null ? name + " \u2022 " : "") + getStatus(user));
        } else {
            binding.contactDisplayName.setText(name == null ? "" : name);
            binding.contactJid.setText(getStatus(user));
        }
        loadAvatar(user, binding.contactPhoto);
        if (user.getRole() == MucOptions.Role.NONE) {
            binding.contactDisplayName.setAlpha(INACTIVE_ALPHA);
            binding.key.setAlpha(INACTIVE_ALPHA);
            binding.contactJid.setAlpha(INACTIVE_ALPHA);
            binding.contactPhoto.setAlpha(INACTIVE_ALPHA);
        }
        membersView.addView(binding.getRoot());
        if (mConversation.getMucOptions().canInvite()) {
            mInviteButton.setVisibility(View.VISIBLE);
        } else {
            mInviteButton.setVisibility(View.GONE);
        }
    }
}
Also used : ImageButton(android.widget.ImageButton) LinearLayout(android.widget.LinearLayout) Bundle(android.os.Bundle) ImageView(android.widget.ImageView) PendingIntent(android.app.PendingIntent) Drawable(android.graphics.drawable.Drawable) Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) User(de.pixart.messenger.entities.MucOptions.User) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) View(android.view.View) Button(android.widget.Button) SendIntentException(android.content.IntentSender.SendIntentException) Log(android.util.Log) XmppConnectionService(de.pixart.messenger.services.XmppConnectionService) ContactBinding(de.pixart.messenger.databinding.ContactBinding) AsyncTask(android.os.AsyncTask) CardView(android.support.v7.widget.CardView) BitmapDrawable(android.graphics.drawable.BitmapDrawable) PorterDuff(android.graphics.PorterDuff) Contact(de.pixart.messenger.entities.Contact) TextView(android.widget.TextView) PgpEngine(de.pixart.messenger.crypto.PgpEngine) RelativeLayout(android.widget.RelativeLayout) UIHelper(de.pixart.messenger.utils.UIHelper) Context(android.content.Context) ContextMenu(android.view.ContextMenu) Intent(android.content.Intent) OnMucRosterUpdate(de.pixart.messenger.services.XmppConnectionService.OnMucRosterUpdate) MenuItem(android.view.MenuItem) ArrayList(java.util.ArrayList) RejectedExecutionException(java.util.concurrent.RejectedExecutionException) Conversation(de.pixart.messenger.entities.Conversation) R(de.pixart.messenger.R) Toast(android.widget.Toast) Menu(android.view.Menu) WeakReference(java.lang.ref.WeakReference) Config(de.pixart.messenger.Config) ActionBar(android.support.v7.app.ActionBar) DialogInterface(android.content.DialogInterface) MucOptions(de.pixart.messenger.entities.MucOptions) Bookmark(de.pixart.messenger.entities.Bookmark) LayoutInflater(android.view.LayoutInflater) OnConversationUpdate(de.pixart.messenger.services.XmppConnectionService.OnConversationUpdate) TimeframeUtils(de.pixart.messenger.utils.TimeframeUtils) AlertDialog(android.support.v7.app.AlertDialog) Bitmap(android.graphics.Bitmap) DataBindingUtil(android.databinding.DataBindingUtil) Collections(java.util.Collections) Resources(android.content.res.Resources) OnClickListener(android.view.View.OnClickListener) OpenPgpUtils(org.openintents.openpgp.util.OpenPgpUtils) MucOptions(de.pixart.messenger.entities.MucOptions) User(de.pixart.messenger.entities.MucOptions.User) LayoutInflater(android.view.LayoutInflater) TextView(android.widget.TextView) ActionBar(android.support.v7.app.ActionBar) ContactBinding(de.pixart.messenger.databinding.ContactBinding) Contact(de.pixart.messenger.entities.Contact)

Example 4 with MucOptions

use of de.pixart.messenger.entities.MucOptions in project Pix-Art-Messenger by kriztan.

the class ConversationFragment method updateStatusMessages.

protected void updateStatusMessages() {
    updateDateBubbles();
    synchronized (this.messageList) {
        if (showLoadMoreMessages(conversation)) {
            this.messageList.add(0, Message.createLoadMoreMessage(conversation));
        }
        if (conversation.getMode() == Conversation.MODE_MULTI) {
            final MucOptions mucOptions = conversation.getMucOptions();
            final List<MucOptions.User> allUsers = mucOptions.getUsers();
            final Set<ReadByMarker> addedMarkers = new HashSet<>();
            ChatState state = ChatState.COMPOSING;
            List<MucOptions.User> users = conversation.getMucOptions().getUsersWithChatState(state, 5);
            if (users.size() == 0) {
                state = ChatState.PAUSED;
                users = conversation.getMucOptions().getUsersWithChatState(state, 5);
            }
            if (mucOptions.isPrivateAndNonAnonymous()) {
                for (int i = this.messageList.size() - 1; i >= 0; --i) {
                    final Set<ReadByMarker> markersForMessage = messageList.get(i).getReadByMarkers();
                    final List<MucOptions.User> shownMarkers = new ArrayList<>();
                    for (ReadByMarker marker : markersForMessage) {
                        if (!ReadByMarker.contains(marker, addedMarkers)) {
                            // may be put outside this condition. set should do dedup anyway
                            addedMarkers.add(marker);
                            MucOptions.User user = mucOptions.findUser(marker);
                            shownMarkers.add(user);
                        }
                    }
                    final ReadByMarker markerForSender = ReadByMarker.from(messageList.get(i));
                    final Message statusMessage;
                    final int size = shownMarkers.size();
                    if (size > 1) {
                        final String body;
                        if (size <= 4) {
                            body = getString(R.string.contacts_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers));
                        } else {
                            body = getString(R.string.contacts_and_n_more_have_read_up_to_this_point, UIHelper.concatNames(shownMarkers, 3), size - 3);
                        }
                        statusMessage = Message.createStatusMessage(conversation, body);
                        statusMessage.setCounterparts(shownMarkers);
                    } else if (size == 1) {
                        statusMessage = Message.createStatusMessage(conversation, getString(R.string.contact_has_read_up_to_this_point, UIHelper.getDisplayName(shownMarkers.get(0))));
                        statusMessage.setCounterpart(shownMarkers.get(0).getFullJid());
                        statusMessage.setTrueCounterpart(shownMarkers.get(0).getRealJid());
                    } else {
                        statusMessage = null;
                    }
                    if (statusMessage != null) {
                        this.messageList.add(i + 1, statusMessage);
                    }
                    addedMarkers.add(markerForSender);
                    if (ReadByMarker.allUsersRepresented(allUsers, addedMarkers)) {
                        break;
                    }
                }
            }
        }
    }
}
Also used : ChatState(de.pixart.messenger.xmpp.chatstate.ChatState) MucOptions(de.pixart.messenger.entities.MucOptions) EditMessage(de.pixart.messenger.ui.widget.EditMessage) Message(de.pixart.messenger.entities.Message) ReadByMarker(de.pixart.messenger.entities.ReadByMarker) ArrayList(java.util.ArrayList) SuppressLint(android.annotation.SuppressLint) HashSet(java.util.HashSet)

Example 5 with MucOptions

use of de.pixart.messenger.entities.MucOptions in project Pix-Art-Messenger by kriztan.

the class PresenceParser method parseConferencePresence.

public void parseConferencePresence(PresencePacket packet, Account account) {
    final Conversation conversation = packet.getFrom() == null ? null : mXmppConnectionService.find(account, packet.getFrom().toBareJid());
    if (conversation != null) {
        final MucOptions mucOptions = conversation.getMucOptions();
        boolean before = mucOptions.online();
        int count = mucOptions.getUserCount();
        final List<MucOptions.User> tileUserBefore = mucOptions.getUsers(5);
        processConferencePresence(packet, conversation);
        final List<MucOptions.User> tileUserAfter = mucOptions.getUsers(5);
        if (!tileUserAfter.equals(tileUserBefore)) {
            mXmppConnectionService.getAvatarService().clear(mucOptions);
        }
        if (before != mucOptions.online() || (mucOptions.online() && count != mucOptions.getUserCount())) {
            mXmppConnectionService.updateConversationUi();
        } else if (mucOptions.online()) {
            mXmppConnectionService.updateMucRosterUi();
        }
    }
}
Also used : MucOptions(de.pixart.messenger.entities.MucOptions) Conversation(de.pixart.messenger.entities.Conversation)

Aggregations

MucOptions (de.pixart.messenger.entities.MucOptions)8 Jid (de.pixart.messenger.xmpp.jid.Jid)5 Account (de.pixart.messenger.entities.Account)4 Conversation (de.pixart.messenger.entities.Conversation)3 PendingIntent (android.app.PendingIntent)2 Intent (android.content.Intent)2 Bundle (android.os.Bundle)2 Contact (de.pixart.messenger.entities.Contact)2 Element (de.pixart.messenger.xml.Element)2 ArrayList (java.util.ArrayList)2 SuppressLint (android.annotation.SuppressLint)1 Context (android.content.Context)1 DialogInterface (android.content.DialogInterface)1 SendIntentException (android.content.IntentSender.SendIntentException)1 Resources (android.content.res.Resources)1 DataBindingUtil (android.databinding.DataBindingUtil)1 Bitmap (android.graphics.Bitmap)1 PorterDuff (android.graphics.PorterDuff)1 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 Drawable (android.graphics.drawable.Drawable)1