Kiran Sarvaiya
Kiran Sarvaiya

Reputation: 1428

XMPP I need to send Typing state via XMPP Chat on specific chat Dialogue

My Requirement is that two users have 2 or more than 2 different dialogue but user are same. so when one can type at that time another one get typing state in all chat dialogue associated with that. bellow is my code on the Sent method

-(void)xmpp_SendTypingNotification:(BOOL)isTyping toFriendID:(NSString*)recieverId{
    XMPPMessage * xMessage = [[XMPPMessage alloc] initWithType:@"chat" to:[XMPPJID jidWithString:strAddDomain(recieverId)]];
    isTyping?[xMessage addComposingChatState]:[xMessage addInactiveChatState];
    [self.xmppStream sendElement:xMessage];
}

or receive code is

- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
    if ([message isErrorMessage]) {
        return;
    }

    if ([message hasChatState]){
        if (!_arrTypingUsersIDs) {
            _arrTypingUsersIDs=[NSMutableArray new];
        }

        NSString *otherUserID=[NSString stringWithFormat:@"%@",[message.fromStr componentsSeparatedByString:@"@"][0]];

        NSInteger typingStatus=[message hasComposingChatState]?1:0;
        [self xmpp_setTypingStatus:typingStatus ofUser:otherUserID];

    }
}

Upvotes: 0

Views: 391

Answers (2)

Rubycon
Rubycon

Reputation: 18346

The reason why it works this way is because you send this status every time to other user:

[XMPPJID jidWithString:strAddDomain(recieverId)]] 

and not in context of particular dialog.

If you have a 1-1 chat then your solution is right for it.

If you have a group chat (by using XEP-0045), then you need to send the typing statuses to group room JID:

XMPPMessage *xMessage = [[XMPPMessage alloc] init];
isTyping ? [xMessage addComposingChatState] : [xMessage addInactiveChatState];
[someXMPPRoom sendMessage:xMessage];

So only users in this particular chat room will receive your statuses

Here is a link to XEP-0045 implementation at XMPPFramework

Upvotes: 1

andesta.erfan
andesta.erfan

Reputation: 998

you have to use XEP-0085 for sending and receiving chat states(like is typing or pause typing).

In XMPPFramework if you want to send is typing chat state just send a message and use message.addaddComposingChatState() to add composing state to a message.

When you receive it in your second client you can check if the message is chat state or not using message.hasChatState or message.message.hasComposingChatState or hasPausedChatState

Upvotes: 1

Related Questions