Search in sources :

Example 81 with Message

use of org.jivesoftware.smack.packet.Message in project xabber-android by redsolution.

the class MUCManager method invite.

/**
 * Sends invitation.
 *
 * @throws NetworkException
 */
public void invite(AccountJid account, EntityBareJid room, UserJid user) throws NetworkException {
    RoomChat roomChat = getRoomChat(account, room);
    if (roomChat == null || roomChat.getState() != RoomState.available) {
        Application.getInstance().onError(R.string.NOT_CONNECTED);
        return;
    }
    Message message = new Message(room);
    MUCUser mucUser = new MUCUser();
    MUCUser.Invite invite = new MUCUser.Invite("", null, user.getBareJid().asEntityBareJidIfPossible());
    mucUser.setInvite(invite);
    message.addExtension(mucUser);
    StanzaSender.sendStanza(account, message);
    roomChat.putInvite(message.getStanzaId(), user);
    roomChat.newAction(roomChat.getNickname(), user.toString(), ChatAction.invite_sent);
}
Also used : MUCUser(org.jivesoftware.smackx.muc.packet.MUCUser) Message(org.jivesoftware.smack.packet.Message)

Example 82 with Message

use of org.jivesoftware.smack.packet.Message in project xabber-android by redsolution.

the class SSNManager method sendFeature.

private void sendFeature(AccountJid account, Jid user, String session, Feature feature) {
    Message message = new Message(user, Message.Type.normal);
    message.setThread(session);
    message.addExtension(feature);
    try {
        StanzaSender.sendStanza(account, message);
    } catch (NetworkException e) {
        LogManager.exception(this, e);
    }
}
Also used : Message(org.jivesoftware.smack.packet.Message) NetworkException(com.xabber.android.data.NetworkException)

Example 83 with Message

use of org.jivesoftware.smack.packet.Message in project xabber-android by redsolution.

the class SSNManager method onStanza.

@Override
public void onStanza(ConnectionItem connection, Stanza stanza) {
    Jid from = stanza.getFrom();
    if (from == null) {
        return;
    }
    if (!(connection instanceof AccountItem) || !(stanza instanceof Message)) {
        return;
    }
    AccountJid account = ((AccountItem) connection).getAccount();
    Message message = (Message) stanza;
    String session = message.getThread();
    if (session == null) {
        return;
    }
    for (ExtensionElement packetExtension : stanza.getExtensions()) {
        if (packetExtension instanceof Feature) {
            Feature feature = (Feature) packetExtension;
            if (!feature.isValid()) {
                continue;
            }
            DataForm.Type dataFormType = feature.getDataFormType();
            if (dataFormType == DataForm.Type.form) {
                onFormReceived(account, from, session, feature);
            } else if (dataFormType == DataForm.Type.submit) {
                onSubmitReceived(account, from, session, feature);
            } else if (dataFormType == DataForm.Type.result) {
                onResultReceived(account, session, feature);
            }
        }
    }
}
Also used : Jid(org.jxmpp.jid.Jid) AccountJid(com.xabber.android.data.entity.AccountJid) Message(org.jivesoftware.smack.packet.Message) AccountItem(com.xabber.android.data.account.AccountItem) AccountJid(com.xabber.android.data.entity.AccountJid) ExtensionElement(org.jivesoftware.smack.packet.ExtensionElement) DataForm(org.jivesoftware.smackx.xdata.packet.DataForm) Feature(com.xabber.xmpp.ssn.Feature)

Example 84 with Message

use of org.jivesoftware.smack.packet.Message in project cayenne by apache.

the class XMPPBridge method sendExternalEvent.

@Override
protected void sendExternalEvent(CayenneEvent localEvent) throws Exception {
    Message message = groupChat.createMessage();
    message.setBody(serializeToString(localEvent));
    // set thread to our session handle to be able to discard messages from self
    message.setThread(sessionHandle);
    groupChat.sendMessage(message);
}
Also used : Message(org.jivesoftware.smack.packet.Message)

Example 85 with Message

use of org.jivesoftware.smack.packet.Message in project wso2-axis2-transports by wso2.

the class XMPPSender method sendChatMessage.

/**
 * Replies to IM clients via a chat message. The reply contains the invocation response as a string.
 * @param msgCtx
 * @param responseMsg
 * @throws AxisFault
 */
private static void sendChatMessage(MessageContext msgCtx, String responseMsg) throws AxisFault {
    XMPPConnection xmppConnection = null;
    XMPPOutTransportInfo xmppOutTransportInfo = null;
    Message message = new Message();
    xmppOutTransportInfo = (XMPPOutTransportInfo) msgCtx.getProperty(Constants.OUT_TRANSPORT_INFO);
    if (xmppOutTransportInfo != null) {
        message.setProperty(XMPPConstants.IN_REPLY_TO, xmppOutTransportInfo.getInReplyTo());
        xmppConnection = xmppOutTransportInfo.getConnectionFactory().getXmppConnection();
        if (xmppConnection == null) {
            handleException("Connection to XMPP Server is not established.");
        }
    } else {
        handleException("Could not find message sender details.");
    }
    // initialize the chat manager using connection
    ChatManager chatManager = xmppConnection.getChatManager();
    Chat chat = chatManager.createChat(xmppOutTransportInfo.getDestinationAccount(), null);
    try {
        message.setProperty(XMPPConstants.SEQUENCE_ID, xmppOutTransportInfo.getSequenceID());
        message.setBody(responseMsg);
        chat.sendMessage(message);
        log.debug("Sent message :" + message.toXML());
    } catch (XMPPException e) {
        XMPPSender.handleException("Error occurred while sending the message : " + message.toXML(), e);
    }
}
Also used : XMPPOutTransportInfo(org.apache.axis2.transport.xmpp.util.XMPPOutTransportInfo) AxisMessage(org.apache.axis2.description.AxisMessage) Message(org.jivesoftware.smack.packet.Message) Chat(org.jivesoftware.smack.Chat) XMPPConnection(org.jivesoftware.smack.XMPPConnection) XMPPException(org.jivesoftware.smack.XMPPException) ChatManager(org.jivesoftware.smack.ChatManager)

Aggregations

Message (org.jivesoftware.smack.packet.Message)166 Test (org.junit.Test)57 Presence (org.jivesoftware.smack.packet.Presence)21 XMPPException (org.jivesoftware.smack.XMPPException)15 StanzaCollector (org.jivesoftware.smack.StanzaCollector)14 NetworkException (com.xabber.android.data.NetworkException)13 Stanza (org.jivesoftware.smack.packet.Stanza)13 MUCUser (org.jivesoftware.smackx.muc.packet.MUCUser)13 MessageTypeFilter (org.jivesoftware.smack.filter.MessageTypeFilter)12 ExtensionElement (org.jivesoftware.smack.packet.ExtensionElement)12 AccountItem (com.xabber.android.data.account.AccountItem)11 XMPPConnection (org.jivesoftware.smack.XMPPConnection)11 Date (java.util.Date)10 Jid (org.jxmpp.jid.Jid)10 Chat (org.jivesoftware.smack.Chat)9 AccountJid (com.xabber.android.data.entity.AccountJid)7 ArrayList (java.util.ArrayList)7 XmlPullParser (org.xmlpull.v1.XmlPullParser)7 InputStream (java.io.InputStream)6 Forwarded (org.jivesoftware.smackx.forward.packet.Forwarded)6