Search in sources :

Example 16 with MessagePacket

use of eu.siacs.conversations.xmpp.stanzas.MessagePacket in project Conversations by siacs.

the class MessageGenerator method preparePacket.

private MessagePacket preparePacket(Message message) {
    Conversation conversation = message.getConversation();
    Account account = conversation.getAccount();
    MessagePacket packet = new MessagePacket();
    if (conversation.getMode() == Conversation.MODE_SINGLE) {
        packet.setTo(message.getCounterpart());
        packet.setType(MessagePacket.TYPE_CHAT);
        packet.addChild("markable", "urn:xmpp:chat-markers:0");
        if (this.mXmppConnectionService.indicateReceived()) {
            packet.addChild("request", "urn:xmpp:receipts");
        }
    } else if (message.getType() == Message.TYPE_PRIVATE) {
        packet.setTo(message.getCounterpart());
        packet.setType(MessagePacket.TYPE_CHAT);
        packet.addChild("x", "http://jabber.org/protocol/muc#user");
        if (this.mXmppConnectionService.indicateReceived()) {
            packet.addChild("request", "urn:xmpp:receipts");
        }
    } else {
        packet.setTo(message.getCounterpart().toBareJid());
        packet.setType(MessagePacket.TYPE_GROUPCHAT);
    }
    packet.setFrom(account.getJid());
    packet.setId(message.getUuid());
    packet.addChild("origin-id", Namespace.STANZA_IDS).setAttribute("id", message.getUuid());
    if (message.edited()) {
        packet.addChild("replace", "urn:xmpp:message-correct:0").setAttribute("id", message.getEditedId());
    }
    return packet;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account) Conversation(eu.siacs.conversations.entities.Conversation)

Example 17 with MessagePacket

use of eu.siacs.conversations.xmpp.stanzas.MessagePacket in project Conversations by siacs.

the class MessageGenerator method received.

public MessagePacket received(Account account, MessagePacket originalMessage, ArrayList<String> namespaces, int type) {
    MessagePacket receivedPacket = new MessagePacket();
    receivedPacket.setType(type);
    receivedPacket.setTo(originalMessage.getFrom());
    receivedPacket.setFrom(account.getJid());
    for (String namespace : namespaces) {
        receivedPacket.addChild("received", namespace).setAttribute("id", originalMessage.getId());
    }
    return receivedPacket;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket)

Example 18 with MessagePacket

use of eu.siacs.conversations.xmpp.stanzas.MessagePacket in project Conversations by siacs.

the class MessageGenerator method directInvite.

public MessagePacket directInvite(final Conversation conversation, final Jid contact) {
    MessagePacket packet = new MessagePacket();
    packet.setType(MessagePacket.TYPE_NORMAL);
    packet.setTo(contact);
    packet.setFrom(conversation.getAccount().getJid());
    Element x = packet.addChild("x", "jabber:x:conference");
    x.setAttribute("jid", conversation.getJid().toBareJid().toString());
    String password = conversation.getMucOptions().getPassword();
    if (password != null) {
        x.setAttribute("password", password);
    }
    return packet;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Element(eu.siacs.conversations.xml.Element)

Example 19 with MessagePacket

use of eu.siacs.conversations.xmpp.stanzas.MessagePacket in project Conversations by siacs.

the class XmppConnectionService method onOtrSessionEstablished.

public void onOtrSessionEstablished(Conversation conversation) {
    final Account account = conversation.getAccount();
    final Session otrSession = conversation.getOtrSession();
    Log.d(Config.LOGTAG, account.getJid().toBareJid() + " otr session established with " + conversation.getJid() + "/" + otrSession.getSessionID().getUserID());
    conversation.findUnsentMessagesWithEncryption(Message.ENCRYPTION_OTR, new Conversation.OnMessageFound() {

        @Override
        public void onMessageFound(Message message) {
            SessionID id = otrSession.getSessionID();
            try {
                message.setCounterpart(Jid.fromString(id.getAccountID() + "/" + id.getUserID()));
            } catch (InvalidJidException e) {
                return;
            }
            if (message.needsUploading()) {
                mJingleConnectionManager.createNewConnection(message);
            } else {
                MessagePacket outPacket = mMessageGenerator.generateOtrChat(message);
                if (outPacket != null) {
                    mMessageGenerator.addDelay(outPacket, message.getTimeSent());
                    message.setStatus(Message.STATUS_SEND);
                    databaseBackend.updateMessage(message);
                    sendMessagePacket(account, outPacket);
                }
            }
            updateConversationUi();
        }
    });
}
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) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation) SessionID(net.java.otr4j.session.SessionID) Session(net.java.otr4j.session.Session)

Example 20 with MessagePacket

use of eu.siacs.conversations.xmpp.stanzas.MessagePacket in project Conversations by siacs.

the class XmppConnectionService method directInvite.

public void directInvite(Conversation conversation, Jid jid) {
    MessagePacket packet = mMessageGenerator.directInvite(conversation, jid);
    sendMessagePacket(conversation.getAccount(), packet);
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket)

Aggregations

MessagePacket (eu.siacs.conversations.xmpp.stanzas.MessagePacket)29 Element (eu.siacs.conversations.xml.Element)8 Account (eu.siacs.conversations.entities.Account)6 Conversation (eu.siacs.conversations.entities.Conversation)6 XmppAxolotlMessage (eu.siacs.conversations.crypto.axolotl.XmppAxolotlMessage)5 Message (eu.siacs.conversations.entities.Message)5 InvalidJidException (eu.siacs.conversations.xmpp.jid.InvalidJidException)4 Jid (eu.siacs.conversations.xmpp.jid.Jid)4 AbstractAcknowledgeableStanza (eu.siacs.conversations.xmpp.stanzas.AbstractAcknowledgeableStanza)3 Session (net.java.otr4j.session.Session)3 MucOptions (eu.siacs.conversations.entities.MucOptions)2 Tag (eu.siacs.conversations.xml.Tag)2 RequestPacket (eu.siacs.conversations.xmpp.stanzas.streammgmt.RequestPacket)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 OtrException (net.java.otr4j.OtrException)2 Bundle (android.os.Bundle)1 Bookmark (eu.siacs.conversations.entities.Bookmark)1 Contact (eu.siacs.conversations.entities.Contact)1 HttpConnectionManager (eu.siacs.conversations.http.HttpConnectionManager)1