Skip to content

Commit

Permalink
Merge branch 'delayed-delivery-module' of https://github.com/esl/XMPP…
Browse files Browse the repository at this point in the history
…Framework into esl-one-to-one-chat-module
  • Loading branch information
chrisballinger committed Nov 13, 2017
2 parents 11b97ad + 6cbd815 commit baf95bf
Show file tree
Hide file tree
Showing 10 changed files with 281 additions and 21 deletions.
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 @@ -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 = "<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 @@ -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 */,
);
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -153,6 +156,7 @@
DD26F5871F7CF1AE00F54F18 /* XMPPOneToOneChatTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPOneToOneChatTests.m; sourceTree = "<group>"; };
DD06EA441F78EBFD008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPMessageDeliveryReceiptsTests.m; sourceTree = "<group>"; };
DDA11A4B1F8518AE00591D1B /* XMPPManagedMessagingTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = XMPPManagedMessagingTests.m; sourceTree = "<group>"; };
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 @@ -227,6 +231,7 @@
DD26F5871F7CF1AE00F54F18 /* XMPPOneToOneChatTests.m */,
DD06EA441F78EBFD008FA8C2 /* XMPPMessageDeliveryReceiptsTests.m */,
DDA11A4B1F8518AE00591D1B /* XMPPManagedMessagingTests.m */,
DD4003F81F7528A90078D144 /* XMPPDelayedDeliveryTests.m */,
63F50D971C60208200CA0201 /* Info.plist */,
);
name = XMPPFrameworkTests;
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down Expand Up @@ -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 */,
Expand Down
Loading

0 comments on commit baf95bf

Please sign in to comment.