Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delayed delivery module #1001

Merged
merged 2 commits into from
Nov 13, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Core/XMPPFramework.h
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
3 changes: 3 additions & 0 deletions Extensions/XEP-0203/NSXMLElement+XEP_0203.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#import <Foundation/Foundation.h>
@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
53 changes: 32 additions & 21 deletions Extensions/XEP-0203/NSXMLElement+XEP_0203.m
Original file line number Diff line number Diff line change
@@ -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).
Expand All @@ -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 xmlns='urn:xmpp:delay'
Expand All @@ -40,7 +25,7 @@ - (NSDate *)delayedDeliveryDate
// The format [of the stamp attribute] MUST adhere to the dateTime format
// specified in XEP-0082 and MUST be expressed in UTC.

delay = [self elementForName:@"delay" xmlns:@"urn:xmpp:delay"];
NSXMLElement *delay = [self delayedDeliveryChildElement];
if (delay)
{
NSString *stampValue = [delay attributeStringValueForName:@"stamp"];
Expand All @@ -60,12 +45,12 @@ - (NSDate *)delayedDeliveryDate
// from='capulet.com'
// stamp='20020910T23:08:25'>

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];
Expand All @@ -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
25 changes: 25 additions & 0 deletions Extensions/XEP-0203/XMPPDelayedDelivery.h
Original file line number Diff line number Diff line change
@@ -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 <NSObject>

@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
57 changes: 57 additions & 0 deletions Extensions/XEP-0203/XMPPDelayedDelivery.m
Original file line number Diff line number Diff line change
@@ -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
16 changes: 16 additions & 0 deletions XMPPFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -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, ); }; };
Expand Down Expand Up @@ -1543,6 +1549,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 = "<group>"; };
D9E6A0561F92DEE100D8BFCB /* XMPPStanzaIdModule.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = XMPPStanzaIdModule.m; sourceTree = "<group>"; };
DD1C59811F4429FD003D73DB /* XMPPDelayedDelivery.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPDelayedDelivery.h; sourceTree = "<group>"; };
DD1C59821F4429FD003D73DB /* XMPPDelayedDelivery.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPDelayedDelivery.m; sourceTree = "<group>"; };
DD1E73311ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "XMPPRoomLightCoreDataStorage+XEP_0313.h"; sourceTree = "<group>"; };
DD1E73321ED885FD009B529B /* XMPPRoomLightCoreDataStorage+XEP_0313.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "XMPPRoomLightCoreDataStorage+XEP_0313.m"; sourceTree = "<group>"; };
DD1E73391ED88622009B529B /* XMPPRoomLightCoreDataStorageProtected.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = XMPPRoomLightCoreDataStorageProtected.h; sourceTree = "<group>"; };
Expand Down Expand Up @@ -2366,6 +2374,8 @@
D9DCD2131E6250930010D1C7 /* XEP-0203 */ = {
isa = PBXGroup;
children = (
DD1C59811F4429FD003D73DB /* XMPPDelayedDelivery.h */,
DD1C59821F4429FD003D73DB /* XMPPDelayedDelivery.m */,
D9DCD2141E6250930010D1C7 /* NSXMLElement+XEP_0203.h */,
D9DCD2151E6250930010D1C7 /* NSXMLElement+XEP_0203.m */,
);
Expand Down Expand Up @@ -2696,6 +2706,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 */,
Expand Down Expand Up @@ -2861,6 +2872,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 */,
Expand Down Expand Up @@ -3026,6 +3038,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 */,
Expand Down Expand Up @@ -3519,6 +3532,7 @@
D9DCD2531E6250930010D1C7 /* XMPPIncomingFileTransfer.m in Sources */,
0D44BB531E537105000930E0 /* XMPPSCRAMSHA1Authentication.m in Sources */,
D9DCD32B1E6250930010D1C7 /* XMPPIQ+XEP_0357.m in Sources */,
DD1C59861F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */,
D9DCD2F71E6250930010D1C7 /* XMPPvCardAvatarModule.m in Sources */,
D9DCD26B1E6250930010D1C7 /* XMPPReconnect.m in Sources */,
D9DCD2B91E6250930010D1C7 /* XMPPvCardTempAdr.m in Sources */,
Expand Down Expand Up @@ -3675,6 +3689,7 @@
D9DCD45B1E6256D90010D1C7 /* XMPPIncomingFileTransfer.m in Sources */,
D9DCD45C1E6256D90010D1C7 /* XMPPSCRAMSHA1Authentication.m in Sources */,
D9DCD45D1E6256D90010D1C7 /* XMPPIQ+XEP_0357.m in Sources */,
DD1C59871F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */,
D9DCD45E1E6256D90010D1C7 /* XMPPvCardAvatarModule.m in Sources */,
D9DCD45F1E6256D90010D1C7 /* XMPPReconnect.m in Sources */,
D9DCD4601E6256D90010D1C7 /* XMPPvCardTempAdr.m in Sources */,
Expand Down Expand Up @@ -3831,6 +3846,7 @@
D9DCD5BE1E6258CF0010D1C7 /* XMPPIncomingFileTransfer.m in Sources */,
D9DCD5BF1E6258CF0010D1C7 /* XMPPSCRAMSHA1Authentication.m in Sources */,
D9DCD5C01E6258CF0010D1C7 /* XMPPIQ+XEP_0357.m in Sources */,
DD1C59881F4429FD003D73DB /* XMPPDelayedDelivery.m in Sources */,
D9DCD5C11E6258CF0010D1C7 /* XMPPvCardAvatarModule.m in Sources */,
D9DCD5C21E6258CF0010D1C7 /* XMPPReconnect.m in Sources */,
D9DCD5C31E6258CF0010D1C7 /* XMPPvCardTempAdr.m in Sources */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
D9DCD70E1E625C560010D1C7 /* OMEMOTestStorage.m in Sources */ = {isa = PBXBuildFile; fileRef = D99C5E0C1D99C48100FB068A /* OMEMOTestStorage.m */; };
D9DCD7191E625CAE0010D1C7 /* XMPPFramework.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = D9DCD6B01E625A9B0010D1C7 /* XMPPFramework.framework */; };
D9E35E701D90B894002E7CF7 /* OMEMOElementTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D9E35E6F1D90B894002E7CF7 /* OMEMOElementTests.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 */
Expand Down Expand Up @@ -137,6 +140,7 @@
D9DCD3EC1E6255E10010D1C7 /* XMPPFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XMPPFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D9DCD7151E625C560010D1C7 /* XMPPFrameworkTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = XMPPFrameworkTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
D9E35E6F1D90B894002E7CF7 /* OMEMOElementTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = OMEMOElementTests.m; path = "../Testing-Shared/OMEMOElementTests.m"; sourceTree = SOURCE_ROOT; };
DD4003F81F7528A90078D144 /* XMPPDelayedDeliveryTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPDelayedDeliveryTests.m; sourceTree = "<group>"; };
/* End PBXFileReference section */

/* Begin PBXFrameworksBuildPhase section */
Expand Down Expand Up @@ -207,6 +211,7 @@
D973A0791D2F18040096F3ED /* XMPPStorageHintTests.m */,
D973A07A1D2F18040096F3ED /* XMPPURITests.m */,
D973A07B1D2F18040096F3ED /* XMPPvCardTests.m */,
DD4003F81F7528A90078D144 /* XMPPDelayedDeliveryTests.m */,
63F50D971C60208200CA0201 /* Info.plist */,
);
name = XMPPFrameworkTests;
Expand Down Expand Up @@ -386,6 +391,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 */,
Expand All @@ -411,6 +417,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 */,
Expand All @@ -436,6 +443,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 */,
Expand Down
Loading