Search in sources :

Example 11 with Account

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

the class XmppConnectionService method sendUnblockRequest.

public void sendUnblockRequest(final Blockable blockable) {
    if (blockable != null && blockable.getJid() != null) {
        final Jid jid = blockable.getBlockedJid();
        this.sendIqPacket(blockable.getAccount(), getIqGenerator().generateSetUnblockRequest(jid), new OnIqPacketReceived() {

            @Override
            public void onIqPacketReceived(final Account account, final IqPacket packet) {
                if (packet.getType() == IqPacket.TYPE.RESULT) {
                    account.getBlocklist().remove(jid);
                    updateBlocklistUi(OnUpdateBlocklist.Status.UNBLOCKED);
                }
            }
        });
    }
}
Also used : Account(de.pixart.messenger.entities.Account) Jid(de.pixart.messenger.xmpp.jid.Jid) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 12 with Account

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

the class DatabaseBackend method writeRoster.

public void writeRoster(final Roster roster) {
    final Account account = roster.getAccount();
    final SQLiteDatabase db = this.getWritableDatabase();
    db.beginTransaction();
    for (Contact contact : roster.getContacts()) {
        if (contact.getOption(Contact.Options.IN_ROSTER)) {
            db.insert(Contact.TABLENAME, null, contact.getContentValues());
        } else {
            String where = Contact.ACCOUNT + "=? AND " + Contact.JID + "=?";
            String[] whereArgs = { account.getUuid(), contact.getJid().toPreppedString() };
            db.delete(Contact.TABLENAME, where, whereArgs);
        }
    }
    db.setTransactionSuccessful();
    db.endTransaction();
    account.setRosterVersion(roster.getVersion());
    updateAccount(account);
}
Also used : Account(de.pixart.messenger.entities.Account) SQLiteDatabase(android.database.sqlite.SQLiteDatabase) Contact(de.pixart.messenger.entities.Contact)

Example 13 with Account

use of de.pixart.messenger.entities.Account 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 14 with Account

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

the class XmppConnectionService method republishAvatarIfNeeded.

public void republishAvatarIfNeeded(Account account) {
    if (account.getAxolotlService().isPepBroken()) {
        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": skipping republication of avatar because pep is broken");
        return;
    }
    IqPacket packet = this.mIqGenerator.retrieveAvatarMetaData(null);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        private Avatar parseAvatar(IqPacket packet) {
            Element pubsub = packet.findChild("pubsub", "http://jabber.org/protocol/pubsub");
            if (pubsub != null) {
                Element items = pubsub.findChild("items");
                if (items != null) {
                    return Avatar.parseMetadata(items);
                }
            }
            return null;
        }

        private boolean errorIsItemNotFound(IqPacket packet) {
            Element error = packet.findChild("error");
            return packet.getType() == IqPacket.TYPE.ERROR && error != null && error.hasChild("item-not-found");
        }

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT || errorIsItemNotFound(packet)) {
                Avatar serverAvatar = parseAvatar(packet);
                if (serverAvatar == null && account.getAvatar() != null) {
                    Avatar avatar = fileBackend.getStoredPepAvatar(account.getAvatar());
                    if (avatar != null) {
                        Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": avatar on server was null. republishing");
                        publishAvatar(account, fileBackend.getStoredPepAvatar(account.getAvatar()), null);
                    } else {
                        Log.e(Config.LOGTAG, account.getJid().toBareJid() + ": error rereading avatar");
                    }
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) Avatar(de.pixart.messenger.xmpp.pep.Avatar) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Example 15 with Account

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

the class XmppConnectionService method publishAvatar.

public void publishAvatar(Account account, final Avatar avatar, final UiCallback<Avatar> callback) {
    IqPacket packet = this.mIqGenerator.publishAvatar(avatar);
    this.sendIqPacket(account, packet, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket result) {
            if (result.getType() == IqPacket.TYPE.RESULT) {
                final IqPacket packet = XmppConnectionService.this.mIqGenerator.publishAvatarMetadata(avatar);
                sendIqPacket(account, packet, new OnIqPacketReceived() {

                    @Override
                    public void onIqPacketReceived(Account account, IqPacket result) {
                        if (result.getType() == IqPacket.TYPE.RESULT) {
                            if (account.setAvatar(avatar.getFilename())) {
                                getAvatarService().clear(account);
                                databaseBackend.updateAccount(account);
                            }
                            Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": published avatar " + (avatar.size / 1024) + "KiB");
                            if (callback != null) {
                                callback.success(avatar);
                            }
                        } else {
                            if (callback != null) {
                                callback.error(R.string.error_publish_avatar_server_reject, avatar);
                            }
                        }
                    }
                });
            } else {
                Element error = result.findChild("error");
                Log.d(Config.LOGTAG, account.getJid().toBareJid() + ": server rejected avatar " + (avatar.size / 1024) + "KiB " + (error != null ? error.toString() : ""));
                if (callback != null) {
                    callback.error(R.string.error_publish_avatar_server_reject, avatar);
                }
            }
        }
    });
}
Also used : Account(de.pixart.messenger.entities.Account) OnIqPacketReceived(de.pixart.messenger.xmpp.OnIqPacketReceived) Element(de.pixart.messenger.xml.Element) IqPacket(de.pixart.messenger.xmpp.stanzas.IqPacket)

Aggregations

Account (de.pixart.messenger.entities.Account)104 IqPacket (de.pixart.messenger.xmpp.stanzas.IqPacket)39 OnIqPacketReceived (de.pixart.messenger.xmpp.OnIqPacketReceived)31 Jid (de.pixart.messenger.xmpp.jid.Jid)26 Element (de.pixart.messenger.xml.Element)23 InvalidJidException (de.pixart.messenger.xmpp.jid.InvalidJidException)19 Conversation (de.pixart.messenger.entities.Conversation)18 ArrayList (java.util.ArrayList)14 Intent (android.content.Intent)12 Contact (de.pixart.messenger.entities.Contact)12 Bookmark (de.pixart.messenger.entities.Bookmark)10 PendingIntent (android.app.PendingIntent)9 Message (de.pixart.messenger.entities.Message)8 Bundle (android.os.Bundle)7 AlertDialog (android.support.v7.app.AlertDialog)7 MucOptions (de.pixart.messenger.entities.MucOptions)7 List (java.util.List)7 SuppressLint (android.annotation.SuppressLint)6 Bitmap (android.graphics.Bitmap)6 View (android.view.View)6