diff --git a/Core/XMPPFramework.h b/Core/XMPPFramework.h index 2225dfcc7d..238b45d47c 100644 --- a/Core/XMPPFramework.h +++ b/Core/XMPPFramework.h @@ -34,6 +34,7 @@ #import "XMPPTimer.h" #import "XMPPCoreDataStorage.h" #import "XMPPCoreDataStorageProtected.h" +#import "XMPPDelayedDelivery.h" #import "NSXMLElement+XEP_0203.h" #import "XMPPFileTransfer.h" #import "XMPPIncomingFileTransfer.h" diff --git a/Extensions/XEP-0203/NSXMLElement+XEP_0203.h b/Extensions/XEP-0203/NSXMLElement+XEP_0203.h index 662fda8303..84fd413ba9 100644 --- a/Extensions/XEP-0203/NSXMLElement+XEP_0203.h +++ b/Extensions/XEP-0203/NSXMLElement+XEP_0203.h @@ -1,10 +1,13 @@ #import @import KissXML; +@class XMPPJID; @interface NSXMLElement (XEP_0203) @property (nonatomic, readonly) BOOL wasDelayed; @property (nonatomic, readonly, nullable) NSDate *delayedDeliveryDate; +@property (nonatomic, readonly, nullable) XMPPJID *delayedDeliveryFrom; +@property (nonatomic, readonly, nullable) NSString *delayedDeliveryReasonDescription; @end diff --git a/Extensions/XEP-0203/NSXMLElement+XEP_0203.m b/Extensions/XEP-0203/NSXMLElement+XEP_0203.m index ee404d3326..82b0b371e6 100644 --- a/Extensions/XEP-0203/NSXMLElement+XEP_0203.m +++ b/Extensions/XEP-0203/NSXMLElement+XEP_0203.m @@ -1,6 +1,7 @@ #import "NSXMLElement+XEP_0203.h" #import "XMPPDateTimeProfiles.h" #import "NSXMLElement+XMPP.h" +#import "XMPPJID.h" #if ! __has_feature(objc_arc) #warning This file must be compiled with ARC. Use -fobjc-arc flag (or convert project to ARC). @@ -10,27 +11,11 @@ @implementation NSXMLElement (XEP_0203) - (BOOL)wasDelayed { - NSXMLElement *delay; - - delay = [self elementForName:@"delay" xmlns:@"urn:xmpp:delay"]; - if (delay) - { - return YES; - } - - delay = [self elementForName:@"x" xmlns:@"jabber:x:delay"]; - if (delay) - { - return YES; - } - - return NO; + return [self anyDelayedDeliveryChildElement] != nil; } - (NSDate *)delayedDeliveryDate { - NSXMLElement *delay; - // From XEP-0203 (Delayed Delivery) // // - delay = [self elementForName:@"x" xmlns:@"jabber:x:delay"]; - if (delay) + NSXMLElement *legacyDelay = [self legacyDelayedDeliveryChildElement]; + if (legacyDelay) { NSDate *stamp; - NSString *stampValue = [delay attributeStringValueForName:@"stamp"]; + NSString *stampValue = [legacyDelay attributeStringValueForName:@"stamp"]; NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setFormatterBehavior:NSDateFormatterBehavior10_4]; @@ -81,4 +66,30 @@ - (NSDate *)delayedDeliveryDate return nil; } +- (XMPPJID *)delayedDeliveryFrom +{ + NSString *delayedDeliveryFromString = [[self anyDelayedDeliveryChildElement] attributeStringValueForName:@"from"]; + return delayedDeliveryFromString ? [XMPPJID jidWithString:delayedDeliveryFromString] : nil; +} + +- (NSString *)delayedDeliveryReasonDescription +{ + return [self anyDelayedDeliveryChildElement].stringValue; +} + +- (NSXMLElement *)delayedDeliveryChildElement +{ + return [self elementForName:@"delay" xmlns:@"urn:xmpp:delay"]; +} + +- (NSXMLElement *)legacyDelayedDeliveryChildElement +{ + return [self elementForName:@"x" xmlns:@"jabber:x:delay"]; +} + +- (NSXMLElement *)anyDelayedDeliveryChildElement +{ + return [self delayedDeliveryChildElement] ?: [self legacyDelayedDeliveryChildElement]; +} + @end diff --git a/Extensions/XEP-0203/XMPPDelayedDelivery.h b/Extensions/XEP-0203/XMPPDelayedDelivery.h new file mode 100644 index 0000000000..29d5240dd0 --- /dev/null +++ b/Extensions/XEP-0203/XMPPDelayedDelivery.h @@ -0,0 +1,25 @@ +#import "XMPP.h" + +NS_ASSUME_NONNULL_BEGIN + +/// A module for processing XEP-0203 Delayed Delivery information in incoming XMPP stanzas. +@interface XMPPDelayedDelivery : XMPPModule + +@end + +/// A protocol defining @c XMPPDelayedDelivery module delegate API. +@protocol XMPPDelayedDeliveryDelegate + +@optional + +/// Notifies the delegate that a delayed delivery message has been received in the stream. +- (void)xmppDelayedDelivery:(XMPPDelayedDelivery *)xmppDelayedDelivery + didReceiveDelayedMessage:(XMPPMessage *)delayedMessage; + +/// Notifies the delegate that a delayed delivery presence has been received in the stream. +- (void)xmppDelayedDelivery:(XMPPDelayedDelivery *)xmppDelayedDelivery + didReceiveDelayedPresence:(XMPPPresence *)delayedPresence; + +@end + +NS_ASSUME_NONNULL_END diff --git a/Extensions/XEP-0203/XMPPDelayedDelivery.m b/Extensions/XEP-0203/XMPPDelayedDelivery.m new file mode 100644 index 0000000000..7831754150 --- /dev/null +++ b/Extensions/XEP-0203/XMPPDelayedDelivery.m @@ -0,0 +1,57 @@ +#import "XMPPDelayedDelivery.h" +#import "XMPPLogging.h" +#import "NSXMLElement+XEP_0203.h" + +// Log levels: off, error, warn, info, verbose +// Log flags: trace +#if DEBUG +static const int xmppLogLevel = XMPP_LOG_LEVEL_WARN; // | XMPP_LOG_FLAG_TRACE; +#else +static const int xmppLogLevel = XMPP_LOG_LEVEL_WARN; +#endif + +@implementation XMPPDelayedDelivery + +- (void)didActivate +{ + XMPPLogTrace(); +} + +- (void)willDeactivate +{ + XMPPLogTrace(); +} + +- (void)xmppStream:(XMPPStream *)sender didReceiveMessage:(XMPPMessage *)message +{ + XMPPLogTrace(); + + if (![message wasDelayed]) { + return; + } + + XMPPLogInfo(@"Received delayed delivery message with date: %@, origin: %@, reason description: %@", + [message delayedDeliveryDate], + [message delayedDeliveryFrom] ?: @"unspecified", + [message delayedDeliveryReasonDescription] ?: @"unspecified"); + + [multicastDelegate xmppDelayedDelivery:self didReceiveDelayedMessage:message]; +} + +- (void)xmppStream:(XMPPStream *)sender didReceivePresence:(XMPPPresence *)presence +{ + XMPPLogTrace(); + + if (![presence wasDelayed]) { + return; + } + + XMPPLogInfo(@"Received delayed delivery presence with date: %@, origin: %@, reason description: %@", + [presence delayedDeliveryDate], + [presence delayedDeliveryFrom] ?: @"unspecified", + [presence delayedDeliveryReasonDescription] ?: @"unspecified"); + + [multicastDelegate xmppDelayedDelivery:self didReceiveDelayedPresence:presence]; +} + +@end diff --git a/XMPPFramework.xcodeproj/project.pbxproj b/XMPPFramework.xcodeproj/project.pbxproj index f1605724b0..cb700c5ca4 100644 --- a/XMPPFramework.xcodeproj/project.pbxproj +++ b/XMPPFramework.xcodeproj/project.pbxproj @@ -938,6 +938,12 @@ D9E6A05A1F92DEE100D8BFCB /* XMPPStanzaIdModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D9E6A0561F92DEE100D8BFCB /* XMPPStanzaIdModule.m */; }; D9E6A05B1F92DEE100D8BFCB /* XMPPStanzaIdModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D9E6A0561F92DEE100D8BFCB /* XMPPStanzaIdModule.m */; }; D9E6A05C1F92DEE100D8BFCB /* XMPPStanzaIdModule.m in Sources */ = {isa = PBXBuildFile; fileRef = D9E6A0561F92DEE100D8BFCB /* XMPPStanzaIdModule.m */; }; + DD1C59831F4429FD003D73DB /* XMPPDelayedDelivery.h in Headers */ = {isa = PBXBuildFile; fileRef = DD1C59811F4429FD003D73DB /* XMPPDelayedDelivery.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DD1C59841F4429FD003D73DB /* XMPPDelayedDelivery.h in Headers */ = {isa = PBXBuildFile; fileRef = DD1C59811F4429FD003D73DB /* XMPPDelayedDelivery.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DD1C59851F4429FD003D73DB /* XMPPDelayedDelivery.h in Headers */ = {isa = PBXBuildFile; fileRef = DD1C59811F4429FD003D73DB /* XMPPDelayedDelivery.h */; settings = {ATTRIBUTES = (Public, ); }; }; + DD1C59861F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1C59821F4429FD003D73DB /* XMPPDelayedDelivery.m */; }; + DD1C59871F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1C59821F4429FD003D73DB /* XMPPDelayedDelivery.m */; }; + DD1C59881F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */ = {isa = PBXBuildFile; fileRef = DD1C59821F4429FD003D73DB /* XMPPDelayedDelivery.m */; }; DD1E73331ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.h in Headers */ = {isa = PBXBuildFile; fileRef = DD1E73311ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.h */; settings = {ATTRIBUTES = (Public, ); }; }; DD1E73341ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.h in Headers */ = {isa = PBXBuildFile; fileRef = DD1E73311ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.h */; settings = {ATTRIBUTES = (Public, ); }; }; DD1E73351ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.h in Headers */ = {isa = PBXBuildFile; fileRef = DD1E73311ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -1561,6 +1567,8 @@ D9DCD6BF1E625B4D0010D1C7 /* AppKit.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = AppKit.framework; path = Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.12.sdk/System/Library/Frameworks/AppKit.framework; sourceTree = DEVELOPER_DIR; }; D9E6A0551F92DEE100D8BFCB /* XMPPStanzaIdModule.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = XMPPStanzaIdModule.h; sourceTree = ""; }; D9E6A0561F92DEE100D8BFCB /* XMPPStanzaIdModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XMPPStanzaIdModule.m; sourceTree = ""; }; + DD1C59811F4429FD003D73DB /* XMPPDelayedDelivery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPDelayedDelivery.h; sourceTree = ""; }; + DD1C59821F4429FD003D73DB /* XMPPDelayedDelivery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPDelayedDelivery.m; sourceTree = ""; }; DD1E73311ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XMPPRoomLightCoreDataStorage+XEP_0313.h"; sourceTree = ""; }; DD1E73321ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XMPPRoomLightCoreDataStorage+XEP_0313.m"; sourceTree = ""; }; DD1E73391ED88622009B529B /* XMPPRoomLightCoreDataStorageProtected.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPRoomLightCoreDataStorageProtected.h; sourceTree = ""; }; @@ -2394,6 +2402,8 @@ D9DCD2131E6250930010D1C7 /* XEP-0203 */ = { isa = PBXGroup; children = ( + DD1C59811F4429FD003D73DB /* XMPPDelayedDelivery.h */, + DD1C59821F4429FD003D73DB /* XMPPDelayedDelivery.m */, D9DCD2141E6250930010D1C7 /* NSXMLElement+XEP_0203.h */, D9DCD2151E6250930010D1C7 /* NSXMLElement+XEP_0203.m */, ); @@ -2744,6 +2754,7 @@ D9DCD26E1E6250930010D1C7 /* XMPPResourceCoreDataStorageObject.h in Headers */, D9DCD2831E6250930010D1C7 /* XMPPIQ+JabberRPC.h in Headers */, D9DCD3201E6250930010D1C7 /* XMPPMessageArchiveManagement.h in Headers */, + DD1C59831F4429FD003D73DB /* XMPPDelayedDelivery.h in Headers */, D9DCD2D61E6250930010D1C7 /* NSDate+XMPPDateTimeProfiles.h in Headers */, D9DCD2BA1E6250930010D1C7 /* XMPPvCardTempAdrTypes.h in Headers */, D9DCD2C81E6250930010D1C7 /* XMPPResultSet.h in Headers */, @@ -2912,6 +2923,7 @@ D9DCD4FB1E6256D90010D1C7 /* XMPPResourceCoreDataStorageObject.h in Headers */, D9DCD4FC1E6256D90010D1C7 /* XMPPIQ+JabberRPC.h in Headers */, D9DCD4FD1E6256D90010D1C7 /* XMPPMessageArchiveManagement.h in Headers */, + DD1C59841F4429FD003D73DB /* XMPPDelayedDelivery.h in Headers */, D9DCD4FE1E6256D90010D1C7 /* NSDate+XMPPDateTimeProfiles.h in Headers */, D9DCD4FF1E6256D90010D1C7 /* XMPPvCardTempAdrTypes.h in Headers */, D9DCD5001E6256D90010D1C7 /* XMPPResultSet.h in Headers */, @@ -3080,6 +3092,7 @@ D9DCD65E1E6258CF0010D1C7 /* XMPPResourceCoreDataStorageObject.h in Headers */, D9DCD65F1E6258CF0010D1C7 /* XMPPIQ+JabberRPC.h in Headers */, D9DCD6601E6258CF0010D1C7 /* XMPPMessageArchiveManagement.h in Headers */, + DD1C59851F4429FD003D73DB /* XMPPDelayedDelivery.h in Headers */, D9DCD6611E6258CF0010D1C7 /* NSDate+XMPPDateTimeProfiles.h in Headers */, D9DCD6621E6258CF0010D1C7 /* XMPPvCardTempAdrTypes.h in Headers */, D9DCD6631E6258CF0010D1C7 /* XMPPResultSet.h in Headers */, @@ -3576,6 +3589,7 @@ 0D44BB531E537105000930E0 /* XMPPSCRAMSHA1Authentication.m in Sources */, D9DCD32B1E6250930010D1C7 /* XMPPIQ+XEP_0357.m in Sources */, DD855F941F74F2B000E12330 /* XMPPOutOfBandResourceMessaging.m in Sources */, + DD1C59861F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */, D9DCD2F71E6250930010D1C7 /* XMPPvCardAvatarModule.m in Sources */, D9DCD26B1E6250930010D1C7 /* XMPPReconnect.m in Sources */, D9DCD2B91E6250930010D1C7 /* XMPPvCardTempAdr.m in Sources */, @@ -3735,6 +3749,7 @@ D9DCD45C1E6256D90010D1C7 /* XMPPSCRAMSHA1Authentication.m in Sources */, D9DCD45D1E6256D90010D1C7 /* XMPPIQ+XEP_0357.m in Sources */, DD855F951F74F2B000E12330 /* XMPPOutOfBandResourceMessaging.m in Sources */, + DD1C59871F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */, D9DCD45E1E6256D90010D1C7 /* XMPPvCardAvatarModule.m in Sources */, D9DCD45F1E6256D90010D1C7 /* XMPPReconnect.m in Sources */, D9DCD4601E6256D90010D1C7 /* XMPPvCardTempAdr.m in Sources */, @@ -3894,6 +3909,7 @@ D9DCD5BF1E6258CF0010D1C7 /* XMPPSCRAMSHA1Authentication.m in Sources */, D9DCD5C01E6258CF0010D1C7 /* XMPPIQ+XEP_0357.m in Sources */, DD855F961F74F2B000E12330 /* XMPPOutOfBandResourceMessaging.m in Sources */, + DD1C59881F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */, D9DCD5C11E6258CF0010D1C7 /* XMPPvCardAvatarModule.m in Sources */, D9DCD5C21E6258CF0010D1C7 /* XMPPReconnect.m in Sources */, D9DCD5C31E6258CF0010D1C7 /* XMPPvCardTempAdr.m in Sources */, diff --git a/Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj/project.pbxproj b/Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj/project.pbxproj index ed4e1f0a96..715f75d77a 100644 --- a/Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj/project.pbxproj +++ b/Xcode/Testing-Carthage/XMPPFrameworkTests.xcodeproj/project.pbxproj @@ -76,6 +76,9 @@ DDA11A4C1F8518AE00591D1B /* XMPPManagedMessagingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DDA11A4B1F8518AE00591D1B /* XMPPManagedMessagingTests.m */; }; DDA11A4D1F8518BA00591D1B /* XMPPManagedMessagingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DDA11A4B1F8518AE00591D1B /* XMPPManagedMessagingTests.m */; }; DDA11A4E1F8518BB00591D1B /* XMPPManagedMessagingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DDA11A4B1F8518AE00591D1B /* XMPPManagedMessagingTests.m */; }; + DD4003F91F7528A90078D144 /* XMPPDelayedDeliveryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4003F81F7528A90078D144 /* XMPPDelayedDeliveryTests.m */; }; + DD4003FA1F7528B40078D144 /* XMPPDelayedDeliveryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4003F81F7528A90078D144 /* XMPPDelayedDeliveryTests.m */; }; + DD4003FB1F7528B40078D144 /* XMPPDelayedDeliveryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD4003F81F7528A90078D144 /* XMPPDelayedDeliveryTests.m */; }; /* End PBXBuildFile section */ /* Begin PBXContainerItemProxy section */ @@ -153,6 +156,7 @@ DD26F5871F7CF1AE00F54F18 /* XMPPOneToOneChatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPOneToOneChatTests.m; sourceTree = ""; }; DD06EA441F78EBFD008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPMessageDeliveryReceiptsTests.m; sourceTree = ""; }; DDA11A4B1F8518AE00591D1B /* XMPPManagedMessagingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPManagedMessagingTests.m; sourceTree = ""; }; + DD4003F81F7528A90078D144 /* XMPPDelayedDeliveryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPDelayedDeliveryTests.m; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -227,6 +231,7 @@ DD26F5871F7CF1AE00F54F18 /* XMPPOneToOneChatTests.m */, DD06EA441F78EBFD008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m */, DDA11A4B1F8518AE00591D1B /* XMPPManagedMessagingTests.m */, + DD4003F81F7528A90078D144 /* XMPPDelayedDeliveryTests.m */, 63F50D971C60208200CA0201 /* Info.plist */, ); name = XMPPFrameworkTests; @@ -406,6 +411,7 @@ buildActionMask = 2147483647; files = ( D973A07C1D2F18040096F3ED /* CapabilitiesHashingTest.m in Sources */, + DD4003F91F7528A90078D144 /* XMPPDelayedDeliveryTests.m in Sources */, D973A0811D2F18040096F3ED /* XMPPMUCLightTests.m in Sources */, D973A07D1D2F18040096F3ED /* EncodeDecodeTest.m in Sources */, D973A0831D2F18040096F3ED /* XMPPRoomLightCoreDataStorageTests.m in Sources */, @@ -435,6 +441,7 @@ buildActionMask = 2147483647; files = ( D9DCD3D51E6255E10010D1C7 /* CapabilitiesHashingTest.m in Sources */, + DD4003FA1F7528B40078D144 /* XMPPDelayedDeliveryTests.m in Sources */, D9DCD3D61E6255E10010D1C7 /* XMPPMUCLightTests.m in Sources */, D9DCD3D71E6255E10010D1C7 /* EncodeDecodeTest.m in Sources */, D9DCD3D81E6255E10010D1C7 /* XMPPRoomLightCoreDataStorageTests.m in Sources */, @@ -464,6 +471,7 @@ buildActionMask = 2147483647; files = ( D9DCD6FE1E625C560010D1C7 /* CapabilitiesHashingTest.m in Sources */, + DD4003FB1F7528B40078D144 /* XMPPDelayedDeliveryTests.m in Sources */, D9DCD6FF1E625C560010D1C7 /* XMPPMUCLightTests.m in Sources */, D9DCD7001E625C560010D1C7 /* EncodeDecodeTest.m in Sources */, D9DCD7011E625C560010D1C7 /* XMPPRoomLightCoreDataStorageTests.m in Sources */, diff --git a/Xcode/Testing-Shared/XMPPDelayedDeliveryTests.m b/Xcode/Testing-Shared/XMPPDelayedDeliveryTests.m new file mode 100644 index 0000000000..34b165c8b4 --- /dev/null +++ b/Xcode/Testing-Shared/XMPPDelayedDeliveryTests.m @@ -0,0 +1,131 @@ +#import +#import "XMPPMockStream.h" + +@class XMPPDelayedDeliveryTestCallbackResult; + +@interface XMPPDelayedDeliveryTests : XCTestCase + +@property (nonatomic, strong) XMPPMockStream *mockStream; +@property (nonatomic, strong) XMPPDelayedDelivery *delayedDelivery; +@property (nonatomic, strong) XCTestExpectation *delegateCallbackExpectation; + +@end + +@implementation XMPPDelayedDeliveryTests + +- (void)setUp { + [super setUp]; + + self.mockStream = [[XMPPMockStream alloc] init]; + + self.delayedDelivery = [[XMPPDelayedDelivery alloc] init]; + [self.delayedDelivery addDelegate:self delegateQueue:dispatch_get_main_queue()]; + [self.delayedDelivery activate:self.mockStream]; +} + +- (void)testMessageDelegateCallback +{ + self.delegateCallbackExpectation = [self expectationWithDescription:@"Test message delegate callback expectation"]; + + [self fakeDelayedDeliveryMessage]; + + [self waitForExpectationsWithTimeout:5 handler:nil]; +} + +- (void)testPresenceDelegateCallback +{ + self.delegateCallbackExpectation = [self expectationWithDescription:@"Test presence delegate callback expectation"]; + + [self fakeDelayedDeliveryPresence]; + + [self waitForExpectationsWithTimeout:5 handler:nil]; +} + +- (void)testStanzaSkipping +{ + self.delegateCallbackExpectation = [self expectationWithDescription:@"Test skipped delegate callback expectation"]; + self.delegateCallbackExpectation.inverted = YES; + + [self fakePlainMessage]; + [self fakePlainPresence]; + + [self waitForExpectationsWithTimeout:1 handler:nil]; +} + +- (void)xmppDelayedDelivery:(XMPPDelayedDelivery *)xmppDelayedDelivery didReceiveDelayedMessage:(XMPPMessage *)delayedMessage +{ + if ([self.delegateCallbackExpectation isInverted] || + ([[delayedMessage delayedDeliveryDate] isEqualToDate:[NSDate dateWithXmppDateTimeString:@"2002-09-10T23:08:25Z"]] + && [[delayedMessage delayedDeliveryFrom] isEqualToJID:[XMPPJID jidWithString:@"capulet.com"]] + && [[delayedMessage delayedDeliveryReasonDescription] isEqualToString:@"Offline Storage"])) { + [self.delegateCallbackExpectation fulfill]; + } +} + +- (void)xmppDelayedDelivery:(XMPPDelayedDelivery *)xmppDelayedDelivery didReceiveDelayedPresence:(XMPPPresence *)delayedPresence +{ + if ([self.delegateCallbackExpectation isInverted] || + ([[delayedPresence delayedDeliveryDate] isEqualToDate:[NSDate dateWithXmppDateTimeString:@"2002-09-10T23:41:07Z"]] + && [[delayedPresence delayedDeliveryFrom] isEqualToJID:[XMPPJID jidWithString:@"juliet@capulet.com/balcony"]] + && [[delayedPresence delayedDeliveryReasonDescription] isEqualToString:@""])) { + [self.delegateCallbackExpectation fulfill]; + } +} + +- (void)fakeDelayedDeliveryMessage +{ + [self.mockStream fakeMessageResponse: + [[XMPPMessage alloc] initWithXMLString: + @"" + @"" + @"O blessed, blessed night! I am afeard." + @"Being in night, all this is but a dream," + @"Too flattering-sweet to be substantial." + @"" + @"" + @"Offline Storage" + @"" + @"" + error:nil]]; +} + +- (void)fakeDelayedDeliveryPresence +{ + [self.mockStream fakeResponse: + [[XMPPPresence alloc] initWithXMLString: + @"" + @"anon!" + @"xa" + @"1" + @"" + @"" + error:nil]]; +} + +- (void)fakePlainMessage +{ + [self.mockStream fakeMessageResponse: + [[XMPPMessage alloc] initWithXMLString: + @"" + @"" + @"O blessed, blessed night! I am afeard." + @"Being in night, all this is but a dream," + @"Too flattering-sweet to be substantial." + @"" + @"" + error:nil]]; +} + +- (void)fakePlainPresence +{ + [self.mockStream fakeResponse: + [[XMPPPresence alloc] initWithXMLString: + @"" + @"anon!" + @"xa" + @"1" + @"" + error:nil]]; +} + +@end diff --git a/Xcode/Testing-iOS/XMPPFrameworkTests.xcodeproj/project.pbxproj b/Xcode/Testing-iOS/XMPPFrameworkTests.xcodeproj/project.pbxproj index 5ca1d480c9..718c7f70b9 100644 --- a/Xcode/Testing-iOS/XMPPFrameworkTests.xcodeproj/project.pbxproj +++ b/Xcode/Testing-iOS/XMPPFrameworkTests.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ DDB40BA81F750B0800B82A93 /* XMPPOutOfBandResourceMessagingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DDB40BA71F750B0800B82A93 /* XMPPOutOfBandResourceMessagingTests.m */; }; DD26F5831F7CECD100F54F18 /* XMPPOneToOneChatTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD26F5821F7CECD100F54F18 /* XMPPOneToOneChatTests.m */; }; DD2AD6F01F84CB0400E0FED2 /* XMPPManagedMessagingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD2AD6EF1F84CB0400E0FED2 /* XMPPManagedMessagingTests.m */; }; + DD24E0251F7119A300FA813C /* XMPPDelayedDeliveryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD24E0241F7119A300FA813C /* XMPPDelayedDeliveryTests.m */; }; FDD2AB232C05507F2045FFFC /* Pods_XMPPFrameworkTests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 5CD0B17267211A912DE2098E /* Pods_XMPPFrameworkTests.framework */; }; /* End PBXBuildFile section */ @@ -63,6 +64,7 @@ DDB40BA71F750B0800B82A93 /* XMPPOutOfBandResourceMessagingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = XMPPOutOfBandResourceMessagingTests.m; path = "../../Testing-Shared/XMPPOutOfBandResourceMessagingTests.m"; sourceTree = ""; }; DD26F5821F7CECD100F54F18 /* XMPPOneToOneChatTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = XMPPOneToOneChatTests.m; path = "../../Testing-Shared/XMPPOneToOneChatTests.m"; sourceTree = ""; }; DD2AD6EF1F84CB0400E0FED2 /* XMPPManagedMessagingTests.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; name = XMPPManagedMessagingTests.m; path = "../../Testing-Shared/XMPPManagedMessagingTests.m"; sourceTree = ""; }; + DD24E0241F7119A300FA813C /* XMPPDelayedDeliveryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPDelayedDeliveryTests.m; path = "../../Testing-Shared/XMPPDelayedDeliveryTests.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -120,6 +122,7 @@ DD26F5821F7CECD100F54F18 /* XMPPOneToOneChatTests.m */, DD06EA3F1F78E566008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m */, DD2AD6EF1F84CB0400E0FED2 /* XMPPManagedMessagingTests.m */, + DD24E0241F7119A300FA813C /* XMPPDelayedDeliveryTests.m */, 63F50D971C60208200CA0201 /* Info.plist */, D973A06E1D2F18030096F3ED /* XMPPFrameworkTests-Bridging-Header.h */, ); @@ -265,6 +268,7 @@ DDB40BA81F750B0800B82A93 /* XMPPOutOfBandResourceMessagingTests.m in Sources */, D973A07C1D2F18040096F3ED /* CapabilitiesHashingTest.m in Sources */, DD26F5831F7CECD100F54F18 /* XMPPOneToOneChatTests.m in Sources */, + DD24E0251F7119A300FA813C /* XMPPDelayedDeliveryTests.m in Sources */, D973A0811D2F18040096F3ED /* XMPPMUCLightTests.m in Sources */, D973A07D1D2F18040096F3ED /* EncodeDecodeTest.m in Sources */, D973A0831D2F18040096F3ED /* XMPPRoomLightCoreDataStorageTests.m in Sources */, diff --git a/Xcode/Testing-macOS/XMPPFrameworkTests.xcodeproj/project.pbxproj b/Xcode/Testing-macOS/XMPPFrameworkTests.xcodeproj/project.pbxproj index 03ba42bcac..9c5a147a7f 100644 --- a/Xcode/Testing-macOS/XMPPFrameworkTests.xcodeproj/project.pbxproj +++ b/Xcode/Testing-macOS/XMPPFrameworkTests.xcodeproj/project.pbxproj @@ -29,6 +29,7 @@ DD26F5851F7CF17200F54F18 /* XMPPOneToOneChatTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD26F5841F7CF17200F54F18 /* XMPPOneToOneChatTests.m */; }; DD06EA421F78EB3B008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD06EA411F78EB3B008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m */; }; DDA11A491F8517C300591D1B /* XMPPManagedMessagingTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DDA11A481F8517C200591D1B /* XMPPManagedMessagingTests.m */; }; + DD24E0271F71463C00FA813C /* XMPPDelayedDeliveryTests.m in Sources */ = {isa = PBXBuildFile; fileRef = DD24E0261F71463C00FA813C /* XMPPDelayedDeliveryTests.m */; }; /* End PBXBuildFile section */ /* Begin PBXFileReference section */ @@ -60,6 +61,7 @@ DD26F5841F7CF17200F54F18 /* XMPPOneToOneChatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPOneToOneChatTests.m; path = "../../Testing-Shared/XMPPOneToOneChatTests.m"; sourceTree = ""; }; DD06EA411F78EB3B008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPMessageDeliveryReceiptsTests.m; path = "../../Testing-Shared/XMPPMessageDeliveryReceiptsTests.m"; sourceTree = ""; }; DDA11A481F8517C200591D1B /* XMPPManagedMessagingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPManagedMessagingTests.m; path = "../../Testing-Shared/XMPPManagedMessagingTests.m"; sourceTree = ""; }; + DD24E0261F71463C00FA813C /* XMPPDelayedDeliveryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = XMPPDelayedDeliveryTests.m; path = "../../Testing-Shared/XMPPDelayedDeliveryTests.m"; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -120,6 +122,7 @@ DD26F5841F7CF17200F54F18 /* XMPPOneToOneChatTests.m */, DD06EA411F78EB3B008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m */, DDA11A481F8517C200591D1B /* XMPPManagedMessagingTests.m */, + DD24E0261F71463C00FA813C /* XMPPDelayedDeliveryTests.m */, D973A0921D2F1EB10096F3ED /* Info.plist */, ); path = XMPPFrameworkTests; @@ -262,6 +265,7 @@ DD06EA421F78EB3B008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m in Sources */, D9F20D011D836080002A8D6F /* OMEMOModuleTests.m in Sources */, D973A0A91D2F1EF60096F3ED /* XMPPMUCLightTests.m in Sources */, + DD24E0271F71463C00FA813C /* XMPPDelayedDeliveryTests.m in Sources */, D973A0A51D2F1EF60096F3ED /* EncodeDecodeTest.m in Sources */, D973A0AB1D2F1EF60096F3ED /* XMPPRoomLightCoreDataStorageTests.m in Sources */, D973A0AE1D2F1EF60096F3ED /* XMPPSwift.swift in Sources */,