1

我正在开发一个聊天应用程序来实现多用户聊天功能。我可以加入房间并发送消息,但我遇到了一个奇怪的问题。在向房间发送消息时,消息会重复/重复。这个问题发生在发送方(正在向房间发送消息的用户),而房间中的其他用户正在收到一条正确的消息。

- (void)sendMessageWithBody:(NSString )messageBody andMessageId:(NSString) messageId 
{ 
if ([messageBody length] == 0) return; 
NSXMLElement *body = [NSXMLElement elementWithName:@"body" stringValue:messageBody];
 XMPPMessage *message = [XMPPMessage message];
 [message addAttributeWithName:@"id" stringValue:messageId];
 [message addChild:body];
 [self sendMessage:message]; 
} 
4

1 回答 1

0
- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message
{
    XMPPLogTrace();

    NSString* fromStr;
    NSArray* arrayFrom = [[message fromStr] componentsSeparatedByString:@"/"];
    if ([arrayFrom count] > 1)
    {
        fromStr = [arrayFrom objectAtIndex:1];
    }

    NSString* toStr;
    NSArray* arrayTo = [[message toStr] componentsSeparatedByString:@"@"];

    if ([arrayTo count] > 1)
    {
        toStr = [arrayTo objectAtIndex:0];
    }
    if ([fromStr isEqualToString:toStr] || ([[message body] length] == 0)) {
        return;
    }
    if ([self shouldArchiveMessage:message outgoing:NO xmppStream:sender])
    {
        [xmppMessageArchivingStorage archiveMessage:message outgoing:NO xmppStream:sender];
    }
}
于 2016-03-01T04:14:45.920 回答