Pergunta

I am working on the iOS chat client by using XMPPFramework ( https://github.com/robbiehanson/XMPPFramework ), can anyone please help me with the chat and message. I use Spark ( http://www.igniterealtime.org/projects/spark/index.jsp ) to test my iOS chat client.

I find out that message XML format send by Spark in the Openfire server log is following:

<message id="nBT3N-161" 
         to="aaa@demo.com/7beebb67" 
         from="bbb@demo.com/Spark 2.6.3" 
         type="chat">
    <body>testing message ...</body>
    <thread>FIoMFD</thread>
    <x xmlns="jabber:x:event"><offline/><composing/></x>
</message> 

Message in the XML format has id :

id="nBT3N-161"

and thread id :

<thread>FIoMFD</thread>

and other info :

<x xmlns="jabber:x:event"><offline/><composing/></x>

But, .. when I use XMPPSteam to send message, the message XML format in the Openfire log is following :

<message type="chat" 
         to="bbb@demo.com/Spark 2.6.3" 
         from="aaa@demo.com/7beebb67">
    <body>tttttttttttttttt</body>
</message>

the message XML format does not include the message id, thread id and xmlns information. My code is following :

- (IBAction)didSendingMessage:(id)sender
{
    NSString *messageStr = self.messageTextField.text;
    if([messageStr length] > 0) {
        NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
        [body setStringValue:messageStr];

        NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
        [message addAttributeWithName:@"type" stringValue:@"chat"];
        [message addAttributeWithName:@"to" stringValue:@"bbb@demo.com/Spark 2.6.3"];
        [message addChild:body];

        [imManager.xmppStream sendElement:message];
        self.messageTextField.text = @"";

       [self.tView reloadData];
    }
}

Does I miss something or did something wrong? How do I generate those information ( ex: message id, thread, xmlns .. ) in the message ?

Or how do I create a message threading or conversation thread ?

Does XMPPFramework has something like ChatManager to createChat in the asmack (https://github.com/Flowdalic/asmack) ?

Thanks

Foi útil?

Solução

You can generate a unique ID for your messages using +[XMPPStream generateUUID] or -[XMPPStream generateUUID] methods, or any other your own method.

Thread element is not fatal. You may use it or not.

XML elements with the namespace jabber:x:event are defined in XEP-0022. AFAIK XMPPFramework does not implement it. But you can implement it on your own. You can find info at: XEP-0022 Message Events. As you can see there, this extension is not recommended anymore:

Note: More modern protocol extensions for this functionality have been defined in Chat State Notifications (XEP-0085) 1 for the composing and offline events and in Message Delivery Receipts (XEP-0184) [2] for the delivered and displayed events; those specifications supersede this one.

So, your final code can be something like:

- (IBAction)didSendingMessage:(id)sender
{
    NSString *messageStr = self.messageTextField.text;
    if([messageStr length] > 0) {
        NSXMLElement *body = [NSXMLElement elementWithName:@"body"];
        [body setStringValue:messageStr];

        NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
        [message addAttributeWithName:@"type" stringValue:@"chat"];
        [message addAttributeWithName:@"to" stringValue:@"bbb@demo.com/Spark 2.6.3"];
        [message addChild:body];
        NSXMLElement * thread = [NSXMLElement elementWithName:@"thread" stringValue:@"SomeThreadName"];
        [message addChild:thread];
        [message addAttributeWithName:@"id" stringValue:[imManager.xmppStream generateUUID]];

        [imManager.xmppStream sendElement:message];
        self.messageTextField.text = @"";

       [self.tView reloadData];
    }
}
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top