Search in sources :

Example 46 with Account

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

the class XmppConnectionService method deleteContactOnServer.

public void deleteContactOnServer(Contact contact) {
    contact.resetOption(Contact.Options.PREEMPTIVE_GRANT);
    contact.resetOption(Contact.Options.DIRTY_PUSH);
    contact.setOption(Contact.Options.DIRTY_DELETE);
    Account account = contact.getAccount();
    if (account.getStatus() == Account.State.ONLINE) {
        IqPacket iq = new IqPacket(IqPacket.TYPE.SET);
        Element item = iq.query(Namespace.ROSTER).addChild("item");
        item.setAttribute("jid", contact.getJid().toString());
        item.setAttribute("subscription", "remove");
        account.getXmppConnection().sendIqPacket(iq, mDefaultIqHandler);
    }
}
Also used : Account(eu.siacs.conversations.entities.Account) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 47 with Account

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

the class XmppConnectionService method fetchMamPreferences.

public void fetchMamPreferences(Account account, final OnMamPreferencesFetched callback) {
    final boolean legacy = account.getXmppConnection().getFeatures().mamLegacy();
    IqPacket request = new IqPacket(IqPacket.TYPE.GET);
    request.addChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
    sendIqPacket(account, request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            Element prefs = packet.findChild("prefs", legacy ? Namespace.MAM_LEGACY : Namespace.MAM);
            if (packet.getType() == IqPacket.TYPE.RESULT && prefs != null) {
                callback.onPreferencesFetched(prefs);
            } else {
                callback.onPreferencesFetchFailed();
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) Element(eu.siacs.conversations.xml.Element) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Example 48 with Account

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

the class XmppConnectionService method sendReadMarker.

public void sendReadMarker(final Conversation conversation) {
    final Message markable = conversation.getLatestMarkableMessage();
    if (this.markRead(conversation)) {
        updateConversationUi();
    }
    if (confirmMessages() && markable != null && markable.trusted() && markable.getRemoteMsgId() != null) {
        Log.d(Config.LOGTAG, conversation.getAccount().getJid().toBareJid() + ": sending read marker to " + markable.getCounterpart().toString());
        Account account = conversation.getAccount();
        final Jid to = markable.getCounterpart();
        MessagePacket packet = mMessageGenerator.confirm(account, to, markable.getRemoteMsgId());
        this.sendMessagePacket(conversation.getAccount(), packet);
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) XmppAxolotlMessage(eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage) Message(eu.siacs.conversations.entities.Message) Jid(eu.siacs.conversations.xmpp.jid.Jid)

Example 49 with Account

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

the class XmppConnectionService method renewSymmetricKey.

public boolean renewSymmetricKey(Conversation conversation) {
    Account account = conversation.getAccount();
    byte[] symmetricKey = new byte[32];
    this.mRandom.nextBytes(symmetricKey);
    Session otrSession = conversation.getOtrSession();
    if (otrSession != null) {
        MessagePacket packet = new MessagePacket();
        packet.setType(MessagePacket.TYPE_CHAT);
        packet.setFrom(account.getJid());
        MessageGenerator.addMessageHints(packet);
        packet.setAttribute("to", otrSession.getSessionID().getAccountID() + "/" + otrSession.getSessionID().getUserID());
        try {
            packet.setBody(otrSession.transformSending(CryptoHelper.FILETRANSFER + CryptoHelper.bytesToHex(symmetricKey))[0]);
            sendMessagePacket(account, packet);
            conversation.setSymmetricKey(symmetricKey);
            return true;
        } catch (OtrException e) {
            return false;
        }
    }
    return false;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) OtrException(net.java.otr4j.OtrException) Session(net.java.otr4j.session.Session)

Example 50 with Account

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

the class XmppConnectionService method changeAffiliationInConference.

public void changeAffiliationInConference(final Conversation conference, Jid user, final MucOptions.Affiliation affiliation, final OnAffiliationChanged callback) {
    final Jid jid = user.toBareJid();
    IqPacket request = this.mIqGenerator.changeAffiliation(conference, jid, affiliation.toString());
    sendIqPacket(conference.getAccount(), request, new OnIqPacketReceived() {

        @Override
        public void onIqPacketReceived(Account account, IqPacket packet) {
            if (packet.getType() == IqPacket.TYPE.RESULT) {
                conference.getMucOptions().changeAffiliation(jid, affiliation);
                getAvatarService().clear(conference);
                callback.onAffiliationChangedSuccessful(jid);
            } else {
                callback.onAffiliationChangeFailed(jid, R.string.could_not_change_affiliation);
            }
        }
    });
}
Also used : Account(eu.siacs.conversations.entities.Account) Jid(eu.siacs.conversations.xmpp.jid.Jid) OnIqPacketReceived(eu.siacs.conversations.xmpp.OnIqPacketReceived) IqPacket(eu.siacs.conversations.xmpp.stanzas.IqPacket)

Aggregations

Account (eu.siacs.conversations.entities.Account)100 IqPacket (eu.siacs.conversations.xmpp.stanzas.IqPacket)41 OnIqPacketReceived (eu.siacs.conversations.xmpp.OnIqPacketReceived)33 Jid (eu.siacs.conversations.xmpp.jid.Jid)22 Element (eu.siacs.conversations.xml.Element)21 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)17 Conversation (eu.siacs.conversations.entities.Conversation)16 Contact (eu.siacs.conversations.entities.Contact)9 Message (eu.siacs.conversations.entities.Message)9 ArrayList (java.util.ArrayList)8 PendingIntent (android.app.PendingIntent)7 Intent (android.content.Intent)7 Bookmark (eu.siacs.conversations.entities.Bookmark)7 SuppressLint (android.annotation.SuppressLint)6 AlertDialog (android.app.AlertDialog)6 TextView (android.widget.TextView)6 MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)6 FileNotFoundException (java.io.FileNotFoundException)6 DialogInterface (android.content.DialogInterface)5 View (android.view.View)5