- Update
This commit is contained in:
1 parent
d281d765ea
commit
5b074a5176
1261 files changed
+199158
-7303
No files matched your search
@@ -0,0 +1,14 @@
|
||||
#import "XMPPMessage.h"
|
||||
|
||||
@interface XMPPMessage (XEP_0308)
|
||||
|
||||
- (BOOL)isMessageCorrection;
|
||||
|
||||
- (NSString *)correctedMessageID;
|
||||
|
||||
- (void)addMessageCorrectionWithID:(NSString *)messageCorrectionID;
|
||||
|
||||
- (XMPPMessage *)generateCorrectionMessageWithID:(NSString *)elementID;
|
||||
- (XMPPMessage *)generateCorrectionMessageWithID:(NSString *)elementID body:(NSString *)body;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,88 @@
|
||||
#import "XMPPMessage+XEP_0308.h"
|
||||
#import "NSXMLElement+XMPP.h"
|
||||
|
||||
#if ! __has_feature(objc_arc)
|
||||
#warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC).
|
||||
#endif
|
||||
|
||||
#define NAME_XMPP_MESSAGE_CORRECT @"replace"
|
||||
#define XMLNS_XMPP_MESSAGE_CORRECT @"urn:xmpp:message-correct:0"
|
||||
|
||||
@implementation XMPPMessage (XEP_0308)
|
||||
|
||||
- (BOOL)isMessageCorrection
|
||||
{
|
||||
if([[self correctedMessageID] length])
|
||||
{
|
||||
return YES;
|
||||
}
|
||||
else
|
||||
{
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (NSString *)correctedMessageID
|
||||
{
|
||||
return [[self elementForName:NAME_XMPP_MESSAGE_CORRECT xmlns:XMLNS_XMPP_MESSAGE_CORRECT] attributeStringValueForName:@"id"];
|
||||
}
|
||||
|
||||
- (void)addMessageCorrectionWithID:(NSString *)messageCorrectionID
|
||||
{
|
||||
NSXMLElement *replace = [NSXMLElement elementWithName:NAME_XMPP_MESSAGE_CORRECT stringValue:XMLNS_XMPP_MESSAGE_CORRECT];
|
||||
[replace addAttributeWithName:@"id" stringValue:messageCorrectionID];
|
||||
[self addChild:replace];
|
||||
}
|
||||
|
||||
- (XMPPMessage *)generateCorrectionMessageWithID:(NSString *)elementID
|
||||
{
|
||||
XMPPMessage *correctionMessage = nil;
|
||||
|
||||
if([[self elementID] length] && ![self isMessageCorrection])
|
||||
{
|
||||
correctionMessage = [self copy];
|
||||
|
||||
[correctionMessage removeAttributeForName:@"id"];
|
||||
|
||||
if([elementID length])
|
||||
{
|
||||
[correctionMessage addAttributeWithName:@"id" stringValue:elementID];
|
||||
}
|
||||
|
||||
[correctionMessage addMessageCorrectionWithID:[self elementID]];
|
||||
}
|
||||
|
||||
return correctionMessage;
|
||||
}
|
||||
|
||||
- (XMPPMessage *)generateCorrectionMessageWithID:(NSString *)elementID body:(NSString *)body
|
||||
{
|
||||
XMPPMessage *correctionMessage = nil;
|
||||
|
||||
if([[self elementID] length] && ![self isMessageCorrection])
|
||||
{
|
||||
correctionMessage = [self copy];
|
||||
|
||||
[correctionMessage removeAttributeForName:@"id"];
|
||||
|
||||
if([elementID length])
|
||||
{
|
||||
[correctionMessage addAttributeWithName:@"id" stringValue:elementID];
|
||||
}
|
||||
|
||||
NSXMLElement *bodyElement = [correctionMessage elementForName:@"body"];
|
||||
|
||||
if(bodyElement)
|
||||
{
|
||||
[correctionMessage removeChildAtIndex:[[correctionMessage children] indexOfObject:bodyElement]];
|
||||
}
|
||||
|
||||
[self addBody:body];
|
||||
|
||||
[correctionMessage addMessageCorrectionWithID:[self elementID]];
|
||||
}
|
||||
|
||||
return correctionMessage;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user