xmpp ios : which xmpp delegate to use to get chat notifications (XMPPMessage+XEP_0085)

StackOverflow https://stackoverflow.com/questions/23348750

  •  11-07-2023
  •  | 
  •  

Question

I am implementing XMPP in my ios app. I am aware of XMPPMessage+XEP_0085 category which has a few simple methods like addActiveChatState, addComposingChatState and a few others. I want to show chat notifications e.g. when user is typing a message or paused. I am using following code to send message:

  NSXMLElement *message = [NSXMLElement elementWithName:@"message"];
    [message addAttributeWithName:@"type" stringValue:@"chat"];
    [message addAttributeWithName:@"to" stringValue:user];
    [message addAttributeWithName:@"id" stringValue:messageID];

    [message addChild:body];
    [message addChild:setting];

    // chat notifications
    XMPPMessage *xmppMessage = [XMPPMessage messageFromElement:message];
    [xmppMessage addActiveChatState];
    [xmppMessage addComposingChatState];
    [xmppMessage addPausedChatState];
    [xmppMessage addInactiveChatState];
    [xmppMessage addGoneChatState];

    [_appDelegate.xmppStream sendElement:xmppMessage];

In which xmpp delegate I should receive these notifications. I am not receiving chat notifications in

- (XMPPMessage *)xmppStream:(XMPPStream *)sender willReceiveMessage:(XMPPMessage *)message

delegate.

Était-ce utile?

La solution 2

@vitalyster is correct to an extent. This is what I have followed to receive typing notifications properly:

  1. After setting up your XMPPMessage, add chatMarkable to the message:

    XMPPMessage *xmppMessage = [XMPPMessage messageFromElement:message]; [xmppMessage addMarkableChatMarker];

and then send new xmppMessage object.

  1. When receiving notification, check if message contains hasInactiveChatState or hasComposingChatState and handle the UI part accordingly.

You guys might need to add some checks according to the project requirement and handling the typing notifications.

Autres conseils

You are right, XMPPMessage+XEP_0085 category just define some simple methods to add chat state info, but also there are methods to check if chat state exists in message. So, you need to write an XMPPModule which will process message in -xmppStream:... didReceiveMessage: (note, you should use didReceiveMessage) and "multicast" events to others if message hasChatState and/or hasComposingChatState, etc. You can see examples of XMPPModule in the implementations of other XMPP extensions, e.g. XMPPPing

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top