Search in sources :

Example 21 with MessagePacket

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

the class XmppConnectionService method sendChatState.

public void sendChatState(Conversation conversation) {
    if (sendChatStates()) {
        MessagePacket packet = mMessageGenerator.generateChatState(conversation);
        sendMessagePacket(conversation.getAccount(), packet);
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket)

Example 22 with MessagePacket

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

the class OtrService method injectMessage.

@Override
public void injectMessage(SessionID session, String body) throws OtrException {
    MessagePacket packet = new MessagePacket();
    packet.setFrom(account.getJid());
    if (session.getUserID().isEmpty()) {
        packet.setAttribute("to", session.getAccountID());
    } else {
        packet.setAttribute("to", session.getAccountID() + "/" + session.getUserID());
    }
    packet.setBody(body);
    MessageGenerator.addMessageHints(packet);
    try {
        Jid jid = Jid.fromSessionID(session);
        Conversation conversation = mXmppConnectionService.find(account, jid);
        if (conversation != null && conversation.setOutgoingChatState(Config.DEFAULT_CHATSTATE)) {
            if (mXmppConnectionService.sendChatStates()) {
                packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
            }
        }
    } catch (final InvalidJidException ignored) {
    }
    packet.setType(MessagePacket.TYPE_CHAT);
    packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("namespace", "urn:xmpp:otr:0");
    account.getXmppConnection().sendMessagePacket(packet);
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation)

Example 23 with MessagePacket

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

the class OtrService method sendOtrErrorMessage.

public void sendOtrErrorMessage(SessionID session, String errorText) {
    try {
        Jid jid = Jid.fromSessionID(session);
        Conversation conversation = mXmppConnectionService.find(account, jid);
        String id = conversation == null ? null : conversation.getLastReceivedOtrMessageId();
        if (id != null) {
            MessagePacket packet = mXmppConnectionService.getMessageGenerator().generateOtrError(jid, id, errorText);
            packet.setFrom(account.getJid());
            mXmppConnectionService.sendMessagePacket(account, packet);
            Log.d(Config.LOGTAG, packet.toString());
            Log.d(Config.LOGTAG, account.getJid().toBareJid().toString() + ": unreadable OTR message in " + conversation.getName());
        }
    } catch (InvalidJidException e) {
        return;
    }
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Jid(eu.siacs.conversations.xmpp.jid.Jid) InvalidJidException(eu.siacs.conversations.xmpp.jid.InvalidJidException) Conversation(eu.siacs.conversations.entities.Conversation)

Example 24 with MessagePacket

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

the class MessageGenerator method generateChatState.

public MessagePacket generateChatState(Conversation conversation) {
    final Account account = conversation.getAccount();
    MessagePacket packet = new MessagePacket();
    packet.setType(conversation.getMode() == Conversation.MODE_MULTI ? MessagePacket.TYPE_GROUPCHAT : MessagePacket.TYPE_CHAT);
    packet.setTo(conversation.getJid().toBareJid());
    packet.setFrom(account.getJid());
    packet.addChild(ChatState.toElement(conversation.getOutgoingChatState()));
    packet.addChild("no-store", "urn:xmpp:hints");
    //wrong! don't copy this. Its *store*
    packet.addChild("no-storage", "urn:xmpp:hints");
    return packet;
}
Also used : MessagePacket(eu.siacs.conversations.xmpp.stanzas.MessagePacket) Account(eu.siacs.conversations.entities.Account)

Example 25 with MessagePacket

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

the class MessageGenerator method generatePgpChat.

public MessagePacket generatePgpChat(Message message) {
    MessagePacket packet = preparePacket(message);
    if (Config.supportUnencrypted()) {
        packet.setBody(PGP_FALLBACK_MESSAGE);
    }
    if (message.getEncryption() == Message.ENCRYPTION_DECRYPTED) {
        packet.addChild("x", "jabber:x:encrypted").setContent(message.getEncryptedBody());
    } else if (message.getEncryption() == Message.ENCRYPTION_PGP) {
        packet.addChild("x", "jabber:x:encrypted").setContent(message.getBody());
    }
    packet.addChild("encryption", "urn:xmpp:eme:0").setAttribute("namespace", "jabber:x:encrypted");
    return 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