From 21f8b7891e0c239240d0072a9a30e4e65d3c6704 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 27 Dec 2022 14:59:47 +0100 Subject: [PATCH 01/10] feat(publish): add message type support for `publish` API Add new publish parameters to specify `messageType` and `spaceId`. feat(signal): add message type support for `signal` API Add new signal parameters to specify `messageType` and `spaceId`. feat(history): add message type support for `history` API Make it possible to opt-out message type receive for stored messages and get `spaceId` for stored message. --- .../project.pbxproj | 84 +++++++++++-- Framework/PubNub/PubNub.h | 4 + PubNub/Core/PubNub+Publish.h | 3 + PubNub/Core/PubNub+Publish.m | 91 ++++++++++++-- .../Publish/PNPublishAPICallBuilder.h | 30 +++++ .../Publish/PNPublishAPICallBuilder.m | 24 ++-- .../API Call/Publish/PNSignalAPICallBuilder.h | 30 ++++- .../API Call/Publish/PNSignalAPICallBuilder.m | 16 ++- PubNub/Data/Managers/PNSubscriber.m | 4 +- PubNub/Data/Models/PNMessageType+Private.h | 38 ++++++ PubNub/Data/Models/PNMessageType.h | 76 +++++++++++ PubNub/Data/Models/PNMessageType.m | 119 ++++++++++++++++++ PubNub/Data/Models/PNSpaceId.h | 64 ++++++++++ PubNub/Data/Models/PNSpaceId.m | 81 ++++++++++++ PubNub/Data/PNEnvelopeInformation.h | 21 +++- PubNub/Data/PNEnvelopeInformation.m | 42 +++++-- .../Data/Service Objects/PNSubscribeStatus.h | 94 +++++++------- .../Data/Service Objects/PNSubscribeStatus.m | 22 ++-- PubNub/Misc/PNPrivateStructures.h | 7 +- PubNub/Network/Parsers/PNHistoryParser.m | 22 +++- PubNub/Network/Parsers/PNSubscribeParser.m | 2 +- .../Requests/Publish/PNBasePublishRequest.h | 17 ++- 22 files changed, 778 insertions(+), 113 deletions(-) create mode 100644 PubNub/Data/Models/PNMessageType+Private.h create mode 100644 PubNub/Data/Models/PNMessageType.h create mode 100644 PubNub/Data/Models/PNMessageType.m create mode 100644 PubNub/Data/Models/PNSpaceId.h create mode 100644 PubNub/Data/Models/PNSpaceId.m diff --git a/Framework/PubNub Framework.xcodeproj/project.pbxproj b/Framework/PubNub Framework.xcodeproj/project.pbxproj index 5da3b015e..c3293db01 100644 --- a/Framework/PubNub Framework.xcodeproj/project.pbxproj +++ b/Framework/PubNub Framework.xcodeproj/project.pbxproj @@ -2493,6 +2493,31 @@ A5A7B0332349330F0060113B /* PNBaseMessageActionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A7AFF82349330F0060113B /* PNBaseMessageActionRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; A5A7B0342349330F0060113B /* PNBaseMessageActionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A7AFF82349330F0060113B /* PNBaseMessageActionRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; A5A7B0362349330F0060113B /* PNBaseMessageActionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A7AFF82349330F0060113B /* PNBaseMessageActionRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35612959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35622959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35632959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35642959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35652959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35662959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; + A5CE35672959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; + A5CE35682959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; + A5CE35692959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; + A5CE356A2959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; + A5CE356C2959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; + A5CE356D2959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; + A5CE356E2959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; + A5CE356F2959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; + A5CE35702959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; + A5CE35732959D1E80038FD6F /* PNSpaceId.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE35712959D1E80038FD6F /* PNSpaceId.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35742959D1E80038FD6F /* PNSpaceId.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE35712959D1E80038FD6F /* PNSpaceId.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35752959D1E80038FD6F /* PNSpaceId.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE35712959D1E80038FD6F /* PNSpaceId.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35762959D1E80038FD6F /* PNSpaceId.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE35712959D1E80038FD6F /* PNSpaceId.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35772959D1E80038FD6F /* PNSpaceId.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE35712959D1E80038FD6F /* PNSpaceId.h */; settings = {ATTRIBUTES = (Public, ); }; }; + A5CE35782959D1E80038FD6F /* PNSpaceId.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35722959D1E80038FD6F /* PNSpaceId.m */; }; + A5CE35792959D1E80038FD6F /* PNSpaceId.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35722959D1E80038FD6F /* PNSpaceId.m */; }; + A5CE357A2959D1E80038FD6F /* PNSpaceId.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35722959D1E80038FD6F /* PNSpaceId.m */; }; + A5CE357B2959D1E80038FD6F /* PNSpaceId.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35722959D1E80038FD6F /* PNSpaceId.m */; }; + A5CE357C2959D1E80038FD6F /* PNSpaceId.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35722959D1E80038FD6F /* PNSpaceId.m */; }; A5FADC342490270E001D7704 /* PubNub+Files.h in Headers */ = {isa = PBXBuildFile; fileRef = A5FADC322490270E001D7704 /* PubNub+Files.h */; settings = {ATTRIBUTES = (Public, ); }; }; A5FADC352490270E001D7704 /* PubNub+Files.h in Headers */ = {isa = PBXBuildFile; fileRef = A5FADC322490270E001D7704 /* PubNub+Files.h */; settings = {ATTRIBUTES = (Public, ); }; }; A5FADC362490270E001D7704 /* PubNub+Files.h in Headers */ = {isa = PBXBuildFile; fileRef = A5FADC322490270E001D7704 /* PubNub+Files.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -3043,6 +3068,11 @@ A5A7AFF62349330E0060113B /* PNRemoveMessageActionRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PNRemoveMessageActionRequest.m; path = Message/PNRemoveMessageActionRequest.m; sourceTree = ""; }; A5A7AFF72349330F0060113B /* PNRemoveMessageActionRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PNRemoveMessageActionRequest.h; path = Message/PNRemoveMessageActionRequest.h; sourceTree = ""; }; A5A7AFF82349330F0060113B /* PNBaseMessageActionRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PNBaseMessageActionRequest.h; path = Message/PNBaseMessageActionRequest.h; sourceTree = ""; }; + A5CE355F2959C45B0038FD6F /* PNMessageType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PNMessageType.h; sourceTree = ""; }; + A5CE35602959C45B0038FD6F /* PNMessageType.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PNMessageType.m; sourceTree = ""; }; + A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PNMessageType+Private.h"; sourceTree = ""; }; + A5CE35712959D1E80038FD6F /* PNSpaceId.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PNSpaceId.h; sourceTree = ""; }; + A5CE35722959D1E80038FD6F /* PNSpaceId.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PNSpaceId.m; sourceTree = ""; }; A5FADC322490270E001D7704 /* PubNub+Files.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PubNub+Files.h"; sourceTree = ""; }; A5FADC332490270E001D7704 /* PubNub+Files.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = "PubNub+Files.m"; sourceTree = ""; }; A5FADC3F2490292A001D7704 /* PNSendFileRequest.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PNSendFileRequest.h; sourceTree = ""; }; @@ -3780,30 +3810,35 @@ A55A86A322FD817E002D0A72 /* Models */ = { isa = PBXGroup; children = ( - A55BCD24231D27F00019DB68 /* PNMessageAction+Private.h */, - A55BCD14231D26110019DB68 /* PNMessageAction.h */, - A55BCD15231D26110019DB68 /* PNMessageAction.m */, - A58975E023005CFB0093BD9A /* PNMembership+Private.h */, - A58975C023005BD80093BD9A /* PNMembership.h */, - A58975C123005BD80093BD9A /* PNMembership.m */, - A568655F2300622C0014E17C /* PNChannelMember+Private.h */, - A58975D023005BE60093BD9A /* PNChannelMember.h */, - A58975D123005BE60093BD9A /* PNChannelMember.m */, A55A86A522FD817E002D0A72 /* PNChannelMetadata+Private.h */, A55A86A622FD817E002D0A72 /* PNChannelMetadata.h */, A55A86A922FD817E002D0A72 /* PNChannelMetadata.m */, + A568655F2300622C0014E17C /* PNChannelMember+Private.h */, + A58975D023005BE60093BD9A /* PNChannelMember.h */, + A58975D123005BE60093BD9A /* PNChannelMember.m */, + A55BCD24231D27F00019DB68 /* PNMessageAction+Private.h */, + A55BCD14231D26110019DB68 /* PNMessageAction.h */, + A55BCD15231D26110019DB68 /* PNMessageAction.m */, A55A86A722FD817E002D0A72 /* PNUUIDMetadata+Private.h */, A55A86A822FD817E002D0A72 /* PNUUIDMetadata.h */, A55A86A422FD817E002D0A72 /* PNUUIDMetadata.m */, + A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */, + A5CE355F2959C45B0038FD6F /* PNMessageType.h */, + A5CE35602959C45B0038FD6F /* PNMessageType.m */, + A5CE35712959D1E80038FD6F /* PNSpaceId.h */, + A5CE35722959D1E80038FD6F /* PNSpaceId.m */, + A58975E023005CFB0093BD9A /* PNMembership+Private.h */, + A58975C023005BD80093BD9A /* PNMembership.h */, + A58975C123005BD80093BD9A /* PNMembership.m */, 79CFA2CF26DE1CD100D206D4 /* PNPAMToken+Private.h */, 79CFA2B726DE1C4900D206D4 /* PNPAMToken.h */, 79CFA2B826DE1C4900D206D4 /* PNPAMToken.m */, - A504E14B24AA9515006DCF5B /* PNFile+Private.h */, - A504E13F24AA94C8006DCF5B /* PNFile.h */, - A504E14024AA94C8006DCF5B /* PNFile.m */, A55DAF0624B1FEC800766EE9 /* PNXML+Private.h */, A55DAEFA24B1FE9E00766EE9 /* PNXML.h */, A55DAEFB24B1FE9E00766EE9 /* PNXML.m */, + A504E14B24AA9515006DCF5B /* PNFile+Private.h */, + A504E13F24AA94C8006DCF5B /* PNFile.h */, + A504E14024AA94C8006DCF5B /* PNFile.m */, ); path = Models; sourceTree = ""; @@ -4057,6 +4092,7 @@ 79AA8EC926EAB81500ADA747 /* PNConfiguration+Private.h in Headers */, A58975B223005AAC0093BD9A /* PNManageMembershipsStatus.h in Headers */, 79A238D01D2E70BD00D080CD /* NSURLSessionConfiguration+PNConfiguration.h in Headers */, + A5CE356C2959C9260038FD6F /* PNMessageType+Private.h in Headers */, 791582521BD709C60084FC70 /* PNPresenceChannelGroupHereNowResult.h in Headers */, 7932485E1D874D9F00FBDF36 /* PNPublishSequence.h in Headers */, 79A0D8441DC22C950039A264 /* PNAPNSAuditAPICallBuilder.h in Headers */, @@ -4168,6 +4204,7 @@ A55DAEFC24B1FE9E00766EE9 /* PNXML.h in Headers */, A55A87DC22FD8272002D0A72 /* PNBaseObjectsRequest.h in Headers */, A57A3089238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, + A5CE35612959C45B0038FD6F /* PNMessageType.h in Headers */, 79A0D86E1DC22C950039A264 /* PNAPICallBuilder+Private.h in Headers */, A57A30E9238DCAAF00DE8C68 /* PNAPNSNotificationTarget+Private.h in Headers */, A55A881B22FD8272002D0A72 /* PNFetchAllChannelsMetadataRequest.h in Headers */, @@ -4216,6 +4253,7 @@ A5A4519E246DE792008ECC74 /* PNRemoveMembershipsRequest.h in Headers */, A504E11C24AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.h in Headers */, A55A86B822FD817E002D0A72 /* PNChannelMetadata.h in Headers */, + A5CE35732959D1E80038FD6F /* PNSpaceId.h in Headers */, 7915827E1BD709C60084FC70 /* PNURLBuilder.h in Headers */, A55A86BF22FD817E002D0A72 /* PNUUIDMetadata+Private.h in Headers */, 7915827C1BD709C60084FC70 /* PNTimeParser.h in Headers */, @@ -4332,6 +4370,7 @@ 79AA8ECB26EAB81500ADA747 /* PNConfiguration+Private.h in Headers */, A58975B423005AAC0093BD9A /* PNManageMembershipsStatus.h in Headers */, 791583201BD709D10084FC70 /* PNPushNotificationsStateModificationParser.h in Headers */, + A5CE356E2959C9260038FD6F /* PNMessageType+Private.h in Headers */, 79A238D21D2E70BD00D080CD /* NSURLSessionConfiguration+PNConfiguration.h in Headers */, 791582FB1BD709D10084FC70 /* PNPresenceChannelGroupHereNowResult.h in Headers */, 793248601D874D9F00FBDF36 /* PNPublishSequence.h in Headers */, @@ -4443,6 +4482,7 @@ A55DAEFE24B1FE9E00766EE9 /* PNXML.h in Headers */, A55A87DE22FD8272002D0A72 /* PNBaseObjectsRequest.h in Headers */, A57A308B238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, + A5CE35632959C45B0038FD6F /* PNMessageType.h in Headers */, 791583111BD709D10084FC70 /* PNHistoryResult.h in Headers */, A57A30EB238DCAAF00DE8C68 /* PNAPNSNotificationTarget+Private.h in Headers */, A55A881D22FD8272002D0A72 /* PNFetchAllChannelsMetadataRequest.h in Headers */, @@ -4491,6 +4531,7 @@ A5A451A0246DE792008ECC74 /* PNRemoveMembershipsRequest.h in Headers */, A504E11E24AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.h in Headers */, A55A86BA22FD817E002D0A72 /* PNChannelMetadata.h in Headers */, + A5CE35752959D1E80038FD6F /* PNSpaceId.h in Headers */, 791583191BD709D10084FC70 /* PNTimeResult.h in Headers */, A55A86C122FD817E002D0A72 /* PNUUIDMetadata+Private.h in Headers */, 79A0D8C01DC22FD60039A264 /* PNPresenceChannelHereNowAPICallBuilder.h in Headers */, @@ -4633,6 +4674,7 @@ 7988423D1C18F128003E8948 /* PNAPNSEnabledChannelsResult.h in Headers */, A57A3027238D59B500DE8C68 /* PNRemovePushNotificationsRequest.h in Headers */, A5A7AFD2234932F30060113B /* PNFetchMessagesActionsParser.h in Headers */, + A5CE35772959D1E80038FD6F /* PNSpaceId.h in Headers */, A55A861522FD80B9002D0A72 /* PNRemoveUUIDMetadataAPICallBuilder.h in Headers */, 79A0D8871DC22F520039A264 /* PNAPNSAPICallBuilder.h in Headers */, A5A451C1246DE8C3008ECC74 /* PNRemoveChannelMembersRequest.h in Headers */, @@ -4649,6 +4691,7 @@ A5A7B0132349330F0060113B /* PNAddMessageActionRequest.h in Headers */, A55BCCFB231D222B0019DB68 /* PNRemoveMessageActionAPICallBuilder.h in Headers */, 7960B6691F68122200FFAEBB /* PNDeleteMessageAPICallBuilder.h in Headers */, + A5CE35652959C45B0038FD6F /* PNMessageType.h in Headers */, A55DAF0B24B1FEC800766EE9 /* PNXML+Private.h in Headers */, A504E15824AA9CFB006DCF5B /* PNFilesAPICallBuilder.h in Headers */, A57A308E238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, @@ -4835,6 +4878,7 @@ 7925DB8C1D3FFCAC00857C0D /* PNLLogger.h in Headers */, 79CFA2BD26DE1C4900D206D4 /* PNPAMToken.h in Headers */, 79A3E4142215699900F2ADB9 /* PNMessageCountAPICallBuilder.h in Headers */, + A5CE35702959C9260038FD6F /* PNMessageType+Private.h in Headers */, A55A866222FD80B9002D0A72 /* PNFetchChannelMetadataAPICallBuilder.h in Headers */, 79ABD8961F01636B007634E0 /* PNTelemetry.h in Headers */, 7988427F1C18F286003E8948 /* PNNumber.h in Headers */, @@ -4881,6 +4925,7 @@ 79AA8ECA26EAB81500ADA747 /* PNConfiguration+Private.h in Headers */, A58975B323005AAC0093BD9A /* PNManageMembershipsStatus.h in Headers */, 79A8BC8D1C58F93900015BDE /* PNPushNotificationsStateModificationParser.h in Headers */, + A5CE356D2959C9260038FD6F /* PNMessageType+Private.h in Headers */, 79A238D11D2E70BD00D080CD /* NSURLSessionConfiguration+PNConfiguration.h in Headers */, 79A8BC681C58F93900015BDE /* PNPresenceChannelGroupHereNowResult.h in Headers */, 7932485F1D874D9F00FBDF36 /* PNPublishSequence.h in Headers */, @@ -4992,6 +5037,7 @@ A55DAEFD24B1FE9E00766EE9 /* PNXML.h in Headers */, A55A87DD22FD8272002D0A72 /* PNBaseObjectsRequest.h in Headers */, A57A308A238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, + A5CE35622959C45B0038FD6F /* PNMessageType.h in Headers */, 79A8BC7E1C58F93900015BDE /* PNHistoryResult.h in Headers */, A57A30EA238DCAAF00DE8C68 /* PNAPNSNotificationTarget+Private.h in Headers */, A55A881C22FD8272002D0A72 /* PNFetchAllChannelsMetadataRequest.h in Headers */, @@ -5040,6 +5086,7 @@ A5A4519F246DE792008ECC74 /* PNRemoveMembershipsRequest.h in Headers */, A504E11D24AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.h in Headers */, A55A86B922FD817E002D0A72 /* PNChannelMetadata.h in Headers */, + A5CE35742959D1E80038FD6F /* PNSpaceId.h in Headers */, 79A8BC861C58F93900015BDE /* PNTimeResult.h in Headers */, A55A86C022FD817E002D0A72 /* PNUUIDMetadata+Private.h in Headers */, 79A0D8BF1DC22FD60039A264 /* PNPresenceChannelHereNowAPICallBuilder.h in Headers */, @@ -5156,6 +5203,7 @@ 79AA8ECC26EAB81500ADA747 /* PNConfiguration+Private.h in Headers */, A58975B523005AAC0093BD9A /* PNManageMembershipsStatus.h in Headers */, 79E20D2C1C8B0AD5001BC9CC /* PNPushNotificationsStateModificationParser.h in Headers */, + A5CE356F2959C9260038FD6F /* PNMessageType+Private.h in Headers */, 79A238D31D2E70BD00D080CD /* NSURLSessionConfiguration+PNConfiguration.h in Headers */, 79E20D2B1C8B0A70001BC9CC /* PNPresenceChannelGroupHereNowResult.h in Headers */, 793248611D874D9F00FBDF36 /* PNPublishSequence.h in Headers */, @@ -5267,6 +5315,7 @@ A55DAEFF24B1FE9E00766EE9 /* PNXML.h in Headers */, A55A87DF22FD8272002D0A72 /* PNBaseObjectsRequest.h in Headers */, A57A308C238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, + A5CE35642959C45B0038FD6F /* PNMessageType.h in Headers */, 79CBB11A1BD03DE4001FC34D /* PNConfiguration.h in Headers */, A57A30EC238DCAAF00DE8C68 /* PNAPNSNotificationTarget+Private.h in Headers */, A55A881E22FD8272002D0A72 /* PNFetchAllChannelsMetadataRequest.h in Headers */, @@ -5315,6 +5364,7 @@ A5A451A1246DE792008ECC74 /* PNRemoveMembershipsRequest.h in Headers */, A504E11F24AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.h in Headers */, A55A86BB22FD817E002D0A72 /* PNChannelMetadata.h in Headers */, + A5CE35762959D1E80038FD6F /* PNSpaceId.h in Headers */, 79CBB1631BD03DE4001FC34D /* PNErrorCodes.h in Headers */, A55A86C222FD817E002D0A72 /* PNUUIDMetadata+Private.h in Headers */, 79A0D8C11DC22FD60039A264 /* PNPresenceChannelHereNowAPICallBuilder.h in Headers */, @@ -5921,6 +5971,7 @@ 7925DB9C1D3FFCAC00857C0D /* PNLLogFileInformation.m in Sources */, 7915822C1BD709C60084FC70 /* PNClientInformation.m in Sources */, 793248651D874D9F00FBDF36 /* PNPublishSequence.m in Sources */, + A5CE35782959D1E80038FD6F /* PNSpaceId.m in Sources */, A504E12124AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.m in Sources */, 791582231BD709C60084FC70 /* PNRequestParameters.m in Sources */, 791582291BD709C60084FC70 /* PNSubscriberResults.m in Sources */, @@ -6064,6 +6115,7 @@ A56865702300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEF9233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D8651DC22C950039A264 /* PNSubscribeAPIBuilder.m in Sources */, + A5CE35662959C45B0038FD6F /* PNMessageType.m in Sources */, A5046F2424784CAB0008C81E /* PNObjectsRemoveParser.m in Sources */, A5046F1D24784CAB0008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046F0B24784CAB0008C81E /* PNMembership.m in Sources */, @@ -6151,6 +6203,7 @@ 791582C01BD709D10084FC70 /* PNPresenceWhereNowResult.m in Sources */, 791582F51BD709D10084FC70 /* PNPresenceHereNowParser.m in Sources */, 791582DA1BD709D10084FC70 /* PNMessagePublishParser.m in Sources */, + A5CE357A2959D1E80038FD6F /* PNSpaceId.m in Sources */, A504E12324AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.m in Sources */, 791582CA1BD709D10084FC70 /* PNAcknowledgmentStatus.m in Sources */, 79A0D9871DC2315D0039A264 /* PNTimeAPICallBuilder.m in Sources */, @@ -6294,6 +6347,7 @@ A56865722300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEFB233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D96D1DC2313A0039A264 /* PNSubscribeChannelsOrGroupsAPIBuilder.m in Sources */, + A5CE35682959C45B0038FD6F /* PNMessageType.m in Sources */, A5046EC624784CAA0008C81E /* PNObjectsRemoveParser.m in Sources */, A5046EBF24784CAA0008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046EAD24784CAA0008C81E /* PNMembership.m in Sources */, @@ -6381,6 +6435,7 @@ 7988426C1C18F1E3003E8948 /* PNPresenceWhereNowResult.m in Sources */, 798842BC1C18F2EA003E8948 /* PNPresenceHereNowParser.m in Sources */, 798842BB1C18F2EA003E8948 /* PNMessagePublishParser.m in Sources */, + A5CE357C2959D1E80038FD6F /* PNSpaceId.m in Sources */, A504E12524AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.m in Sources */, 798842601C18F1E3003E8948 /* PNAcknowledgmentStatus.m in Sources */, 79A0D98B1DC2315F0039A264 /* PNTimeAPICallBuilder.m in Sources */, @@ -6524,6 +6579,7 @@ A56865752300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEFE233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D96F1DC2313B0039A264 /* PNSubscribeChannelsOrGroupsAPIBuilder.m in Sources */, + A5CE356A2959C45B0038FD6F /* PNMessageType.m in Sources */, A5046E6824784CA90008C81E /* PNObjectsRemoveParser.m in Sources */, A5046E6124784CA90008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046E4F24784CA90008C81E /* PNMembership.m in Sources */, @@ -6611,6 +6667,7 @@ 79A8BC2C1C58F93900015BDE /* PNPresenceWhereNowResult.m in Sources */, 79A8BC621C58F93900015BDE /* PNPresenceHereNowParser.m in Sources */, 79A8BC461C58F93900015BDE /* PNMessagePublishParser.m in Sources */, + A5CE35792959D1E80038FD6F /* PNSpaceId.m in Sources */, A504E12224AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.m in Sources */, 79A8BC361C58F93900015BDE /* PNAcknowledgmentStatus.m in Sources */, 79A0D9861DC2315D0039A264 /* PNTimeAPICallBuilder.m in Sources */, @@ -6754,6 +6811,7 @@ A56865712300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEFA233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D96E1DC2313A0039A264 /* PNSubscribeChannelsOrGroupsAPIBuilder.m in Sources */, + A5CE35672959C45B0038FD6F /* PNMessageType.m in Sources */, A5046EF524784CAB0008C81E /* PNObjectsRemoveParser.m in Sources */, A5046EEE24784CAB0008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046EDC24784CAB0008C81E /* PNMembership.m in Sources */, @@ -6841,6 +6899,7 @@ 79CBB17B1BD03DE4001FC34D /* PNPresenceWhereNowParser.m in Sources */, 79CBB1791BD03DE4001FC34D /* PNPresenceHereNowParser.m in Sources */, 79CBB1771BD03DE4001FC34D /* PNMessagePublishParser.m in Sources */, + A5CE357B2959D1E80038FD6F /* PNSpaceId.m in Sources */, A504E12424AA8FBF006DCF5B /* PNGenerateFileUploadURLStatus.m in Sources */, 79CBB11D1BD03DE4001FC34D /* PNAcknowledgmentStatus.m in Sources */, 79A0D9881DC2315E0039A264 /* PNTimeAPICallBuilder.m in Sources */, @@ -6984,6 +7043,7 @@ A56865732300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEFC233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D9711DC2313C0039A264 /* PNSubscribeChannelsOrGroupsAPIBuilder.m in Sources */, + A5CE35692959C45B0038FD6F /* PNMessageType.m in Sources */, A5046E9724784CAA0008C81E /* PNObjectsRemoveParser.m in Sources */, A5046E9024784CAA0008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046E7E24784CAA0008C81E /* PNMembership.m in Sources */, diff --git a/Framework/PubNub/PubNub.h b/Framework/PubNub/PubNub.h index 0da8bdaa2..3f5960cd8 100644 --- a/Framework/PubNub/PubNub.h +++ b/Framework/PubNub/PubNub.h @@ -54,6 +54,10 @@ FOUNDATION_EXPORT const unsigned char PubNubVersionString[]; #import "PNResult.h" #import "PNStatus.h" +// Models +#import "PNMessageType.h" +#import "PNSpaceId.h" + // API #import "PubNub+Core.h" #import "PubNub+MessageActions.h" diff --git a/PubNub/Core/PubNub+Publish.h b/PubNub/Core/PubNub+Publish.h index e8c896b9e..b2db8a6f8 100644 --- a/PubNub/Core/PubNub+Publish.h +++ b/PubNub/Core/PubNub+Publish.h @@ -3,6 +3,9 @@ #import "PNPublishFileMessageRequest.h" #import "PNPublishRequest.h" +#import "PNMessageType.h" +#import "PNSpaceId.h" + #import "PNPublishFileMessageAPICallBuilder.h" #import "PNPublishSizeAPICallBuilder.h" #import "PNPublishAPICallBuilder.h" diff --git a/PubNub/Core/PubNub+Publish.m b/PubNub/Core/PubNub+Publish.m index 8c3f57353..ecbf6d734 100644 --- a/PubNub/Core/PubNub+Publish.m +++ b/PubNub/Core/PubNub+Publish.m @@ -1,8 +1,8 @@ /** * @author Serhii Mamontov - * @version 4.15.0 + * @version 5.2.0 * @since 4.0.0 - * @copyright © 2010-2020 PubNub, Inc. + * @copyright © 2010-2022 PubNub, Inc. */ #import "PubNub+Publish.h" #import "PNBasePublishRequest+Private.h" @@ -31,7 +31,9 @@ @interface PubNub (PublishProtected) * * @param message Object (\a NSString, \a NSNumber, \a NSArray, \a NSDictionary) which will be * published. + * @param type Type with which message should be published. * @param channel Name of the channel to which message should be published. + * @param spaceId Identifier of space to which message should be published. * @param payloads Dictionary with payloads for different vendors (Apple with "apns" key and Google * with "gcm"). * @param shouldStore Whether message should be stored and available with history API or not. @@ -49,7 +51,9 @@ @interface PubNub (PublishProtected) * @since 4.8.2 */ - (void)publish:(nullable id)message + withType:(nullable PNMessageType *)type toChannel:(NSString *)channel + spaceId:(nullable PNSpaceId *)spaceId mobilePushPayload:(nullable NSDictionary *)payloads storeInHistory:(BOOL)shouldStore ttl:(nullable NSNumber *)ttl @@ -70,7 +74,9 @@ - (void)publish:(nullable id)message * * @param message Object (\a NSString, \a NSNumber, \a NSArray, \a NSDictionary) which will be * sent with signal. + * @param messageType Type with which signal should be published. * @param channel Name of the channel to which signal should be sent. + * @param spaceId Identifier of space to which signal should be published. * @param queryParameters List arbitrary query parameters which should be sent along with original * API call. * @param block Signal completion block. @@ -78,7 +84,9 @@ - (void)publish:(nullable id)message * @since 4.9.0 */ - (void)signal:(id)message + withType:(nullable PNMessageType *)messageType channel:(NSString *)channel + spaceId:(nullable PNSpaceId *)spaceId withQueryParameters:(nullable NSDictionary *)queryParameters completion:(nullable PNSignalCompletionBlock)block; @@ -92,7 +100,9 @@ - (void)signal:(id)message * @note Size calculation use percent-escaped \c message and all added headers to get full size. * * @param message Message for which size should be calculated. + * @param type Type with which message should be published. * @param channel Name of the channel to which message should be published. + * @param spaceId Identifier of space to which message should be published. * @param compressMessage Whether message should be compressed before sending or not. * @param shouldStore Whether message should be stored and available with history API or not. * @param ttl How long message should be stored in channel's storage. If \b 0 it will be @@ -108,7 +118,9 @@ - (void)signal:(id)message * @since 4.8.2 */ - (void)sizeOfMessage:(id)message + withType:(nullable PNMessageType *)type toChannel:(NSString *)channel + spaceId:(nullable PNSpaceId *)spaceId compressed:(BOOL)compressMessage storeInHistory:(BOOL)shouldStore ttl:(nullable NSNumber *)ttl @@ -142,7 +154,9 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags * * @param message Object (\a NSString, \a NSNumber, \a NSArray, \a NSDictionary) which will be * published. + * @param type Type with which message should be published. * @param channel Name of the channel to which message should be published. + * @param spaceId Identifier of space to which message should be published. * @param compressMessage Whether message should be compressed before sending or not. * @param replicate Whether message should be replicated across the PubNub Real-Time Network and * sent simultaneously to all subscribed clients on a channel. @@ -160,7 +174,9 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags * @since 4.0 */ - (PNRequestParameters *)requestParametersForMessage:(NSString *)message + withType:(nullable PNMessageType *)type toChannel:(NSString *)channel + spaceId:(nullable PNSpaceId *)spaceId compressed:(BOOL)compressMessage storeInHistory:(BOOL)shouldStore ttl:(nullable NSNumber *)ttl @@ -256,12 +272,12 @@ @implementation PubNub (Publish) } - (PNPublishAPICallBuilder * (^)(void))publish { - PNPublishAPICallBuilder *builder = nil; __weak __typeof(self) weakSelf = self; + builder = [PNPublishAPICallBuilder builderWithExecutionBlock:^(NSArray *flags, NSDictionary *parameters) { - + NSString *channel = parameters[NSStringFromSelector(@selector(channel))]; NSNumber *shouldStore = parameters[NSStringFromSelector(@selector(shouldStore))]; NSNumber *ttl = parameters[NSStringFromSelector(@selector(ttl))]; @@ -273,9 +289,11 @@ @implementation PubNub (Publish) } PNPublishRequest *request = [PNPublishRequest requestWithChannel:channel]; + request.spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; request.metadata = parameters[NSStringFromSelector(@selector(metadata))]; request.payloads = parameters[NSStringFromSelector(@selector(payloads))]; request.message = parameters[NSStringFromSelector(@selector(message))]; + request.messageType = parameters[NSStringFromSelector(@selector(messageType))]; request.arbitraryQueryParameters = parameters[@"queryParam"]; request.store = (shouldStore ? shouldStore.boolValue : YES); request.replicate = (replicate ? replicate.boolValue : YES); @@ -291,9 +309,9 @@ @implementation PubNub (Publish) } - (PNPublishAPICallBuilder * (^)(void))fire { - PNPublishAPICallBuilder *builder = nil; __weak __typeof(self) weakSelf = self; + builder = [PNPublishAPICallBuilder builderWithExecutionBlock:^(NSArray *flags, NSDictionary *parameters) { @@ -309,18 +327,25 @@ @implementation PubNub (Publish) } - (PNSignalAPICallBuilder * (^)(void))signal { - PNSignalAPICallBuilder * builder = nil; __weak __typeof(self) weakSelf = self; + builder = [PNSignalAPICallBuilder builderWithExecutionBlock:^(NSArray *flags, NSDictionary *parameters) { id message = parameters[NSStringFromSelector(@selector(message))]; + PNMessageType *messageType = parameters[NSStringFromSelector(@selector(messageType))]; NSString *channel = parameters[NSStringFromSelector(@selector(channel))]; + PNSpaceId *spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; NSDictionary *queryParam = parameters[@"queryParam"]; id block = parameters[@"block"]; - [weakSelf signal:message channel:channel withQueryParameters:queryParam completion:block]; + [weakSelf signal:message + withType:messageType + channel:channel + spaceId:spaceId + withQueryParameters:queryParam + completion:block]; }]; return ^PNSignalAPICallBuilder * { @@ -329,13 +354,14 @@ @implementation PubNub (Publish) } - (PNPublishSizeAPICallBuilder * (^)(void))size { - PNPublishSizeAPICallBuilder *builder = nil; builder = [PNPublishSizeAPICallBuilder builderWithExecutionBlock:^(NSArray *flags, NSDictionary *parameters) { id message = parameters[NSStringFromSelector(@selector(message))]; + PNMessageType *messageType = parameters[NSStringFromSelector(@selector(messageType))]; NSString *channel = parameters[NSStringFromSelector(@selector(channel))]; + PNSpaceId *spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; NSNumber *shouldStore = parameters[NSStringFromSelector(@selector(shouldStore))]; NSNumber *ttl = parameters[NSStringFromSelector(@selector(ttl))]; NSNumber *compressed = parameters[NSStringFromSelector(@selector(compress))]; @@ -349,7 +375,9 @@ @implementation PubNub (Publish) } [self sizeOfMessage:message + withType:messageType toChannel:channel + spaceId:spaceId compressed:compressed.boolValue storeInHistory:(shouldStore ? shouldStore.boolValue : YES) ttl:ttl @@ -399,6 +427,7 @@ - (void)publishFileMessageWithRequest:(PNPublishFileMessageRequest *)request }]; } + #pragma mark - Publish with request - (void)publishWithRequest:(PNPublishRequest *)request completion:(PNPublishCompletionBlock)block { @@ -409,9 +438,13 @@ - (void)publishWithRequest:(PNPublishRequest *)request completion:(PNPublishComp request.useRandomInitializationVector = self.configuration.shouldUseRandomInitializationVector; request.cipherKey = self.configuration.cipherKey; - PNLogAPICall(self.logger, @" Publish%@ message to '%@' channel%@%@%@", + PNLogAPICall(self.logger, @" Publish%@ message%@ to '%@' channel%@%@%@%@", (request.shouldCompress ? @" compressed" : @""), + (request.messageType ? [NSString stringWithFormat:@" of '%@' type", + request.messageType.value] : @""), (request.channel ?: @""), + (request.spaceId ? [NSString stringWithFormat:@" (space id: %@)", + request.spaceId.value] : @""), (request.metadata ? [NSString stringWithFormat:@" with metadata (%@)", request.metadata] : @""), (!request.shouldStore ? @" which won't be saved in history" : @""), @@ -646,7 +679,9 @@ - (void)publish:(id)message completion:(PNPublishCompletionBlock)block { [self publish:message + withType:nil toChannel:channel + spaceId:nil mobilePushPayload:payloads storeInHistory:shouldStore ttl:nil @@ -658,7 +693,9 @@ - (void)publish:(id)message } - (void)publish:(id)message + withType:(PNMessageType *)messageType toChannel:(NSString *)channel + spaceId:(PNSpaceId *)spaceId mobilePushPayload:(NSDictionary *)payloads storeInHistory:(BOOL)shouldStore ttl:(NSNumber *)ttl @@ -669,6 +706,7 @@ - (void)publish:(id)message completion:(PNPublishCompletionBlock)block { PNPublishRequest *request = [PNPublishRequest requestWithChannel:channel]; + request.spaceId = spaceId; request.arbitraryQueryParameters = queryParameters; request.ttl = ttl.unsignedIntegerValue; request.replicate = replicate; @@ -677,6 +715,7 @@ - (void)publish:(id)message request.payloads = payloads; request.store = shouldStore; request.message = message; + request.messageType = messageType; [self publishWithRequest:request completion:block]; } @@ -688,11 +727,13 @@ - (void)signal:(id)message channel:(NSString *)channel withCompletion:(PNSignalCompletionBlock)block { - [self signal:message channel:channel withQueryParameters:nil completion:block]; + [self signal:message withType:nil channel:channel spaceId:nil withQueryParameters:nil completion:block]; } - (void)signal:(id)message + withType:(PNMessageType *)messageType channel:(NSString *)channel + spaceId:(PNSpaceId *)spaceId withQueryParameters:(NSDictionary *)queryParameters completion:(PNSignalCompletionBlock)block { @@ -717,6 +758,10 @@ - (void)signal:(id)message forPlaceholder:@"{channel}"]; } + if (spaceId) { + [parameters addQueryParameter:spaceId.value forFieldName:@"space-id"]; + } + if (([messageForSignal isKindOfClass:[NSString class]] && messageForSignal.length) || messageForSignal) { @@ -724,6 +769,10 @@ - (void)signal:(id)message forPlaceholder:@"{message}"]; } + if (messageType) { + [parameters addQueryParameter:messageType.value forFieldName:@"type"]; + } + PNLogAPICall(strongSelf.logger, @" Signal to '%@' channel.", (channel ?: @"")); @@ -735,7 +784,9 @@ - (void)signal:(id)message if (status.isError) { status.retryBlock = ^{ [weakSelf signal:message + withType:messageType channel:channel + spaceId:spaceId withQueryParameters:queryParameters completion:block]; }; @@ -842,7 +893,9 @@ - (void)sizeOfMessage:(id)message completion:(PNMessageSizeCalculationCompletionBlock)block { [self sizeOfMessage:message + withType:nil toChannel:channel + spaceId:nil compressed:compressMessage storeInHistory:shouldStore ttl:nil @@ -853,7 +906,9 @@ - (void)sizeOfMessage:(id)message } - (void)sizeOfMessage:(id)message + withType:(PNMessageType *)messageType toChannel:(NSString *)channel + spaceId:(PNSpaceId *)spaceId compressed:(BOOL)compressMessage storeInHistory:(BOOL)shouldStore ttl:(NSNumber *)ttl @@ -899,7 +954,9 @@ - (void)sizeOfMessage:(id)message } PNRequestParameters *parameters = [self requestParametersForMessage:messageForPublish + withType:messageType toChannel:channel + spaceId:spaceId compressed:compressMessage storeInHistory:shouldStore ttl:ttl @@ -932,7 +989,9 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags parameters:(NSDictionary *)parameters { id message = parameters[NSStringFromSelector(@selector(message))]; + PNMessageType *messageType = parameters[NSStringFromSelector(@selector(messageType))]; NSString *channel = parameters[NSStringFromSelector(@selector(channel))]; + PNSpaceId *spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; NSDictionary *payloads = parameters[NSStringFromSelector(@selector(payloads))]; NSNumber *shouldStore = parameters[NSStringFromSelector(@selector(shouldStore))]; NSNumber *ttl = parameters[NSStringFromSelector(@selector(ttl))]; @@ -942,7 +1001,9 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags NSDictionary *metadata = parameters[NSStringFromSelector(@selector(metadata))]; [self publish:message + withType:messageType toChannel:channel + spaceId:spaceId mobilePushPayload:payloads storeInHistory:(shouldStore ? shouldStore.boolValue : YES) ttl:ttl @@ -957,7 +1018,9 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags #pragma mark - Misc - (PNRequestParameters *)requestParametersForMessage:(NSString *)message + withType:(PNMessageType *)messageType toChannel:(NSString *)channel + spaceId:(PNSpaceId *)spaceId compressed:(BOOL)compressMessage storeInHistory:(BOOL)shouldStore ttl:(NSNumber *)ttl @@ -974,6 +1037,10 @@ - (PNRequestParameters *)requestParametersForMessage:(NSString *)message [parameters addPathComponent:[PNString percentEscapedString:channel] forPlaceholder:@"{channel}"]; } + + if (spaceId) { + [parameters addQueryParameter:spaceId.value forFieldName:@"space-id"]; + } if (!shouldStore) { [parameters addQueryParameter:@"0" forFieldName:@"store"]; @@ -992,6 +1059,10 @@ - (PNRequestParameters *)requestParametersForMessage:(NSString *)message [parameters addPathComponent:targetMessage forPlaceholder:@"{message}"]; } + if (messageType) { + [parameters addQueryParameter:messageType.value forFieldName:@"type"]; + } + if ([metadata isKindOfClass:[NSString class]] && metadata.length) { [parameters addQueryParameter:[PNString percentEscapedString:metadata] forFieldName:@"meta"]; diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h b/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h index 84c8c68ab..c4ac94744 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h @@ -2,12 +2,20 @@ #import "PNStructures.h" +#pragma mark Class forward + +@class PNMessageType, PNSpaceId; + + NS_ASSUME_NONNULL_BEGIN +#pragma mark - Interface declaration + /** * @brief Publish API call builder. * * @author Serhii Mamontov + * @version 5.2.0 * @since 4.5.4 * @copyright © 2010-2018 PubNub, Inc. */ @@ -27,6 +35,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNPublishAPICallBuilder * (^channel)(NSString *channel); +/** + * @brief Target space identifier name. + * + * @param spaceId Identifier of the space to which message should be published. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNPublishAPICallBuilder * (^spaceId)(PNSpaceId *spaceId); + /** * @brief Message payload addition block. * @@ -42,6 +61,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNPublishAPICallBuilder * (^message)(id message); +/** + * @brief Type of message which will be published. + * + * @param type Custom type for published message. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNPublishAPICallBuilder * (^messageType)(PNMessageType *type); + /** * @brief Message metadata addition block. * diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m b/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m index 6b2ac4781..09d4beaa2 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m @@ -1,5 +1,6 @@ /** * @author Serhii Mamontov + * @version 5.2.0 * @since 4.5.4 * @copyright © 2010-2018 PubNub, Inc. */ @@ -20,23 +21,34 @@ @implementation PNPublishAPICallBuilder #pragma mark - Configuration - (PNPublishAPICallBuilder * (^)(NSString *channel))channel { - return ^PNPublishAPICallBuilder * (NSString *channel) { [self setValue:channel forParameter:NSStringFromSelector(_cmd)]; return self; }; } +- (PNPublishAPICallBuilder * (^)(PNSpaceId *spaceId))spaceId { + return ^PNPublishAPICallBuilder * (PNSpaceId *spaceId) { + [self setValue:spaceId forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNPublishAPICallBuilder * (^)(id message))message { - return ^PNPublishAPICallBuilder * (id message) { [self setValue:message forParameter:NSStringFromSelector(_cmd)]; return self; }; } +- (PNPublishAPICallBuilder * (^)(PNMessageType *messageType))messageType { + return ^PNPublishAPICallBuilder * (PNMessageType *messageType) { + [self setValue:messageType forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNPublishAPICallBuilder * (^)(NSDictionary *metadata))metadata { - return ^PNPublishAPICallBuilder * (NSDictionary *metadata) { [self setValue:metadata forParameter:NSStringFromSelector(_cmd)]; return self; @@ -44,7 +56,6 @@ @implementation PNPublishAPICallBuilder } - (PNPublishAPICallBuilder * (^)(BOOL shouldStore))shouldStore { - return ^PNPublishAPICallBuilder * (BOOL shouldStore) { [self setValue:@(shouldStore) forParameter:NSStringFromSelector(_cmd)]; return self; @@ -52,7 +63,6 @@ @implementation PNPublishAPICallBuilder } - (PNPublishAPICallBuilder * (^)(NSUInteger ttl))ttl { - return ^PNPublishAPICallBuilder * (NSUInteger ttl) { [self setValue:@(ttl) forParameter:NSStringFromSelector(_cmd)]; return self; @@ -60,7 +70,6 @@ @implementation PNPublishAPICallBuilder } - (PNPublishAPICallBuilder * (^)(BOOL compress))compress { - return ^PNPublishAPICallBuilder * (BOOL compress) { [self setValue:@(compress) forParameter:NSStringFromSelector(_cmd)]; return self; @@ -68,7 +77,6 @@ @implementation PNPublishAPICallBuilder } - (PNPublishAPICallBuilder * (^)(BOOL))replicate { - return ^PNPublishAPICallBuilder * (BOOL replicate) { [self setValue:@(replicate) forParameter:NSStringFromSelector(_cmd)]; return self; @@ -76,7 +84,6 @@ @implementation PNPublishAPICallBuilder } - (PNPublishAPICallBuilder * (^)(NSDictionary *payload))payloads { - return ^PNPublishAPICallBuilder * (NSDictionary *payload) { [self setValue:payload forParameter:NSStringFromSelector(_cmd)]; return self; @@ -87,7 +94,6 @@ @implementation PNPublishAPICallBuilder #pragma mark - Execution - (void(^)(PNPublishCompletionBlock block))performWithCompletion { - return ^(PNPublishCompletionBlock block) { [super performWithBlock:block]; }; diff --git a/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h b/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h index 33c7ad00a..b6771f736 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h @@ -2,13 +2,19 @@ #import "PNStructures.h" +#pragma mark Class forward + +@class PNMessageType, PNSpaceId; + NS_ASSUME_NONNULL_BEGIN +#pragma mark - Interface declaration + /** * @brief Signal API call builder. * * @author Serhii Mamontov - * @version 4.9.0 + * @version 5.2.0 * @since 4.9.0 * @copyright © 2010-2019 PubNub, Inc. */ @@ -26,6 +32,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNSignalAPICallBuilder * (^channel)(NSString *channel); +/** + * @brief Target space identifier name. + * + * @param spaceId Identifier of the space to which signal should be published. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNSignalAPICallBuilder * (^spaceId)(PNSpaceId *spaceId); + /** * @brief Signal payload addition block. * @@ -39,6 +56,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNSignalAPICallBuilder * (^message)(id message); +/** + * @brief Type of signal which will be published. + * + * @param type Custom type for published signal. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNSignalAPICallBuilder * (^messageType)(PNMessageType *type); + #pragma mark - Execution diff --git a/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m b/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m index 51979910f..2874d26e5 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m @@ -21,7 +21,6 @@ @implementation PNSignalAPICallBuilder #pragma mark - Configuration - (PNSignalAPICallBuilder * (^)(NSString *channel))channel { - return ^PNSignalAPICallBuilder * (NSString *channel) { if ([channel isKindOfClass:[NSString class]]) { [self setValue:channel forParameter:NSStringFromSelector(_cmd)]; @@ -31,14 +30,27 @@ @implementation PNSignalAPICallBuilder }; } +- (PNSignalAPICallBuilder * (^)(PNSpaceId *spaceId))spaceId { + return ^PNSignalAPICallBuilder * (PNSpaceId *spaceId) { + [self setValue:spaceId forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNSignalAPICallBuilder * (^)(id message))message { - return ^PNSignalAPICallBuilder * (id message) { [self setValue:message forParameter:NSStringFromSelector(_cmd)]; return self; }; } +- (PNSignalAPICallBuilder * (^)(PNMessageType * messageType))messageType { + return ^PNSignalAPICallBuilder * (PNMessageType *messageType) { + [self setValue:messageType forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + #pragma mark - Execution diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index 330e60cda..13e78262c 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -1532,7 +1532,7 @@ - (void)handleLiveFeedEvents:(PNSubscribeStatus *)status forInitialSubscription: [self handleNewPresenceEvent:((PNPresenceEventResult *)eventResultObject)]; } else { PNEnvelopeInformation *envelope = event[@"envelope"]; - PNMessageType messageType = envelope.messageType; + PNServiceMessageType messageType = envelope.pubNubMessageType; if (messageType == PNObjectMessageType) { [self handleNewObjectsEvent:eventResultObject]; @@ -1741,7 +1741,7 @@ - (void)deDuplicateMessages:(NSMutableArray *)events { NSMutableIndexSet *duplicateMessagesIndices = [NSMutableIndexSet indexSet]; [events enumerateObjectsUsingBlock:^(NSDictionary *event, NSUInteger eventIdx, BOOL *eventsEnumeratorStop) { - PNMessageType messageType = ((PNEnvelopeInformation *)event[@"envelope"]).messageType; + PNServiceMessageType messageType = ((PNEnvelopeInformation *)event[@"envelope"]).pubNubMessageType; BOOL isMessageEvent = (messageType != PNFileMessageType && messageType != PNObjectMessageType && messageType != PNMessageActionType); diff --git a/PubNub/Data/Models/PNMessageType+Private.h b/PubNub/Data/Models/PNMessageType+Private.h new file mode 100644 index 000000000..6c63d9fe2 --- /dev/null +++ b/PubNub/Data/Models/PNMessageType+Private.h @@ -0,0 +1,38 @@ +#import "PNMessageType.h" +#import "PNPrivateStructures.h" + + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark Interface extension declaration + +/** + * @brief Extension for public interface for parsers support. + * + * @author Serhii Mamontov + * @version 5.2.0 + * @since 5.2.0 + * @copyright © 2010-2022 PubNub Inc. All Rights Reserved. + */ +@interface PNMessageType (Private) + + +#pragma mark - Initialization and configuration + +/** + * @brief Create and configure message type based on type provided by \b PubNub and user. + * + * @param userMessageType Custom message type which should be used when publish message. + * @param pubNubMessageType One of pre-defined message / event types. + * + * @return Configured and ready to use message type instance. + */ ++ (instancetype)messageTypeFromString:(NSString *)userMessageType + pubNubMessageType:(PNServiceMessageType)pubNubMessageType; + +#pragma mark - + + +@end + +NS_ASSUME_NONNULL_END diff --git a/PubNub/Data/Models/PNMessageType.h b/PubNub/Data/Models/PNMessageType.h new file mode 100644 index 000000000..e18f830fa --- /dev/null +++ b/PubNub/Data/Models/PNMessageType.h @@ -0,0 +1,76 @@ +#import + + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark Interface declaration + +/** + * @brief Published message representation model. + * + * @discussion This type let identify message received from subscriber later. + * There is five types which is set by \b PubNub service depending from used API endpoint: + * - \c message + * - \c signal + * - \c object + * - \c messageAction + * - \c file + * + * Additionally it is possible to specify custom type for published message using \b PNMessageType method + * + * @author Serhii Mamontov + * @version 5.2.0 + * @since 5.2.0 + * @copyright © 2010-2022 PubNub Inc. All Rights Reserved. + */ +@interface PNMessageType : NSObject + + +#pragma mark - Information + +/** + * @brief One of types associated with message when it has been published. + * + * @discussion This property may store \b PubNub defined types (like: message, signal, file, object, messageAction + */ +@property(nonatomic, readonly, copy) NSString *value; + + +#pragma mark - Initialization and configuration + +/** + * @brief Create and configure message type instance. + * + * @param type Custom message type which should be used when publish message. + * + * @return Configured and ready to use message type instance. + */ ++ (instancetype)messageTypeFromString:(NSString *)type; + +/** + * @brief Initialize message type instance. + * + * @note This method can't be used directly and will throw an exception. + * + * @return Message type instance. + */ +- (nullable instancetype)init NS_UNAVAILABLE; + + +#pragma mark - Helper + +/** + * @brief Check whether receiving message type is equal to another instance. + * + * @param otherMessageType Second instance against which check should be done. + * + * @return \c YES if \c otherMessageType is equal to receiver. + */ +- (BOOL)isEqualToMessageType:(PNMessageType *)otherMessageType; + +#pragma mark - + + +@end + +NS_ASSUME_NONNULL_END diff --git a/PubNub/Data/Models/PNMessageType.m b/PubNub/Data/Models/PNMessageType.m new file mode 100644 index 000000000..22989b797 --- /dev/null +++ b/PubNub/Data/Models/PNMessageType.m @@ -0,0 +1,119 @@ +/** + * @author Serhii Mamontov + * @version 5.2.0 + * @since 5.2.0 + * @copyright © 2010-2022 PubNub Inc. All Rights Reserved. + */ +#import "PNMessageType+Private.h" + + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark Protected interface declaration + +@interface PNMessageType () + +/** + * @brief One of types associated with message when it has been published. + * + * @discussion This property may store \b PubNub defined types (like: message, signal, file, object, messageAction + */ +@property(nonatomic, copy) NSString *value; + + +#pragma mark - Initialization and configuration + +/** + * @brief Create and configure instance from actual value. + * + * @param value Custom user type of stringified \b PubNub provided type. + */ +- (instancetype)initWithValueFromString:(NSString *)value NS_DESIGNATED_INITIALIZER; + + +#pragma mark - Helper + +/** + * @brief Transform provided data to string. + * + * @param userType User-provided type which should be used for message type. + * @param pnType \b PubNub provided message type which should be stringified. + * + * @return Proper message type which will be used by user and publish endpoints. + */ ++ (NSString *)valueFromUserType:(nullable NSString *)userType + pubNubMessageType:(PNServiceMessageType)pnType; + +#pragma mark - + + +@end + +NS_ASSUME_NONNULL_END + + +#pragma mark - Interface implementation + +@implementation PNMessageType + + +#pragma mark - Initialization and configuration + ++ (instancetype)messageTypeFromString:(NSString *)type { + return [self messageTypeFromString:type pubNubMessageType:PNRegularMessageType]; +} + ++ (instancetype)messageTypeFromString:(NSString *)userType pubNubMessageType:(PNServiceMessageType)pnType { + return [[self alloc] initWithValueFromString:[self valueFromUserType:userType pubNubMessageType:pnType]]; +} + +- (instancetype)init { + NSDictionary *errorInformation = @{ NSLocalizedRecoverySuggestionErrorKey: @"Use provided constructor" }; + @throw [NSException exceptionWithName:@"PNInterfaceNotAvailable" + reason:@"+new or -init methods unavailable." + userInfo:errorInformation]; + + return nil; +} + +- (instancetype)initWithValueFromString:(NSString *)value { + if ((self = [super init])) { + _value = [value copy]; + } + + return self; +} + + +#pragma mark - NSCopying + +- (id)copyWithZone:(NSZone *)zone { + return [[PNMessageType alloc] initWithValueFromString:self.value]; +} + + +#pragma mark - Helper + +- (BOOL)isEqual:(id)other { + return other && [other isKindOfClass:[self class]] ? [self isEqualToMessageType:other] : NO; +} + +- (BOOL)isEqualToMessageType:(PNMessageType *)otherMessageType { + return [self.value isEqualToString:otherMessageType.value]; +} + ++ (NSString *)valueFromUserType:(NSString *)userMessageType pubNubMessageType:(PNServiceMessageType)pubNubMessageType { + static NSArray *_pubNubMessageTypeMap; + static dispatch_once_t onceToken; + + dispatch_once(&onceToken, ^{ + _pubNubMessageTypeMap = @[@"message", @"signal", @"object", @"messageAction", @"file"]; + }); + + return userMessageType ? userMessageType : _pubNubMessageTypeMap[pubNubMessageType]; +} + +#pragma mark - + + +@end diff --git a/PubNub/Data/Models/PNSpaceId.h b/PubNub/Data/Models/PNSpaceId.h new file mode 100644 index 000000000..b89ae9a37 --- /dev/null +++ b/PubNub/Data/Models/PNSpaceId.h @@ -0,0 +1,64 @@ +#import + + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark Interface declaration + +/** + * @brief Model which represent space into which message should be / has been published. + * + * @author Serhii Mamontov + * @version 5.2.0 + * @since 5.2.0 + * @copyright © 2010-2022 PubNub Inc. All Rights Reserved. + */ +@interface PNSpaceId : NSObject + + +#pragma mark - Information + +/** + * @brief Space into which message should be / has been published + */ +@property(nonatomic, readonly, copy) NSString *value; + + +#pragma mark - Initialization and configuration + +/** + * @brief Create and configure space id instance. + * + * @param identifier Space id identifier. + * + * @return Configured and ready to use space id instance. + */ ++ (instancetype)spaceIdFromString:(NSString *)identifier; + +/** + * @brief Initialize space id instance. + * + * @note This method can't be used directly and will throw an exception. + * + * @return Space id instance. + */ +- (nullable instancetype)init NS_UNAVAILABLE; + + +#pragma mark - Helper + +/** + * @brief Check whether receiving space id is equal to another instance. + * + * @param otherSpaceId Second instance against which check should be done. + * + * @return \c YES if \c otherSpaceId is equal to receiver. + */ +- (BOOL)isEqualToSpaceId:(PNSpaceId *)otherSpaceId; + +#pragma mark - + + +@end + +NS_ASSUME_NONNULL_END diff --git a/PubNub/Data/Models/PNSpaceId.m b/PubNub/Data/Models/PNSpaceId.m new file mode 100644 index 000000000..52e26f85e --- /dev/null +++ b/PubNub/Data/Models/PNSpaceId.m @@ -0,0 +1,81 @@ +/** + * @author Serhii Mamontov + * @version 5.2.0 + * @since 5.2.0 + * @copyright © 2010-2022 PubNub Inc. All Rights Reserved. + */ +#import "PNSpaceId.h" + + +NS_ASSUME_NONNULL_BEGIN + +#pragma mark Protected interface declaration + +@interface PNSpaceId () + +/** + * @brief Space into which message should be / has been published + */ +@property(nonatomic, copy) NSString *value; + + +#pragma mark - Initialization and configuration + +/** + * @brief Initialize space id instance. + * + * @param identifier Space id identifier. + * + * @return Initialized and ready to use space id instance. + */ +- (instancetype)initFromString:(NSString *)identifier NS_DESIGNATED_INITIALIZER; + +#pragma mark - + + +@end + +NS_ASSUME_NONNULL_END + + +#pragma mark - Interface implementation + +@implementation PNSpaceId + + +#pragma mark - Initialization and configuration + ++ (instancetype)spaceIdFromString:(NSString *)identifier { + return [[self alloc] initFromString:identifier]; +} + +- (instancetype)initFromString:(NSString *)identifier { + if ((self = [super init])) { + _value = [identifier copy]; + } + + return self; +} + + +#pragma mark - NSCopying + +- (id)copyWithZone:(NSZone *)zone { + return [[PNSpaceId alloc] initFromString:self.value]; +} + + +#pragma mark - Helper + +- (BOOL)isEqual:(id)other { + return other && [other isKindOfClass:[self class]] ? [self isEqualToSpaceId:other] : NO; +} + +- (BOOL)isEqualToSpaceId:(PNSpaceId *)otherSpaceId { + return [self.value isEqualToString:otherSpaceId.value]; +} + +#pragma mark - + + +@end diff --git a/PubNub/Data/PNEnvelopeInformation.h b/PubNub/Data/PNEnvelopeInformation.h index ce2d53852..d01ae5d00 100644 --- a/PubNub/Data/PNEnvelopeInformation.h +++ b/PubNub/Data/PNEnvelopeInformation.h @@ -2,6 +2,11 @@ #import "PNPrivateStructures.h" +#pragma mark Class forward + +@class PNMessageType, PNSpaceId; + + /** * @brief Class describe real-time event envelope information. * @@ -43,10 +48,24 @@ */ @property (nonatomic, nullable, readonly, copy) NSString *subscribeKey; +/** + * @brief \b PubNub defined object type. + * + * @since 5.2.0 + */ +@property (atomic, readonly, assign) PNServiceMessageType pubNubMessageType; + /** * @brief Object's message type. + * + * @since 5.2.0 + */ +@property (nonatomic, nullable, readonly, strong) PNMessageType *messageType; + +/** + * @brief Identifier of space from which message has been received. */ -@property (nonatomic, readonly, assign) PNMessageType messageType; +@property (nonatomic, nullable, readonly, copy) PNSpaceId *spaceId; /** * @brief Event replication map (region based). diff --git a/PubNub/Data/PNEnvelopeInformation.m b/PubNub/Data/PNEnvelopeInformation.m index 24013b05d..79b50e61f 100644 --- a/PubNub/Data/PNEnvelopeInformation.m +++ b/PubNub/Data/PNEnvelopeInformation.m @@ -5,6 +5,8 @@ @copyright © 2010-2019 PubNub Inc. */ #import "PNEnvelopeInformation.h" +#import "PNMessageType+Private.h" +#import "PNSpaceId.h" #import "PNJSON.h" @@ -41,9 +43,19 @@ __unsafe_unretained NSString *subscribeKey; /** - * @brief Key under which stored object's message type. + * @brief Key under which stored \b PubNub defined object's message type. */ - __unsafe_unretained NSString *messageTypeKey; + __unsafe_unretained NSString *pubNubMessageTypeKey; + + /** + * @brief Key under which stored user-defined object's message type. + */ + __unsafe_unretained NSString *userMessageTypeKey; + + /** + * @brief Key under which stored identifier of space to which object has been sent. + */ + __unsafe_unretained NSString *spaceIdKey; /** * @brief Key under which stored numeric representation of event replication map (region based). @@ -72,7 +84,8 @@ .senderIdentifier = @"i", .sequenceNumber = @"s", .subscribeKey = @"k", - .messageTypeKey = @"e", + .pubNubMessageTypeKey = @"e", + .userMessageTypeKey = @"mt", .replicationMap = @"r", .eatAfterReading = @"ear", .metadata = @"u", @@ -94,7 +107,9 @@ @interface PNEnvelopeInformation () @property (nonatomic, copy) NSString *senderIdentifier; @property (nonatomic, copy) NSNumber *sequenceNumber; @property (nonatomic, copy) NSString *subscribeKey; -@property (nonatomic, assign) PNMessageType messageType; +@property (atomic, assign) PNServiceMessageType pubNubMessageType; +@property (nonatomic, nullable, strong) PNMessageType *messageType; +@property (nonatomic, nullable, copy) PNSpaceId *spaceId; @property (nonatomic, copy) NSNumber *replicationMap; @property (nonatomic, copy) NSNumber *eatAfterReading; @property (nonatomic, copy) NSDictionary *metadata; @@ -128,25 +143,29 @@ @implementation PNEnvelopeInformation #pragma mark - Initialization and Configuration + (nonnull instancetype)envelopeInformationWithPayload:(nonnull NSDictionary *)payload { - return [[self alloc] initWithPayload:payload]; } - (nonnull instancetype)initWithPayload:(nonnull NSDictionary *)payload { - - // Check whether initialization was successful or not. if ((self = [super init])) { - _shardIdentifier = [payload[PNDebugEventEnvelope.shardIdentifier] copy]; _debugFlags = [payload[PNDebugEventEnvelope.debugFlags] copy]; _senderIdentifier = [payload[PNDebugEventEnvelope.senderIdentifier] copy]; _sequenceNumber = [payload[PNDebugEventEnvelope.sequenceNumber] copy]; _subscribeKey = [payload[PNDebugEventEnvelope.subscribeKey] copy]; - _messageType = ((NSNumber *)payload[PNDebugEventEnvelope.messageTypeKey]).unsignedIntegerValue; _replicationMap = [payload[PNDebugEventEnvelope.replicationMap] copy]; _eatAfterReading = payload[PNDebugEventEnvelope.eatAfterReading]; _metadata = [payload[PNDebugEventEnvelope.metadata] copy]; _waypoints = [payload[PNDebugEventEnvelope.waypoints] copy]; + + _pubNubMessageType = ((NSNumber *)payload[PNDebugEventEnvelope.pubNubMessageTypeKey]).unsignedIntegerValue; + NSString *userMessageType = payload[PNDebugEventEnvelope.userMessageTypeKey]; + _messageType = [PNMessageType messageTypeFromString:userMessageType pubNubMessageType:_pubNubMessageType]; + + NSString *spaceId = payload[PNDebugEventEnvelope.spaceIdKey]; + if (spaceId) { + _spaceId = [PNSpaceId spaceIdFromString:spaceId]; + } } return self; @@ -161,13 +180,12 @@ - (BOOL)shouldEatAfterReading { #pragma mark - Misc - (NSDictionary *)dictionaryRepresentation { - return @{@"Shard identifier": (self.shardIdentifier?: @""), @"Flags": (self.debugFlags?: @""), @"Client Identifier": (self.senderIdentifier?: @""), @"Sequence number": (self.sequenceNumber?: @""), @"Subscribe key": (self.subscribeKey?: @""), - @"Message type": @(self.messageType), + @"Message type": (self.messageType.value ?: @(self.pubNubMessageType)), @"Replication map": (self.replicationMap?: @""), @"Eat after reading": (self.eatAfterReading ? (self.shouldEatAfterReading ? @"YES" : @"NO") : @""), @"Metadata": (self.metadata ? [PNJSON JSONStringFrom:self.metadata withError:nil] : @""), @@ -175,12 +193,10 @@ - (NSDictionary *)dictionaryRepresentation { } - (NSString *)stringifiedRepresentation { - return [PNJSON JSONStringFrom:[self dictionaryRepresentation] withError:NULL]; } - (NSString *)debugDescription { - return [[self dictionaryRepresentation] description]; } diff --git a/PubNub/Data/Service Objects/PNSubscribeStatus.h b/PubNub/Data/Service Objects/PNSubscribeStatus.h index af092a18c..754c04202 100644 --- a/PubNub/Data/Service Objects/PNSubscribeStatus.h +++ b/PubNub/Data/Service Objects/PNSubscribeStatus.h @@ -2,47 +2,65 @@ #import "PNServiceData.h" +#pragma mark Class forward + +@class PNMessageType, PNSpaceId; + + NS_ASSUME_NONNULL_BEGIN +#pragma mark - Interface declaration + /** - @brief Base class which allow to get access to general information about subscribe loop. - - @author Sergey Mamontov - @since 4.0 - @copyright © 2010-2018 PubNub, Inc. + * @brief Base class which allow to get access to general information about subscribe loop. + * + * @author Serhii Mamontov + * @version 5.2.0 + * @since 4.0.0 + * @copyright © 2010-2022 PubNub, Inc. */ @interface PNSubscriberData : PNServiceData -///------------------------------------------------ -/// @name Information -///------------------------------------------------ +#pragma mark - Information /** - @brief Name of channel for which subscriber received data. - - @since 4.5.2 + * @brief Name of channel for which subscriber received data. + * + * @since 4.5.2 */ @property (nonatomic, readonly, strong) NSString *channel; /** - @brief Name of \c channel or channel \c group (in case if not equal to \c channel). - - @since 4.5.2 + * @brief Identifier to which message originally has been published. + * + * @since 5.2.0 + */ +@property (nonatomic, nullable, readonly, strong) PNSpaceId *spaceId; + +/** + * @brief Name of \c channel or channel \c group (in case if not equal to \c channel). + * + * @since 4.5.2 */ @property (nonatomic, nullable, readonly, strong) NSString *subscription; /** - @brief Time at which event arrived. - - @since 4.0 + * @brief Time at which event arrived. */ @property (nonatomic, readonly, strong) NSNumber *timetoken; /** - @brief Stores reference on metadata information which has been passed along with received event. - - @since 4.3.0 + * @brief Type of message which has been published. + * + * @since 5.2.0 + */ +@property (nonatomic, nullable, readonly, strong) PNMessageType *messageType; + +/** + * @brief Stores reference on metadata information which has been passed along with received event. + * + * @since 4.3.0 */ @property (nonatomic, nullable, readonly, strong) NSDictionary *userMetadata; @@ -53,52 +71,40 @@ NS_ASSUME_NONNULL_BEGIN /** - @brief Class which is used to provide access to request processing results. - - @author Sergey Mamontov - @since 4.0 - @copyright © 2010-2018 PubNub, Inc. + * @brief Class which is used to provide access to request processing results. + * + * @author Serhii Mamontov + * @since 4.0 + * @copyright © 2010-2018 PubNub, Inc. */ @interface PNSubscribeStatus : PNErrorStatus -///------------------------------------------------ -/// @name Information -///------------------------------------------------ +#pragma mark - Information /** - @brief Time token which has been used to establish current subscription cycle. - - @since 4.0 + * @brief Time token which has been used to establish current subscription cycle. */ @property (nonatomic, readonly, strong) NSNumber *currentTimetoken; /** - @brief Stores reference on previous key which has been used in subscription cycle to receive - \c currentTimetoken along with other events. - - @since 4.0 + * @brief Stores reference on previous key which has been used in subscription cycle to receive + * \c currentTimetoken along with other events. */ @property (nonatomic, readonly, strong) NSNumber *lastTimeToken; /** - @brief List of channels on which client currently subscribed. - - @since 4.0 + * @brief List of channels on which client currently subscribed. */ @property (nonatomic, readonly, copy) NSArray *subscribedChannels; /** - @brief List of channel group names on which client currently subscribed. - - @since 4.0 + * @brief List of channel group names on which client currently subscribed. */ @property (nonatomic, readonly, copy) NSArray *subscribedChannelGroups; /** - @brief Structured \b PNResult \c data field information. - - @since 4.0 + * @brief Structured \b PNResult \c data field information. */ @property (nonatomic, readonly, strong) PNSubscriberData *data; diff --git a/PubNub/Data/Service Objects/PNSubscribeStatus.m b/PubNub/Data/Service Objects/PNSubscribeStatus.m index 86e98f56b..012dece3c 100644 --- a/PubNub/Data/Service Objects/PNSubscribeStatus.m +++ b/PubNub/Data/Service Objects/PNSubscribeStatus.m @@ -1,12 +1,14 @@ /** - @author Sergey Mamontov - @since 4.0 - @copyright © 2010-2018 PubNub, Inc. + * @author Serhii Mamontov + * @version 5.2.0 + * @since 4.0.0 + * @copyright © 2010-2022 PubNub, Inc. */ #import "PNSubscribeStatus+Private.h" #import "PNEnvelopeInformation.h" #import "PNServiceData+Private.h" #import "PNResult+Private.h" +#import "PNSpaceId.h" #pragma mark Interface implementation @@ -17,32 +19,34 @@ @implementation PNSubscriberData #pragma mark - Information - (NSString *)channel { - return self.serviceData[@"channel"]; } +- (PNSpaceId *)spaceId { + return self.envelope.spaceId; +} + +- (PNMessageType *)messageType { + return self.envelope.messageType; +} + - (NSString *)subscription { - return self.serviceData[@"subscription"]; } - (NSNumber *)timetoken { - return (self.serviceData[@"timetoken"]?: @0); } - (NSNumber *)region { - return (self.serviceData[@"region"]?: @0); } - (NSDictionary *)userMetadata { - return self.envelope.metadata; } - (PNEnvelopeInformation *)envelope { - return self.serviceData[@"envelope"]; } diff --git a/PubNub/Misc/PNPrivateStructures.h b/PubNub/Misc/PNPrivateStructures.h index 77e63ac16..d00790a52 100644 --- a/PubNub/Misc/PNPrivateStructures.h +++ b/PubNub/Misc/PNPrivateStructures.h @@ -29,11 +29,12 @@ extern NSString * const kPNPublishSequenceDataKey; extern NSString * const kPNConfigurationUUIDKey; /** - * @brief Options describe object's message type. + * @brief \b PubNub provided service message types. * - * @since 4.9.0 + * @version 5.2.0 + * @since 5.2.0 */ -typedef NS_OPTIONS(NSUInteger, PNMessageType) { +typedef NS_OPTIONS(NSUInteger, PNServiceMessageType) { /** @brief Type which represent regular message object. */ diff --git a/PubNub/Network/Parsers/PNHistoryParser.m b/PubNub/Network/Parsers/PNHistoryParser.m index b28f91418..de228dea6 100644 --- a/PubNub/Network/Parsers/PNHistoryParser.m +++ b/PubNub/Network/Parsers/PNHistoryParser.m @@ -5,7 +5,9 @@ * @copyright © 2010-2019 PubNub, Inc. */ #import "PNHistoryParser.h" +#import "PNMessageType+Private.h" #import "PubNub+CorePrivate.h" +#import "PNSpaceId.h" #import "PNConstants.h" #import "PNLogMacro.h" #import "PNLLogger.h" @@ -141,8 +143,10 @@ + (NSMutableDictionary *)processedMessagesFrom:(NSArray *)messages __unused BOOL *messageObjectEnumeratorStop) { NSArray *actions = nil; + NSString *spaceId = nil; NSDictionary *metadata = nil; - NSNumber *messageType = nil; + NSNumber *pubNubMessageType = nil; + NSString *userMessageType = nil; NSString *senderUUID = nil; id message = messageObject; NSNumber *timeToken = nil; @@ -151,7 +155,9 @@ + (NSMutableDictionary *)processedMessagesFrom:(NSArray *)messages (messageObject[@"timetoken"] || messageObject[@"meta"] || messageObject[@"actions"] || messageObject[@"message_type"] || messageObject[@"uuid"])) { - messageType = messageObject[@"message_type"]; + pubNubMessageType = messageObject[@"message_type"]; + userMessageType = messageObject[@"type"]; + spaceId = messageObject[@"space_id"]; timeToken = messageObject[@"timetoken"]; message = messageObject[@"message"]; actions = messageObject[@"actions"]; @@ -223,11 +229,17 @@ + (NSMutableDictionary *)processedMessagesFrom:(NSArray *)messages } if (message) { - if (timeToken || metadata || actions || messageType || senderUUID) { + if (timeToken || metadata || actions || pubNubMessageType || userMessageType || spaceId || senderUUID) { NSMutableDictionary *messageWithInfo = [@{ @"message": message } mutableCopy]; - if ([messageType isKindOfClass:[NSNumber class]]) { - messageWithInfo[@"messageType"] = messageType; + if ([pubNubMessageType isKindOfClass:[NSNumber class]] || + [userMessageType isKindOfClass:[NSString class]]) { + messageWithInfo[@"messageType"] = [PNMessageType messageTypeFromString:userMessageType + pubNubMessageType:pubNubMessageType.unsignedIntValue]; + } + + if (spaceId) { + messageWithInfo[@"spaceId"] = [PNSpaceId spaceIdFromString:spaceId]; } if (timeToken) { diff --git a/PubNub/Network/Parsers/PNSubscribeParser.m b/PubNub/Network/Parsers/PNSubscribeParser.m index 04d4516c3..d204273cc 100644 --- a/PubNub/Network/Parsers/PNSubscribeParser.m +++ b/PubNub/Network/Parsers/PNSubscribeParser.m @@ -419,7 +419,7 @@ + (NSMutableDictionary *)eventFromData:(NSDictionary *)data event[@"subscription"] = (subscriptionMatch ?: channel); event[@"channel"] = channel; - PNMessageType messageType = ((PNEnvelopeInformation *)event[@"envelope"]).messageType; + PNServiceMessageType messageType = ((PNEnvelopeInformation *)event[@"envelope"]).pubNubMessageType; BOOL isEncryptionSupported = messageType == PNRegularMessageType || messageType == PNFileMessageType; diff --git a/PubNub/Network/Requests/Publish/PNBasePublishRequest.h b/PubNub/Network/Requests/Publish/PNBasePublishRequest.h index a77134eeb..0b26f1ce2 100644 --- a/PubNub/Network/Requests/Publish/PNBasePublishRequest.h +++ b/PubNub/Network/Requests/Publish/PNBasePublishRequest.h @@ -2,9 +2,14 @@ #import "PNRequest.h" +#pragma mark Class forward + +@class PNMessageType, PNSpaceId; + + NS_ASSUME_NONNULL_BEGIN -#pragma mark Interface declaration +#pragma mark - Interface declaration /** * @brief Base class for all 'Publish' API endpoints which has shared query options. @@ -39,6 +44,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, copy) NSString *channel; +/** + * @brief Identifier of the space to which message should be published. + */ +@property (nonatomic, nullable, copy) PNSpaceId *spaceId; + /** * @brief Message which will be published. * @@ -47,6 +57,11 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, nullable, strong) id message; +/** + * @brief Custom type with which message should be published. + */ +@property (nonatomic, nullable, copy) PNMessageType *messageType; + /** * @brief How long message should be stored in channel's storage. Pass \b 0 store message according to retention. */ From 8536e9e4b5bbaca470b7849daba0e5967e92e9ac Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 24 Jan 2023 14:11:32 +0100 Subject: [PATCH 02/10] feat(history): add message type support for `history` API Add new fetch batch history parameters to specify `includeMessageType` and `includeSpaceId`. feat(subscribe): return message type and space in listener Objects returned with message / signal listeners now have new `messageType` and `spaceId` fields. --- PubNub/Core/PubNub+History.m | 18 ++- .../History/PNHistoryAPICallBuilder.h | 16 ++ .../History/PNHistoryAPICallBuilder.m | 7 + PubNub/Data/PNEnvelopeInformation.m | 1 + .../Data/Service Objects/PNResult+Private.h | 26 ++- PubNub/Data/Service Objects/PNResult.m | 53 ++++++- PubNub/Network/Parsers/PNHistoryParser.m | 4 + .../Requests/Publish/PNBasePublishRequest.m | 10 ++ Tests/Podfile.lock | 8 +- Tests/Tests/Contract/PNContractCucumberTest.m | 11 +- .../History/PNHistoryContractTestSteps.m | 96 +++++++++++- .../Publish/PNPublishContractTestSteps.m | 42 ++++- .../Subscribe/PNSubscribeContractTestSteps.m | 59 ++++++- Tests/Tests/Helpers/PNContractTestCase.h | 13 ++ Tests/Tests/Helpers/PNContractTestCase.m | 148 +++++++++++++++++- 15 files changed, 482 insertions(+), 30 deletions(-) diff --git a/PubNub/Core/PubNub+History.m b/PubNub/Core/PubNub+History.m index b6c982447..44b78dfb8 100644 --- a/PubNub/Core/PubNub+History.m +++ b/PubNub/Core/PubNub+History.m @@ -43,6 +43,7 @@ @interface PubNub (HistoryProtected) * not. * @param includeMessageType Whether event type should be included in response or not. * By default set to: \b YES. + * @param includeSpaceId Whether identifier of space to which event has been sent should be included or not. * @param includeUUID Whether event publisher UUID should be included in response or not. * By default set to: \b YES. * @param shouldIncludeMessageActions Whether event actions should be included in response or not. @@ -61,6 +62,7 @@ - (void)historyForChannels:(BOOL)multipleChannels reverse:(nullable NSNumber *)shouldReverseOrder includeTimeToken:(nullable NSNumber *)shouldIncludeTimeToken includeMessageType:(nullable NSNumber *)includeMessageType + includeSpaceId:(nullable NSNumber *)includeSpaceId includeUUID:(nullable NSNumber *)includeUUID includeMessageActions:(nullable NSNumber *)shouldIncludeMessageActions includeMetadata:(nullable NSNumber *)shouldIncludeMetadata @@ -153,6 +155,7 @@ @implementation PubNub (History) NSNumber *reverse = parameters[NSStringFromSelector(@selector(reverse))]; NSNumber *includeTimeToken = parameters[NSStringFromSelector(@selector(includeTimeToken))]; NSNumber *includeMessageType = parameters[NSStringFromSelector(@selector(includeMessageType))]; + NSNumber *includeSpaceId = parameters[NSStringFromSelector(@selector(includeSpaceId))]; NSNumber *includeUUID = parameters[NSStringFromSelector(@selector(includeUUID))]; NSNumber *includeMetadata = parameters[NSStringFromSelector(@selector(includeMetadata))]; NSNumber *includeActions = parameters[NSStringFromSelector(@selector(includeMessageActions))]; @@ -167,6 +170,7 @@ @implementation PubNub (History) reverse:reverse includeTimeToken:includeTimeToken includeMessageType:includeMessageType + includeSpaceId:includeSpaceId includeUUID:includeUUID includeMessageActions:includeActions includeMetadata:includeMetadata @@ -316,6 +320,7 @@ - (void)historyForChannel:(NSString *)channel reverse:@NO includeTimeToken:@NO includeMessageType:@YES + includeSpaceId:@NO includeUUID:@YES includeMessageActions:@(shouldIncludeMessageActions) includeMetadata:@(shouldIncludeMetadata) @@ -403,6 +408,7 @@ - (void)historyForChannel:(NSString *)channel reverse:@(shouldReverseOrder) includeTimeToken:@(shouldIncludeTimeToken) includeMessageType:@YES + includeSpaceId:@NO includeUUID:@YES includeMessageActions:nil includeMetadata:nil @@ -418,6 +424,7 @@ - (void)historyForChannels:(BOOL)multipleChannels reverse:(NSNumber *)shouldReverseOrder includeTimeToken:(NSNumber *)shouldIncludeTimeToken includeMessageType:(NSNumber *)includeMessageType + includeSpaceId:(NSNumber *)includeSpaceId includeUUID:(NSNumber *)includeUUID includeMessageActions:(NSNumber *)shouldIncludeMessageActions includeMetadata:(NSNumber *)shouldIncludeMetadata @@ -436,10 +443,14 @@ - (void)historyForChannels:(BOOL)multipleChannels if (!limit || limit.unsignedIntValue == 0) { limit = nil; } - + if (!includeMessageType) { includeMessageType = @YES; } + + if (!includeSpaceId) { + includeSpaceId = @NO; + } if (!includeUUID) { includeUUID = @YES; @@ -508,6 +519,10 @@ - (void)historyForChannels:(BOOL)multipleChannels if (operation == PNHistoryWithActionsOperation || multipleChannels) { [parameters addQueryParameter:(includeMessageType.boolValue ? @"true" : @"false") forFieldName:@"include_message_type"]; + [parameters addQueryParameter:(includeMessageType.boolValue ? @"true" : @"false") + forFieldName:@"include_type"]; + [parameters addQueryParameter:(includeSpaceId.boolValue ? @"true" : @"false") + forFieldName:@"include_space_id"]; [parameters addQueryParameter:(includeUUID.boolValue ? @"true" : @"false") forFieldName:@"include_uuid"]; } @@ -569,6 +584,7 @@ - (void)historyForChannels:(BOOL)multipleChannels reverse:shouldReverseOrder includeTimeToken:shouldIncludeTimeToken includeMessageType:includeMessageType + includeSpaceId:includeSpaceId includeUUID:includeUUID includeMessageActions:shouldIncludeMessageActions includeMetadata:shouldIncludeMetadata diff --git a/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h b/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h index 573880b11..aa875a3da 100644 --- a/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h @@ -121,6 +121,22 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNHistoryAPICallBuilder * (^includeMessageType)(BOOL includeMessageType); +/** + * @brief Events' space presence flag. + * + * @note Available only when message fetched for multiple channels or should include message actions. + * @note Each fetched entry will contain published data under 'message' key and published message + * \c message \c type will be available under 'spaceId' key. + * + * @param includeSpaceId Whether identifier of space to which event has been sent should be included or not. + * By default set to: \b NO. + * + * @return API call configuration builder. + * + * @since 5.2.0 + */ +@property (nonatomic, readonly, strong) PNHistoryAPICallBuilder * (^includeSpaceId)(BOOL includeSpaceId); + /** * @brief Events' publisher UUID presence flag. * diff --git a/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.m b/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.m index ec537eb62..b97af1c83 100644 --- a/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.m @@ -76,6 +76,13 @@ @implementation PNHistoryAPICallBuilder }; } +- (PNHistoryAPICallBuilder * _Nonnull (^)(BOOL includeSpaceId))includeSpaceId { + return ^PNHistoryAPICallBuilder * (BOOL includeSpaceId) { + [self setValue:@(includeSpaceId) forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNHistoryAPICallBuilder * _Nonnull (^)(BOOL includeUUID))includeUUID { return ^PNHistoryAPICallBuilder * (BOOL includeUUID) { [self setValue:@(includeUUID) forParameter:NSStringFromSelector(_cmd)]; diff --git a/PubNub/Data/PNEnvelopeInformation.m b/PubNub/Data/PNEnvelopeInformation.m index 79b50e61f..f57cd9776 100644 --- a/PubNub/Data/PNEnvelopeInformation.m +++ b/PubNub/Data/PNEnvelopeInformation.m @@ -86,6 +86,7 @@ .subscribeKey = @"k", .pubNubMessageTypeKey = @"e", .userMessageTypeKey = @"mt", + .spaceIdKey = @"si", .replicationMap = @"r", .eatAfterReading = @"ear", .metadata = @"u", diff --git a/PubNub/Data/Service Objects/PNResult+Private.h b/PubNub/Data/Service Objects/PNResult+Private.h index f0ac96e0d..e5225f4c5 100644 --- a/PubNub/Data/Service Objects/PNResult+Private.h +++ b/PubNub/Data/Service Objects/PNResult+Private.h @@ -109,13 +109,35 @@ NS_ASSUME_NONNULL_BEGIN /** @brief Convert result object to dictionary which can be used to print out structured data - + @return Object in dictionary representation. - + @since 4.0 */ - (NSDictionary *)dictionaryRepresentation; +/** + @brief Convert result object to dictionary which can be used to print out structured data + + @param dictionary Dictionary in which fields should be normalised. + + @return Object in dictionary representation. + + @since 5.2.0 + */ +- (NSDictionary *)dictionaryRepresentationFromDictionary:(NSDictionary *)dictionary; + +/** + @brief Convert result object to dictionary which can be used to print out structured data + + @param array Array in which fields should be normalised. + + @return Object in dictionary representation. + + @since 5.2.0 + */ +- (NSArray *)arrayRepresentationFromArray:(NSArray *)array; + /** @brief Convert result object to string which can be used to print out data diff --git a/PubNub/Data/Service Objects/PNResult.m b/PubNub/Data/Service Objects/PNResult.m index 27f3cd2f9..4f4195be7 100644 --- a/PubNub/Data/Service Objects/PNResult.m +++ b/PubNub/Data/Service Objects/PNResult.m @@ -201,9 +201,58 @@ - (NSDictionary *)dictionaryRepresentation { @"Response": response}; } +- (NSDictionary *)dictionaryRepresentationFromDictionary:(NSDictionary *)dictionary { + NSMutableDictionary *representation = [NSMutableDictionary new]; + Class messageTypeClass = NSClassFromString(@"PNMessageType"); + Class spaceIdClass = NSClassFromString(@"PNSpaceId"); + + [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { + if ([obj isKindOfClass:messageTypeClass] || [obj isKindOfClass:spaceIdClass]) { + representation[key] = [obj valueForKey:@"value"]; + } else if ([[obj class] isSubclassOfClass:[NSDictionary class]]) { + representation[key] = [self dictionaryRepresentationFromDictionary:obj]; + } else if ([[obj class] isSubclassOfClass:[NSArray class]]) { + representation[key] = [self arrayRepresentationFromArray:obj]; + } else { + representation[key] = obj; + } + }]; + + return representation; +} + +- (NSArray *)arrayRepresentationFromArray:(NSArray *)array { + NSMutableArray *representation = [NSMutableArray new]; + Class messageTypeClass = NSClassFromString(@"PNMessageType"); + Class spaceIdClass = NSClassFromString(@"PNSpaceId"); + + [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL * _Nonnull stop) { + if ([obj isKindOfClass:messageTypeClass] || [obj isKindOfClass:spaceIdClass]) { + if ([obj valueForKey:@"value"]) [representation addObject:[obj valueForKey:@"value"]]; + } else if ([[obj class] isSubclassOfClass:[NSDictionary class]]) { + [representation addObject:[self dictionaryRepresentationFromDictionary:obj]]; + } else if ([[obj class] isSubclassOfClass:[NSArray class]]) { + [representation addObject:[self arrayRepresentationFromArray:obj]]; + } else { + [representation addObject:obj]; + } + }]; + + return representation; +} + - (NSString *)stringifiedRepresentation { - - return [PNJSON JSONStringFrom:[self dictionaryRepresentation] withError:NULL]; + NSDictionary *dictionary = [self dictionaryRepresentation]; + NSString *representation; + + @try { + representation = [PNJSON JSONStringFrom:dictionary withError:NULL]; + } @catch (NSException *exception) { + dictionary = [self dictionaryRepresentationFromDictionary:dictionary]; + representation = [PNJSON JSONStringFrom:dictionary withError:NULL]; + } + + return representation ? representation : @"unable to stirnfigy object"; } - (NSString *)debugDescription { diff --git a/PubNub/Network/Parsers/PNHistoryParser.m b/PubNub/Network/Parsers/PNHistoryParser.m index de228dea6..03627d572 100644 --- a/PubNub/Network/Parsers/PNHistoryParser.m +++ b/PubNub/Network/Parsers/PNHistoryParser.m @@ -168,6 +168,10 @@ + (NSMutableDictionary *)processedMessagesFrom:(NSArray *)messages if (![metadata isKindOfClass:[NSDictionary class]]) { metadata = nil; } + + if ([pubNubMessageType isKindOfClass:[NSNull class]]) { + pubNubMessageType = @(PNRegularMessageType); + } timeToken = timeToken ? @(((NSString *)timeToken).longLongValue) : nil; [self normalizeActionTimetokens:((NSDictionary *)actions).allValues]; diff --git a/PubNub/Network/Requests/Publish/PNBasePublishRequest.m b/PubNub/Network/Requests/Publish/PNBasePublishRequest.m index 4d414631a..259dfe20b 100644 --- a/PubNub/Network/Requests/Publish/PNBasePublishRequest.m +++ b/PubNub/Network/Requests/Publish/PNBasePublishRequest.m @@ -6,6 +6,8 @@ */ #import "PNBasePublishRequest+Private.h" #import "PNRequest+Private.h" +#import "PNMessageType.h" +#import "PNSpaceId.h" #import "PNHelpers.h" #import "PNAES.h" @@ -113,6 +115,14 @@ - (PNRequestParameters *)requestParameters { if (!self.shouldReplicate) { [parameters addQueryParameter:@"true" forFieldName:@"norep"]; } + + if (self.spaceId) { + [parameters addQueryParameter:self.spaceId.value forFieldName:@"space-id"]; + } + + if (self.messageType) { + [parameters addQueryParameter:self.messageType.value forFieldName:@"type"]; + } parameters.POSTBodyCompressed = self.shouldCompress; diff --git a/Tests/Podfile.lock b/Tests/Podfile.lock index 6c57afa50..5874ac7e5 100644 --- a/Tests/Podfile.lock +++ b/Tests/Podfile.lock @@ -1,9 +1,9 @@ PODS: - Cucumberish (1.4.0) - OCMock (3.6) - - PubNub (5.1.2): - - PubNub/Core (= 5.1.2) - - PubNub/Core (5.1.2) + - PubNub (5.1.3): + - PubNub/Core (= 5.1.3) + - PubNub/Core (5.1.3) - YAHTTPVCR (1.4.2) DEPENDENCIES: @@ -32,7 +32,7 @@ CHECKOUT OPTIONS: SPEC CHECKSUMS: Cucumberish: 6cbd0c1f50306b369acebfe7d9f514c9c287d26c OCMock: 5ea90566be239f179ba766fd9fbae5885040b992 - PubNub: 65ddd075debdb479878f7bd42e4f3ab7de25ccec + PubNub: 0c6f2e5728efe4bb65c26b991331aae39ac5e5a5 YAHTTPVCR: e2aa406443a4db12585ff626b445369e1953a729 PODFILE CHECKSUM: 569ce5fdb7670790d6d4a9d1a5a304a20781e374 diff --git a/Tests/Tests/Contract/PNContractCucumberTest.m b/Tests/Tests/Contract/PNContractCucumberTest.m index c1b33bb45..51c473566 100644 --- a/Tests/Tests/Contract/PNContractCucumberTest.m +++ b/Tests/Tests/Contract/PNContractCucumberTest.m @@ -37,10 +37,19 @@ void CucumberishInit(void) { if ([xcTestBundlePath rangeOfString:@"Contract Tests Beta"].location != NSNotFound) { [excludeTags removeObject:@"beta"]; } + + // TODO: REMOVE AFTER ALL TESTS FOR MESSAGE TYPE WILL BE MERGED. + excludeTags = nil; + NSArray *includedTags = @[ + @"featureSet=historyVSP", + @"featureSet=publishToSpace", + @"featureSet=signalToSpace", + @"featureSet=subscribeVSP" + ]; NSBundle * bundle = [NSBundle bundleForClass:[PNContractTestCase class]]; [Cucumberish executeFeaturesInDirectory:@"Features" fromBundle:bundle - includeTags:nil + includeTags:includedTags excludeTags:excludeTags]; } diff --git a/Tests/Tests/Contract/Steps/History/PNHistoryContractTestSteps.m b/Tests/Tests/Contract/Steps/History/PNHistoryContractTestSteps.m index ba2ff5897..d1315baca 100644 --- a/Tests/Tests/Contract/Steps/History/PNHistoryContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/History/PNHistoryContractTestSteps.m @@ -14,8 +14,68 @@ @implementation PNHistoryContractTestSteps - (void)setup { [self startCucumberHookEventsListening]; + + When(@"^I fetch message history for '(.*)' channel$", ^(NSArray *args, NSDictionary *userInfo) { + XCTAssertEqual(args.count, 1); + self.testedFeatureType = PNHistoryForChannelsOperation; + + [self callCodeSynchronously:^(dispatch_block_t completion) { + self.client.history() + .channels(args) + .performWithCompletion(^(PNHistoryResult *result, PNErrorStatus *status) { + [self storeRequestResult:result]; + [self storeRequestStatus:status]; + completion(); + }); + }]; + }); + + Match(@[@"And"], @"^history response contains messages (with|without) ('(.*)' and '(.*)' )?message types$", + ^(NSArray *args, NSDictionary *userInfo) { + XCTAssertGreaterThan(args.count, 0); + NSString *inclusionFlag = args.firstObject; + PNHistoryResult *result = (PNHistoryResult *)[self lastResult]; + XCTAssertNotNil(result); + + NSArray *messages = result.data.channels.allValues.firstObject; + XCTAssertGreaterThan(messages.count, 0); + NSArray *receivedMessageTypes = [messages valueForKeyPath:@"messageType.value"]; + NSMutableArray *filteredReceivedMessageTypes = [NSMutableArray arrayWithArray:receivedMessageTypes]; + [filteredReceivedMessageTypes removeObjectIdenticalTo:[NSNull null]]; + + XCTAssertFalse([inclusionFlag isEqual:@"with"] && filteredReceivedMessageTypes.count == 0); + XCTAssertFalse([inclusionFlag isEqual:@"without"] && filteredReceivedMessageTypes.count > 0); + + if (args.count > 1) { + SEL compare = @selector(caseInsensitiveCompare:); + NSArray *expectedMessageTypes = [[args subarrayWithRange:NSMakeRange(2, 2)] sortedArrayUsingSelector:compare]; + NSArray *receivedMessageTypes = [filteredReceivedMessageTypes sortedArrayUsingSelector:compare]; + XCTAssertEqualObjects(receivedMessageTypes, expectedMessageTypes); + } else { + XCTAssertEqual([inclusionFlag isEqual:@"with"] ? messages.count : 0, + filteredReceivedMessageTypes.count); + } + }); + + Match(@[@"And"], @"^history response contains messages (with|without) space ids$", + ^(NSArray *args, NSDictionary *userInfo) { + XCTAssertGreaterThan(args.count, 0); + NSString *inclusionFlag = args.firstObject; + PNHistoryResult *result = (PNHistoryResult *)[self lastResult]; + XCTAssertNotNil(result); + + NSArray *messages = result.data.channels.allValues.firstObject; + XCTAssertGreaterThan(messages.count, 0); + NSArray *receivedSpaceIds = [messages valueForKeyPath:@"spaceId.value"]; + NSMutableArray *filteredReceivedSpaceIds = [NSMutableArray arrayWithArray:receivedSpaceIds]; + [filteredReceivedSpaceIds removeObjectIdenticalTo:[NSNull null]]; + + XCTAssertFalse([inclusionFlag isEqual:@"with"] && filteredReceivedSpaceIds.count == 0); + XCTAssertFalse([inclusionFlag isEqual:@"without"] && filteredReceivedSpaceIds.count > 0); + XCTAssertEqual([inclusionFlag isEqual:@"with"] ? messages.count : 0, filteredReceivedSpaceIds.count); + }); - When(@"^I fetch message history for (.*) channel(s)?$", ^(NSArray *args, NSDictionary *userInfo) { + When(@"^I fetch message history for (single|multiple) channel(s)?$", ^(NSArray *args, NSDictionary *userInfo) { NSArray *channels = [args.firstObject isEqualToString:@"multiple"] ? @[@"test1", @"test2"] : @[@"test"]; self.testedFeatureType = PNHistoryForChannelsOperation; @@ -30,15 +90,15 @@ - (void)setup { }]; }); - Then(@"the response contains pagination info", ^(NSArray *args, NSDictionary *userInfo) { + Then(@"^the response contains pagination info$", ^(NSArray *args, NSDictionary *userInfo) { PNHistoryResult *result = (PNHistoryResult *)[self lastResult]; XCTAssertNotNil(result.data.start); XCTAssertNotNil(result.data.end); }); - - When(@"I fetch message history with message actions", ^(NSArray *args, NSDictionary *userInfo) { + + When(@"^I fetch message history with message actions$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNHistoryWithActionsOperation; - + [self callCodeSynchronously:^(dispatch_block_t completion) { self.client.history() .channel(@"test") @@ -50,6 +110,32 @@ - (void)setup { }); }]; }); + + When(@"^I fetch message history with '(.*)' set to '(.*)' for '(.*)' channel$", + ^(NSArray *args, NSDictionary *userInfo) { + XCTAssertEqual(args.count, 3); + self.testedFeatureType = PNHistoryWithActionsOperation; + BOOL includeMessageType = YES; + BOOL includeSpaceId = NO; + + if ([args.firstObject isEqual:@"includeMessageType"]) { + includeMessageType = [args[1] isEqual:@"true"]; + } else if ([args.firstObject isEqual:@"includeSpaceId"]) { + includeSpaceId = [args[1] isEqual:@"true"]; + } + + [self callCodeSynchronously:^(dispatch_block_t completion) { + self.client.history() + .channels(@[args[2]]) + .includeMessageType(includeMessageType) + .includeSpaceId(includeSpaceId) + .performWithCompletion(^(PNHistoryResult *result, PNErrorStatus *status) { + [self storeRequestResult:result]; + [self storeRequestStatus:status]; + completion(); + }); + }]; + }); } #pragma mark - diff --git a/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m b/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m index 192ce5474..8a38f23ba 100644 --- a/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m @@ -15,7 +15,7 @@ @implementation PNPublishContractTestSteps - (void)setup { [self startCucumberHookEventsListening]; - When(@"I publish a message", ^(NSArray *args, NSDictionary *userInfo) { + When(@"^I publish a message$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNPublishOperation; [self callCodeSynchronously:^(dispatch_block_t completion) { @@ -28,10 +28,10 @@ - (void)setup { }); }]; }); - + When(@"^I publish a message with (.*) metadata$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNPublishOperation; - + [self callCodeSynchronously:^(dispatch_block_t completion) { id meta = [args.lastObject isEqualToString:@"JSON"] ? @{@"test-user": @"bob"} : @"test-user=bob"; self.client.publish() @@ -44,8 +44,25 @@ - (void)setup { }); }]; }); + + When(@"^I publish message with '(.*)' space id and '(.*)' message type$", + ^(NSArray *args, NSDictionary *userInfo) { + self.testedFeatureType = PNPublishOperation; + + [self callCodeSynchronously:^(dispatch_block_t completion) { + self.client.publish() + .message(@"hello") + .channel(@"test") + .messageType([PNMessageType messageTypeFromString:args.lastObject]) + .spaceId([PNSpaceId spaceIdFromString:args.firstObject]) + .performWithCompletion(^(PNPublishStatus *status) { + [self storeRequestStatus:status]; + completion(); + }); + }]; + }); - When(@"I send a signal", ^(NSArray *args, NSDictionary *userInfo) { + When(@"^I send a signal$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNSignalOperation; [self callCodeSynchronously:^(dispatch_block_t completion) { @@ -58,6 +75,23 @@ - (void)setup { }); }]; }); + + When(@"^I send a signal with '(.*)' space id and '(.*)' message type$", + ^(NSArray *args, NSDictionary *userInfo) { + self.testedFeatureType = PNSignalOperation; + + [self callCodeSynchronously:^(dispatch_block_t completion) { + self.client.signal() + .message(@"hello") + .channel(@"test") + .messageType([PNMessageType messageTypeFromString:args.lastObject]) + .spaceId([PNSpaceId spaceIdFromString:args.firstObject]) + .performWithCompletion(^(PNSignalStatus *status) { + [self storeRequestStatus:status]; + completion(); + }); + }]; + }); } #pragma mark - diff --git a/Tests/Tests/Contract/Steps/Subscribe/PNSubscribeContractTestSteps.m b/Tests/Tests/Contract/Steps/Subscribe/PNSubscribeContractTestSteps.m index 7aec371f5..ec6298b2e 100644 --- a/Tests/Tests/Contract/Steps/Subscribe/PNSubscribeContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/Subscribe/PNSubscribeContractTestSteps.m @@ -22,21 +22,37 @@ - (void)setup { Given(@"the invalid-crypto keyset", ^(NSArray *args, NSDictionary *userInfo) { self.configuration.cipherKey = @"secret"; }); - - When(@"I subscribe", ^(NSArray *args, NSDictionary *userInfo) { + + When(@"^I subscribe$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNSubscribeOperation; - + [self subscribeClient:nil synchronouslyToChannels:@[@"test"] groups:nil withPresence:NO timetoken:nil]; - + + // Give some time to rotate received timetokens. + [self pauseMainQueueFor:0.5f]; + }); + + When(@"^I subscribe to '(.*)' channel$", ^(NSArray *args, NSDictionary *userInfo) { + self.testedFeatureType = PNSubscribeOperation; + XCTAssertGreaterThan(args.count, 0); + + [self subscribeClient:nil synchronouslyToChannels:args groups:nil withPresence:NO timetoken:nil]; + // Give some time to rotate received timetokens. [self pauseMainQueueFor:0.5f]; }); - Then(@"I receive the message in my subscribe response", ^(NSArray *args, NSDictionary *userInfo) { + Then(@"^I receive (the|[0-9]+) message(s)? in my subscribe response$", + ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNSubscribeOperation; + XCTAssertGreaterThan(args.count, 0); + NSUInteger expectedCount = ![args.firstObject isEqual:@"the"] ? args.firstObject.intValue : 1; - NSArray *messages = [self waitClient:nil toReceiveMessages:1 onChannel:nil]; + NSArray *messages = [self waitClient:nil + toReceiveSignalsOrMessages:expectedCount + onChannel:nil]; XCTAssertNotNil(messages); + XCTAssertEqual(messages.count, expectedCount); if ([self checkInUserInfo:userInfo testingFeature:@"Message encryption"]) { XCTAssertEqualObjects(messages.lastObject.data.message, @"hello world"); } else if ([self checkInUserInfo:userInfo testingFeature:@"Subscribe Loop"]) { @@ -55,6 +71,37 @@ - (void)setup { [self pauseMainQueueFor:0.5f]; }); + + Match(@[@"And"], @"^response contains messages with '(.*)' and '(.*)' message types$", + ^(NSArray *args, NSDictionary *userInfo) { + XCTAssertEqual(args.count, 2); + + NSArray *messages = [self waitClient:nil toReceiveSignalsOrMessages:2 onChannel:nil]; + XCTAssertNotNil(messages); + XCTAssertEqual(messages.count, 2); + + SEL compare = @selector(caseInsensitiveCompare:); + NSArray *expectedMessageTypes = [args sortedArrayUsingSelector:compare]; + NSArray *receivedMessageTypes = [[messages valueForKeyPath:@"data.messageType.value"] sortedArrayUsingSelector:compare]; + XCTAssertEqualObjects(receivedMessageTypes, expectedMessageTypes); + }); + + Match(@[@"And"], @"^response contains messages (with|without) space ids$", + ^(NSArray *args, NSDictionary *userInfo) { + XCTAssertEqual(args.count, 1); + + NSArray *messages = [self waitClient:nil toReceiveSignalsOrMessages:2 onChannel:nil]; + XCTAssertNotNil(messages); + XCTAssertEqual(messages.count, 2); + + NSArray *receivedSpaceIds = [messages valueForKeyPath:@"data.spaceId.value"]; + NSMutableArray *filteredReceivedSpaceIds = [NSMutableArray arrayWithArray:receivedSpaceIds]; + [filteredReceivedSpaceIds removeObjectIdenticalTo:[NSNull null]]; + + XCTAssertFalse([args.firstObject isEqual:@"with"] && filteredReceivedSpaceIds.count == 0); + XCTAssertFalse([args.firstObject isEqual:@"without"] && filteredReceivedSpaceIds.count > 0); + XCTAssertEqual([args.firstObject isEqual:@"with"] ? messages.count : 0, filteredReceivedSpaceIds.count); + }); } #pragma mark - diff --git a/Tests/Tests/Helpers/PNContractTestCase.h b/Tests/Tests/Helpers/PNContractTestCase.h index d9568dddc..a2b2e1073 100644 --- a/Tests/Tests/Helpers/PNContractTestCase.h +++ b/Tests/Tests/Helpers/PNContractTestCase.h @@ -92,6 +92,19 @@ synchronouslyFromChannels:(nullable NSArray *)channels toReceiveMessages:(NSUInteger)messagesCount onChannel:(nullable NSString *)channel; +/** + * @brief Wait specified \b PubNub client to receive expected number (in total) of messages and signals. + * + * @param client \b PubNub client which is expecting to receive specific number (in total) of messages and signals. + * @param count How many messages and signals it is expected to receive. + * @param channel Channel on which messages and signals expected. All channels for \c client if \c nil. + * + * @return List of messages and signals when expected count received. + */ +- (nullable NSArray *)waitClient:(nullable PubNub *)client + toReceiveSignalsOrMessages:(NSUInteger)count + onChannel:(nullable NSString *)channel; + /** * @brief Wait specified \b PubNub client to receive expected number of status events. * diff --git a/Tests/Tests/Helpers/PNContractTestCase.m b/Tests/Tests/Helpers/PNContractTestCase.m index ebe936e49..3d17f891c 100644 --- a/Tests/Tests/Helpers/PNContractTestCase.m +++ b/Tests/Tests/Helpers/PNContractTestCase.m @@ -31,7 +31,9 @@ static NSString * const kPNCucumberAfterHook = @"PNCucumberAfterHook"; typedef NSMutableArray PNTestChannelMessagesList; +typedef NSMutableArray PNTestChannelSignalsList; typedef NSMutableDictionary PNTestClientMessagesList; +typedef NSMutableDictionary PNTestClientSignalsList; typedef NSMutableArray PNTestClientStatusesList; @@ -69,11 +71,21 @@ */ static NSMutableArray *_messageHandlers; +/** + * @brief List of GCD blocks which listens for PubNub client signal receive. + */ +static NSMutableArray *_signalHandlers; + /** * @brief Messages received during current scenario execution. */ static NSMutableDictionary *_receivedMessages; +/** + * @brief Signals received during current scenario execution. + */ +static NSMutableDictionary *_receivedSignals; + static PNOperationType _currentlyTestedFeatureType; @@ -137,6 +149,16 @@ - (nullable NSString *)contractForScenario:(CCIScenarioDefinition *)scenario; */ - (NSUInteger)messagesCountForClient:(PubNub *)client onChannel:(nullable NSString *)channel; +/** + * @brief Get total number of messages and signals which has been sent to specific channel. + * + * @param client \b PubNub client for which count should be done. + * @param channel Specific channel on which messages should be counted or all channels for \c client if \c nil. + * + * @return Total number of messages and signals for specified \c client and \c channel. + */ +- (NSUInteger)messagesAndSignalsCountForClient:(PubNub *)client onChannel:(nullable NSString *)channel; + /** * @brief Check whether currently tested feature expects to receive response from server or not. * @@ -219,7 +241,9 @@ - (void)setup { _apiCallResults = [NSMutableArray new]; _receivedMessages = [NSMutableDictionary new]; _receivedStatuses = [NSMutableDictionary new]; + _receivedSignals = [NSMutableDictionary new]; _messageHandlers = [NSMutableArray new]; + _signalHandlers = [NSMutableArray new]; _statusHandlers = [NSMutableArray new]; _resourcesAccess = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0); @@ -263,7 +287,7 @@ - (void)setup { // Nothing to do. Mock server will simulate proper error here. }); - Then(@"I receive successful response", ^(NSArray *args, NSDictionary *userInfo) { + Then(@"I receive (a )?successful response", ^(NSArray *args, NSDictionary *userInfo) { PNStatus *status = [self lastStatus]; PNResult *result = [self lastResult]; @@ -276,7 +300,7 @@ - (void)setup { } }); - Then(@"I receive error response", ^(NSArray *args, NSDictionary *userInfo) { + Then(@"I receive (an )?error response", ^(NSArray *args, NSDictionary *userInfo) { PNStatus *status = [self lastStatus]; PNResult *result = [self lastResult]; @@ -380,7 +404,7 @@ - (void)unsubscribeClient:(PubNub *)client NSString *clientIdentifier = receiver.currentConfiguration.uuid; if ([client.currentConfiguration.uuid isEqualToString:clientIdentifier]) { - receivedRequiredCount = messagesCount >= [weakSelf messagesCountForClient:receiver onChannel:channel]; + receivedRequiredCount = messagesCount < [weakSelf messagesCountForClient:receiver onChannel:channel]; } if (receivedRequiredCount) { @@ -404,7 +428,7 @@ - (void)unsubscribeClient:(PubNub *)client dispatch_semaphore_signal(semaphore); } }]; - + if (!checkMessagesCount(client)){ dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC)); } else { @@ -416,6 +440,74 @@ - (void)unsubscribeClient:(PubNub *)client return messages; } +- (NSArray *)waitClient:(PubNub *)client + toReceiveSignalsOrMessages:(NSUInteger)count + onChannel:(NSString *)channel { + dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); + __block BOOL completedInTime = NO; + __block NSArray *messages = nil; + client = client ?: self.client; + + __weak __typeof(self) weakSelf = self; + BOOL(^checkMessagesCount)(PubNub *) = ^BOOL(PubNub *receiver) { + __block NSUInteger receivedMessagesCount = 0; + __block BOOL receivedRequiredCount = NO; + + dispatch_sync(_resourcesAccess, ^{ + NSString *clientIdentifier = receiver.currentConfiguration.uuid; + + if ([client.currentConfiguration.uuid isEqualToString:clientIdentifier]) { + receivedMessagesCount = [weakSelf messagesAndSignalsCountForClient:receiver onChannel:channel]; + receivedRequiredCount = receivedMessagesCount >= count; + } + + if (receivedRequiredCount) { + PNTestClientMessagesList *clientMessages = _receivedMessages[clientIdentifier]; + PNTestClientSignalsList *clientSignals = _receivedSignals[clientIdentifier]; + NSArray *receivedMessages; + NSArray *receivedSignals; + + if (channel) { + receivedMessages = clientMessages[channel] ?: @[]; + receivedSignals = clientSignals[channel] ?: @[]; + } else { + receivedMessages = [clientMessages.allValues valueForKeyPath:@"@unionOfArrays.self"] ?: @[]; + receivedSignals = [clientSignals.allValues valueForKeyPath:@"@unionOfArrays.self"] ?: @[]; + } + + messages = [receivedMessages arrayByAddingObjectsFromArray:receivedSignals]; + } + }); + + return receivedRequiredCount; + }; + + + [_messageHandlers addObject:^void(PubNub *receiver, PNMessageResult *message) { + if (checkMessagesCount(receiver)) { + completedInTime = YES; + dispatch_semaphore_signal(semaphore); + } + }]; + + [_signalHandlers addObject:^void(PubNub *receiver, PNSignalResult *message) { + if (checkMessagesCount(receiver)) { + completedInTime = YES; + dispatch_semaphore_signal(semaphore); + } + }]; + + if (!checkMessagesCount(client)){ + dispatch_semaphore_wait(semaphore, dispatch_time(DISPATCH_TIME_NOW, 30 * NSEC_PER_SEC)); + } else { + completedInTime = YES; + } + + XCTAssertTrue(completedInTime, @"%@ messages not received in time", @(count)); + + return messages.count > 0 ? messages : nil; +} + - (NSArray *)waitClient:(PubNub *)client toReceiveStatuses:(NSUInteger)statusesCount { dispatch_semaphore_t semaphore = dispatch_semaphore_create(0); __block PNTestClientStatusesList *statuses = nil; @@ -506,7 +598,9 @@ - (void)handleAfterHook { [_apiCallResults removeAllObjects]; [_receivedMessages removeAllObjects]; [_receivedStatuses removeAllObjects]; + [_receivedSignals removeAllObjects]; [_messageHandlers removeAllObjects]; + [_signalHandlers removeAllObjects]; [_statusHandlers removeAllObjects]; dispatch_barrier_sync(_resourcesAccess, ^{ @@ -612,6 +706,26 @@ - (NSUInteger)messagesCountForClient:(PubNub *)client onChannel:(NSString *)chan return messagesCount; } +- (NSUInteger)messagesAndSignalsCountForClient:(PubNub *)client onChannel:(NSString *)channel { + PNTestClientMessagesList *clientMessages = _receivedMessages[client.currentConfiguration.uuid]; + PNTestClientSignalsList *clientSignals = _receivedSignals[client.currentConfiguration.uuid]; + __block NSUInteger messagesCount = 0; + + if (channel) { + messagesCount = clientMessages[channel].count + clientSignals[channel].count; + } else { + [clientMessages enumerateKeysAndObjectsUsingBlock:^(NSString *channel, PNTestChannelMessagesList *messages, BOOL *stop) { + messagesCount += messages.count; + }]; + + [clientSignals enumerateKeysAndObjectsUsingBlock:^(NSString *channel, PNTestChannelSignalsList *messages, BOOL *stop) { + messagesCount += messages.count; + }]; + } + + return messagesCount; +} + - (BOOL)testedFeatureExpectResponse { BOOL responseExpected = NO; @@ -689,13 +803,37 @@ - (void)client:(PubNub *)client didReceiveMessage:(PNMessageResult *)message { } [channelMessages addObject:message]; - + [_messageHandlers enumerateObjectsUsingBlock:^(void (^block)(PubNub *, PNMessageResult *), NSUInteger idx, BOOL *stop) { block(client, message); }]; }); } +- (void)client:(PubNub *)client didReceiveSignal:(PNSignalResult *)signal { + dispatch_barrier_async(_resourcesAccess, ^{ + PNTestClientSignalsList *clientSignals = _receivedSignals[client.currentConfiguration.uuid]; + + if (!clientSignals) { + clientSignals = [NSMutableDictionary new]; + _receivedSignals[client.currentConfiguration.uuid] = clientSignals; + } + + PNTestChannelSignalsList *channelSignals = clientSignals[signal.data.channel]; + + if (!channelSignals) { + channelSignals = [NSMutableArray new]; + clientSignals[signal.data.channel] = channelSignals; + } + + [channelSignals addObject:signal]; + + [_signalHandlers enumerateObjectsUsingBlock:^(void (^block)(PubNub *, PNSignalResult *), NSUInteger idx, BOOL *stop) { + block(client, signal); + }]; + }); +} + #pragma mark - From 9becf0d17f3ae5102594a7178170c03ec5cff358 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 24 Jan 2023 15:41:14 +0100 Subject: [PATCH 03/10] test(history): fix history integration tests --- ...hActionsAndReceiveResultWithExpectedOperation.json | 6 +++--- ...esAndFailToDecryptWhenDifferentCipherKeyIsSet.json | 6 +++--- ...istoryWithActionsUsingBuilderPatternInterface.json | 6 +++--- ...nelUsingBuilderPatternInterfaceWhenLimitIsSet.json | 6 +++--- ...n25MessagesForEachChannelWithUsedBatchBuilder.json | 6 +++--- ...nterfaceAndReceiveResultWithExpectedOperation.json | 6 +++--- ...eMessageForEachChannelWithOutUUIDUsingBuilder.json | 6 +++--- Tests/Tests/Contract/PNContractCucumberTest.m | 11 +---------- .../Tests/Integration/Files/PNFilesIntegrationTests.m | 2 +- 9 files changed, 23 insertions(+), 32 deletions(-) diff --git a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryForChannelWithActionsAndReceiveResultWithExpectedOperation.json b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryForChannelWithActionsAndReceiveResultWithExpectedOperation.json index cd78bd66e..4be5b95ee 100644 --- a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryForChannelWithActionsAndReceiveResultWithExpectedOperation.json +++ b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryForChannelWithActionsAndReceiveResultWithExpectedOperation.json @@ -598,7 +598,7 @@ }, "pipeline" : false, "network" : 0, - "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1" + "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1&include_type=1&include_space_id=0" }, "type" : 0 }, @@ -607,7 +607,7 @@ "data" : { "status" : 200, "cls" : "NSHTTPURLResponse", - "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1", + "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1&include_type=1&include_space_id=0", "headers" : { "Access-Control-Allow-Credentials" : "true", "Content-Type" : "text\/javascript; charset=\"UTF-8\"", @@ -689,4 +689,4 @@ "id" : "7F4AC768-102F-4C2F-998F-ED5AF035E9FA", "type" : 4 } -] \ No newline at end of file +] diff --git a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryForChannelWithEncryptedMessagesAndFailToDecryptWhenDifferentCipherKeyIsSet.json b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryForChannelWithEncryptedMessagesAndFailToDecryptWhenDifferentCipherKeyIsSet.json index c370ef887..e7a76cd63 100644 --- a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryForChannelWithEncryptedMessagesAndFailToDecryptWhenDifferentCipherKeyIsSet.json +++ b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryForChannelWithEncryptedMessagesAndFailToDecryptWhenDifferentCipherKeyIsSet.json @@ -220,7 +220,7 @@ }, "pipeline" : false, "network" : 0, - "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Kim&include_message_type=1" + "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Kim&include_message_type=1&include_type=1&include_space_id=0" }, "type" : 0 }, @@ -229,7 +229,7 @@ "data" : { "status" : 200, "cls" : "NSHTTPURLResponse", - "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Kim&include_message_type=1", + "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Kim&include_message_type=1&include_type=1&include_space_id=0", "headers" : { "Access-Control-Allow-Credentials" : "true", "Content-Type" : "text\/javascript; charset=\"UTF-8\"", @@ -311,4 +311,4 @@ "id" : "268F0D38-2C56-4628-87FA-DDCB4360EE22", "type" : 4 } -] \ No newline at end of file +] diff --git a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryWithActionsUsingBuilderPatternInterface.json b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryWithActionsUsingBuilderPatternInterface.json index 21b4ba14e..6b709e1b0 100644 --- a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryWithActionsUsingBuilderPatternInterface.json +++ b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchHistoryWithActionsUsingBuilderPatternInterface.json @@ -598,7 +598,7 @@ }, "pipeline" : false, "network" : 0, - "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=16&include_meta=1&include_message_type=1" + "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=16&include_meta=1&include_message_type=1&include_type=1&include_space_id=0" }, "type" : 0 }, @@ -607,7 +607,7 @@ "data" : { "status" : 200, "cls" : "NSHTTPURLResponse", - "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=16&include_meta=1&include_message_type=1", + "url" : "https:\/\/ps.pndsn.com\/v3\/history-with-actions\/sub-key\/demo\/channel\/test-channel?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=16&include_meta=1&include_message_type=1&include_type=1&include_space_id=0", "headers" : { "Access-Control-Allow-Credentials" : "true", "Content-Type" : "text\/javascript; charset=\"UTF-8\"", @@ -689,4 +689,4 @@ "id" : "25FC405C-400B-40E6-8AE7-B55BEBA1CFC0", "type" : 4 } -] \ No newline at end of file +] diff --git a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchMessagesForEachChannelUsingBuilderPatternInterfaceWhenLimitIsSet.json b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchMessagesForEachChannelUsingBuilderPatternInterfaceWhenLimitIsSet.json index 7071d30ee..60b11e0e6 100644 --- a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchMessagesForEachChannelUsingBuilderPatternInterfaceWhenLimitIsSet.json +++ b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchMessagesForEachChannelUsingBuilderPatternInterfaceWhenLimitIsSet.json @@ -424,7 +424,7 @@ }, "pipeline" : false, "network" : 0, - "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=20&include_meta=1&include_message_type=1" + "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=20&include_meta=1&include_message_type=1&include_type=1&include_space_id=0" }, "type" : 0 }, @@ -433,7 +433,7 @@ "data" : { "status" : 200, "cls" : "NSHTTPURLResponse", - "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=20&include_meta=1&include_message_type=1", + "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=20&include_meta=1&include_message_type=1&include_type=1&include_space_id=0", "headers" : { "Access-Control-Allow-Methods" : "GET, POST, DELETE, OPTIONS", "Content-Type" : "text\/javascript; charset=\"UTF-8\"", @@ -569,4 +569,4 @@ "id" : "64F5D15E-CF9C-47A0-926D-528E3B8E1EFA", "type" : 4 } -] \ No newline at end of file +] diff --git a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchMoreThan25MessagesForEachChannelWithUsedBatchBuilder.json b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchMoreThan25MessagesForEachChannelWithUsedBatchBuilder.json index 2a51ecf5a..cdefb3e9a 100644 --- a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchMoreThan25MessagesForEachChannelWithUsedBatchBuilder.json +++ b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchMoreThan25MessagesForEachChannelWithUsedBatchBuilder.json @@ -2056,7 +2056,7 @@ }, "pipeline" : false, "network" : 0, - "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1?include_uuid=0&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=100&include_message_type=1" + "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1?include_uuid=0&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=100&include_message_type=1&include_type=1&include_space_id=0" }, "type" : 0 }, @@ -2065,7 +2065,7 @@ "data" : { "status" : 200, "cls" : "NSHTTPURLResponse", - "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1?include_uuid=0&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=100&include_message_type=1", + "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1?include_uuid=0&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&max=100&include_message_type=1&include_type=1&include_space_id=0", "headers" : { "Access-Control-Allow-Methods" : "GET, POST, DELETE, OPTIONS", "Content-Type" : "text\/javascript; charset=\"UTF-8\"", @@ -2155,4 +2155,4 @@ "id" : "E1E2034E-B481-419F-ACE1-5B56D0789B1F", "type" : 4 } -] \ No newline at end of file +] diff --git a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchOneMessageForEachChannelUsingBuilderPatternInterfaceAndReceiveResultWithExpectedOperation.json b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchOneMessageForEachChannelUsingBuilderPatternInterfaceAndReceiveResultWithExpectedOperation.json index 0427af5b2..21760a541 100644 --- a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchOneMessageForEachChannelUsingBuilderPatternInterfaceAndReceiveResultWithExpectedOperation.json +++ b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchOneMessageForEachChannelUsingBuilderPatternInterfaceAndReceiveResultWithExpectedOperation.json @@ -424,7 +424,7 @@ }, "pipeline" : false, "network" : 0, - "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1" + "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1&include_type=1&include_space_id=0" }, "type" : 0 }, @@ -433,7 +433,7 @@ "data" : { "status" : 200, "cls" : "NSHTTPURLResponse", - "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1", + "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=1&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1&include_type=1&include_space_id=0", "headers" : { "Access-Control-Allow-Methods" : "GET, POST, DELETE, OPTIONS", "Content-Type" : "text\/javascript; charset=\"UTF-8\"", @@ -569,4 +569,4 @@ "id" : "F619DD49-DEA7-4B53-B066-072B83029FA2", "type" : 4 } -] \ No newline at end of file +] diff --git a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchOneMessageForEachChannelWithOutUUIDUsingBuilder.json b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchOneMessageForEachChannelWithOutUUIDUsingBuilder.json index b197bb43c..93afee8de 100644 --- a/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchOneMessageForEachChannelWithOutUUIDUsingBuilder.json +++ b/Tests/Support Files/Fixtures/PNHistoryIntegrationTests.bundle/ItShouldFetchOneMessageForEachChannelWithOutUUIDUsingBuilder.json @@ -424,7 +424,7 @@ }, "pipeline" : false, "network" : 0, - "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=0&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1" + "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=0&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1&include_type=1&include_space_id=0" }, "type" : 0 }, @@ -433,7 +433,7 @@ "data" : { "status" : 200, "cls" : "NSHTTPURLResponse", - "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=0&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1", + "url" : "https:\/\/ps.pndsn.com\/v3\/history\/sub-key\/demo\/channel\/test-channel1,test-channel2?include_uuid=0&pnsdk=PubNub-ObjC-iOS\/4.x.x&uuid=Serhii&include_message_type=1&include_type=1&include_space_id=0", "headers" : { "Access-Control-Allow-Methods" : "GET, POST, DELETE, OPTIONS", "Content-Type" : "text\/javascript; charset=\"UTF-8\"", @@ -569,4 +569,4 @@ "id" : "7E42FE27-9BC5-4FC6-B8DE-4A72B5C10804", "type" : 4 } -] \ No newline at end of file +] diff --git a/Tests/Tests/Contract/PNContractCucumberTest.m b/Tests/Tests/Contract/PNContractCucumberTest.m index 51c473566..c1b33bb45 100644 --- a/Tests/Tests/Contract/PNContractCucumberTest.m +++ b/Tests/Tests/Contract/PNContractCucumberTest.m @@ -37,19 +37,10 @@ void CucumberishInit(void) { if ([xcTestBundlePath rangeOfString:@"Contract Tests Beta"].location != NSNotFound) { [excludeTags removeObject:@"beta"]; } - - // TODO: REMOVE AFTER ALL TESTS FOR MESSAGE TYPE WILL BE MERGED. - excludeTags = nil; - NSArray *includedTags = @[ - @"featureSet=historyVSP", - @"featureSet=publishToSpace", - @"featureSet=signalToSpace", - @"featureSet=subscribeVSP" - ]; NSBundle * bundle = [NSBundle bundleForClass:[PNContractTestCase class]]; [Cucumberish executeFeaturesInDirectory:@"Features" fromBundle:bundle - includeTags:includedTags + includeTags:nil excludeTags:excludeTags]; } diff --git a/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m b/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m index 83630a035..07c48d07c 100644 --- a/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m +++ b/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m @@ -169,7 +169,7 @@ - (void)testItShouldSendFileFromDataAndReceiveFromHistory { XCTAssertEqual(messages.count, 1); XCTAssertNotNil(messages.firstObject[@"uuid"]); XCTAssertNotNil(messages.firstObject[@"messageType"]); - XCTAssertEqualObjects(messages.firstObject[@"messageType"], @4); + XCTAssertEqualObjects(((PNMessageType *)messages.firstObject[@"messageType"]).value, @"file"); handler(); }); From b202f01e07c85aaded48fb6d3edecba545346a34 Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Fri, 10 Feb 2023 21:45:25 +0100 Subject: [PATCH 04/10] feat(message-type): add message type for file Add `messageType` and `spaceId` to files API endpoints. --- PubNub/Core/PubNub+Files.h | 2 ++ PubNub/Core/PubNub+Files.m | 4 +++ PubNub/Core/PubNub+Publish.m | 2 ++ .../API Call/Files/PNSendFileAPICallBuilder.h | 29 ++++++++++++++++++- .../API Call/Files/PNSendFileAPICallBuilder.m | 14 +++++++++ .../PNPublishFileMessageAPICallBuilder.h | 29 ++++++++++++++++++- .../PNPublishFileMessageAPICallBuilder.m | 14 +++++++++ PubNub/Data/PNEnvelopeInformation.h | 4 ++- PubNub/Data/PNEnvelopeInformation.m | 2 +- .../Requests/Files/PNSendFileRequest.h | 21 +++++++++++++- .../Requests/Publish/PNBasePublishRequest.h | 8 +++-- 11 files changed, 122 insertions(+), 7 deletions(-) diff --git a/PubNub/Core/PubNub+Files.h b/PubNub/Core/PubNub+Files.h index 3980c3653..ec5b7afa9 100644 --- a/PubNub/Core/PubNub+Files.h +++ b/PubNub/Core/PubNub+Files.h @@ -3,6 +3,8 @@ #import "PNDeleteFileRequest.h" #import "PNListFilesRequest.h" #import "PNSendFileRequest.h" +#import "PNMessageType.h" +#import "PNSpaceId.h" #import "PNFile.h" #import "PNDownloadFileResult.h" diff --git a/PubNub/Core/PubNub+Files.m b/PubNub/Core/PubNub+Files.m index 5fbda728b..eabd316ff 100644 --- a/PubNub/Core/PubNub+Files.m +++ b/PubNub/Core/PubNub+Files.m @@ -189,6 +189,8 @@ - (void)sendFileRequestUsingBuilderParameters:(NSDictionary *)parameters { request.cipherKey = cipherKey ?: self.configuration.cipherKey; request.fileMessageMetadata = parameters[NSStringFromSelector(@selector(fileMessageMetadata))]; request.arbitraryQueryParameters = parameters[@"queryParam"]; + request.messageType = parameters[NSStringFromSelector(@selector(messageType))]; + request.spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; request.message = parameters[NSStringFromSelector(@selector(message))]; if (store) { @@ -506,7 +508,9 @@ - (void)handleUploadFileSuccessWithFileIdentifier:(NSString *)fileIdentifier request.arbitraryQueryParameters = sendFileRequest.arbitraryQueryParameters; request.metadata = sendFileRequest.fileMessageMetadata; + request.messageType = sendFileRequest.messageType; request.store = sendFileRequest.fileMessageStore; + request.spaceId = sendFileRequest.spaceId; request.message = sendFileRequest.message; if (request.store) { diff --git a/PubNub/Core/PubNub+Publish.m b/PubNub/Core/PubNub+Publish.m index ecbf6d734..307f9ccc8 100644 --- a/PubNub/Core/PubNub+Publish.m +++ b/PubNub/Core/PubNub+Publish.m @@ -257,7 +257,9 @@ @implementation PubNub (Publish) PNPublishFileMessageRequest *request = [PNPublishFileMessageRequest requestWithChannel:channel fileIdentifier:identifier name:filename]; + request.messageType = parameters[NSStringFromSelector(@selector(messageType))]; request.metadata = parameters[NSStringFromSelector(@selector(metadata))]; + request.spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; request.message = parameters[NSStringFromSelector(@selector(message))]; request.arbitraryQueryParameters = parameters[@"queryParam"]; request.store = (shouldStore ? shouldStore.boolValue : YES); diff --git a/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.h b/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.h index 199d82117..77b7d06c4 100644 --- a/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.h @@ -3,7 +3,12 @@ NS_ASSUME_NONNULL_BEGIN -#pragma mark Interface declaration +#pragma mark Class forward + +@class PNSpaceId, PNMessageType; + + +#pragma mark - Interface declaration /** * @brief \c Send \c file API call builder. @@ -73,6 +78,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNSendFileAPICallBuilder * (^cipherKey)(NSString *key); +/** + * @brief Target space identifier name. + * + * @param spaceId Identifier of the space to which message should be published. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNSendFileAPICallBuilder * (^spaceId)(PNSpaceId *spaceId); + /** * @brief Message which should be sent along with file to specified \c channel. * @@ -85,6 +101,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNSendFileAPICallBuilder * (^message)(id message); +/** + * @brief Type of message which will be published. + * + * @param type Custom type for published message. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNSendFileAPICallBuilder * (^messageType)(PNMessageType *type); + /** * @brief In-memory binary data which should be uploaded and available in target channel. * diff --git a/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.m b/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.m index 2c3331958..e1011bf25 100644 --- a/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.m @@ -67,6 +67,13 @@ @implementation PNSendFileAPICallBuilder }; } +- (PNSendFileAPICallBuilder * (^)(PNSpaceId *spaceId))spaceId { + return ^PNSendFileAPICallBuilder * (PNSpaceId *spaceId) { + [self setValue:spaceId forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNSendFileAPICallBuilder * (^)(id message))message { return ^PNSendFileAPICallBuilder * (id message) { [self setValue:message forParameter:NSStringFromSelector(_cmd)]; @@ -75,6 +82,13 @@ @implementation PNSendFileAPICallBuilder }; } +- (PNSendFileAPICallBuilder * (^)(PNMessageType *messageType))messageType { + return ^PNSendFileAPICallBuilder * (PNMessageType *messageType) { + [self setValue:messageType forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNSendFileAPICallBuilder * (^)(NSData *data))data { return ^PNSendFileAPICallBuilder * (NSData *data) { if ([data isKindOfClass:[NSData class]]) { diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.h b/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.h index db78efffa..d409807f5 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.h @@ -2,9 +2,14 @@ #import "PNStructures.h" +#pragma mark Class forward + +@class PNMessageType, PNSpaceId; + + NS_ASSUME_NONNULL_BEGIN -#pragma mark Interface declaration +#pragma mark - Interface declaration /** * @brief Base publish API call builder. @@ -46,6 +51,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNPublishFileMessageAPICallBuilder * (^channel)(NSString *channel); +/** + * @brief Target space identifier name. + * + * @param spaceId Identifier of the space to which message should be published. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNPublishFileMessageAPICallBuilder * (^spaceId)(PNSpaceId *spaceId); + /** * @brief Message payload. * @@ -58,6 +74,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNPublishFileMessageAPICallBuilder * (^message)(id message); +/** + * @brief Type of message which will be published. + * + * @param type Custom type for published message. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNPublishFileMessageAPICallBuilder * (^messageType)(PNMessageType *type); + /** * @brief Message metadata. * diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.m b/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.m index 873bf2660..72692341b 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.m @@ -50,6 +50,13 @@ @implementation PNPublishFileMessageAPICallBuilder }; } +- (PNPublishFileMessageAPICallBuilder * (^)(PNSpaceId *spaceId))spaceId { + return ^PNPublishFileMessageAPICallBuilder * (PNSpaceId *spaceId) { + [self setValue:spaceId forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNPublishFileMessageAPICallBuilder * (^)(id message))message { return ^PNPublishFileMessageAPICallBuilder * (id message) { [self setValue:message forParameter:NSStringFromSelector(_cmd)]; @@ -57,6 +64,13 @@ @implementation PNPublishFileMessageAPICallBuilder }; } +- (PNPublishFileMessageAPICallBuilder * (^)(PNMessageType *messageType))messageType { + return ^PNPublishFileMessageAPICallBuilder * (PNMessageType *messageType) { + [self setValue:messageType forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNPublishFileMessageAPICallBuilder * (^)(NSDictionary *metadata))metadata { return ^PNPublishFileMessageAPICallBuilder * (NSDictionary *metadata) { if ([metadata isKindOfClass:[NSDictionary class]]) { diff --git a/PubNub/Data/PNEnvelopeInformation.h b/PubNub/Data/PNEnvelopeInformation.h index d01ae5d00..53ce05adf 100644 --- a/PubNub/Data/PNEnvelopeInformation.h +++ b/PubNub/Data/PNEnvelopeInformation.h @@ -64,8 +64,10 @@ /** * @brief Identifier of space from which message has been received. + * + * @since 5.2.0 */ -@property (nonatomic, nullable, readonly, copy) PNSpaceId *spaceId; +@property (nonatomic, nullable, readonly, strong) PNSpaceId *spaceId; /** * @brief Event replication map (region based). diff --git a/PubNub/Data/PNEnvelopeInformation.m b/PubNub/Data/PNEnvelopeInformation.m index f57cd9776..da9624081 100644 --- a/PubNub/Data/PNEnvelopeInformation.m +++ b/PubNub/Data/PNEnvelopeInformation.m @@ -110,7 +110,7 @@ @interface PNEnvelopeInformation () @property (nonatomic, copy) NSString *subscribeKey; @property (atomic, assign) PNServiceMessageType pubNubMessageType; @property (nonatomic, nullable, strong) PNMessageType *messageType; -@property (nonatomic, nullable, copy) PNSpaceId *spaceId; +@property (nonatomic, nullable, strong) PNSpaceId *spaceId; @property (nonatomic, copy) NSNumber *replicationMap; @property (nonatomic, copy) NSNumber *eatAfterReading; @property (nonatomic, copy) NSDictionary *metadata; diff --git a/PubNub/Network/Requests/Files/PNSendFileRequest.h b/PubNub/Network/Requests/Files/PNSendFileRequest.h index 672221147..80e700ac0 100644 --- a/PubNub/Network/Requests/Files/PNSendFileRequest.h +++ b/PubNub/Network/Requests/Files/PNSendFileRequest.h @@ -4,7 +4,12 @@ NS_ASSUME_NONNULL_BEGIN -#pragma mark Interface declaration +#pragma mark Class forward + +@class PNSpaceId, PNMessageType; + + +#pragma mark - Interface declaration /** * @brief \c Upload \c file request. @@ -46,6 +51,13 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, copy) NSString *channel; +/** + * @brief Identifier of the space to which message should be published. + * + * @since 5.2.0 + */ +@property (nonatomic, nullable, strong) PNSpaceId *spaceId; + /** * @brief Whether \b PubNub published \c file \c message should be stored in \c channel history. */ @@ -59,6 +71,13 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, nullable, strong) id message; +/** + * @brief Custom type with which message should be published. + * + * @since 5.2.0 + */ +@property (nonatomic, nullable, strong) PNMessageType *messageType; + /** * @brief Name which should be used to store uploaded data. */ diff --git a/PubNub/Network/Requests/Publish/PNBasePublishRequest.h b/PubNub/Network/Requests/Publish/PNBasePublishRequest.h index 0b26f1ce2..e6c5f51af 100644 --- a/PubNub/Network/Requests/Publish/PNBasePublishRequest.h +++ b/PubNub/Network/Requests/Publish/PNBasePublishRequest.h @@ -46,8 +46,10 @@ NS_ASSUME_NONNULL_BEGIN /** * @brief Identifier of the space to which message should be published. + * + * @since 5.2.0 */ -@property (nonatomic, nullable, copy) PNSpaceId *spaceId; +@property (nonatomic, nullable, strong) PNSpaceId *spaceId; /** * @brief Message which will be published. @@ -59,8 +61,10 @@ NS_ASSUME_NONNULL_BEGIN /** * @brief Custom type with which message should be published. + * + * @since 5.2.0 */ -@property (nonatomic, nullable, copy) PNMessageType *messageType; +@property (nonatomic, nullable, strong) PNMessageType *messageType; /** * @brief How long message should be stored in channel's storage. Pass \b 0 store message according to retention. From cfa2ce4fa9bcfb8d6ba60ca7199502c70e64baeb Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Wed, 15 Feb 2023 13:51:44 +0100 Subject: [PATCH 05/10] test(contract-test): add files contract testing Add contract testing for file upload with `messageType` and `spaceId`. --- .../Steps/Files/PNFilesContractTestSteps.m | 26 ++++++++++++++++--- 1 file changed, 23 insertions(+), 3 deletions(-) diff --git a/Tests/Tests/Contract/Steps/Files/PNFilesContractTestSteps.m b/Tests/Tests/Contract/Steps/Files/PNFilesContractTestSteps.m index 811f6cb90..2f3ff5163 100644 --- a/Tests/Tests/Contract/Steps/Files/PNFilesContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/Files/PNFilesContractTestSteps.m @@ -70,14 +70,34 @@ - (void)setup { }); }]; }); - - When(@"I send file", ^(NSArray *args, NSDictionary *userInfo) { + + When(@"^I send file$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNSendFileOperation; - + + [self callCodeSynchronously:^(dispatch_block_t completion) { + self.client.files() + .sendFile(@"test", @"name.txt") + .data([@"test file data" dataUsingEncoding:NSUTF8StringEncoding]) + .performWithCompletion(^(PNSendFileStatus *status) { + [self storeRequestStatus:status]; + completion(); + }); + }]; + }); + + When(@"^I send a file with '(.+)' space id and '(.+)' message type$", ^(NSArray *args, NSDictionary *userInfo) { + XCTAssertEqual(args.count, 2); + NSString *messageType = args.lastObject; + NSString *spaceId = args.firstObject; + + self.testedFeatureType = PNSendFileOperation; + [self callCodeSynchronously:^(dispatch_block_t completion) { self.client.files() .sendFile(@"test", @"name.txt") .data([@"test file data" dataUsingEncoding:NSUTF8StringEncoding]) + .messageType([PNMessageType messageTypeFromString:messageType]) + .spaceId([PNSpaceId spaceIdFromString:spaceId]) .performWithCompletion(^(PNSendFileStatus *status) { [self storeRequestStatus:status]; completion(); From 51c8c007df42cb585d984fa02869d27d73940eff Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Fri, 24 Feb 2023 08:46:40 +0100 Subject: [PATCH 06/10] refactor(message-type): add type prefix Add prefix to service provided message types. refactor(files): do not retry publish on 400 Stop file message publish attempts if server returned 400 status code. --- PubNub/Core/PubNub+Files.m | 2 +- PubNub/Data/Models/PNMessageType.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PubNub/Core/PubNub+Files.m b/PubNub/Core/PubNub+Files.m index eabd316ff..19c8fec77 100644 --- a/PubNub/Core/PubNub+Files.m +++ b/PubNub/Core/PubNub+Files.m @@ -520,7 +520,7 @@ - (void)handleUploadFileSuccessWithFileIdentifier:(NSString *)fileIdentifier __block NSUInteger publishAttemptsCount = 1; [self publishFileMessageWithRequest:request completion:^(PNPublishStatus *status) { - if (!status.isError || publishAttemptsCount >= fileMessagePublishRetryLimit) { + if (!status.isError || status.statusCode == 400 || publishAttemptsCount >= fileMessagePublishRetryLimit) { PNSendFileStatus *sendFileStatus = nil; NSMutableDictionary *serviceData = [@{ @"id": fileIdentifier, diff --git a/PubNub/Data/Models/PNMessageType.m b/PubNub/Data/Models/PNMessageType.m index 22989b797..86ed24bea 100644 --- a/PubNub/Data/Models/PNMessageType.m +++ b/PubNub/Data/Models/PNMessageType.m @@ -107,7 +107,7 @@ + (NSString *)valueFromUserType:(NSString *)userMessageType pubNubMessageType:(P static dispatch_once_t onceToken; dispatch_once(&onceToken, ^{ - _pubNubMessageTypeMap = @[@"message", @"signal", @"object", @"messageAction", @"file"]; + _pubNubMessageTypeMap = @[@"pn_message", @"pn_signal", @"pn_object", @"pn_messageAction", @"pn_file"]; }); return userMessageType ? userMessageType : _pubNubMessageTypeMap[pubNubMessageType]; From e3342a8ecc21908bc170dd39ae3c458015f9f8fe Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Fri, 24 Feb 2023 09:14:04 +0100 Subject: [PATCH 07/10] fix(message-type): fix for empty message type Fix `PNMessageType` initialization when user-provided message type is empty. --- PubNub/Data/Models/PNMessageType.m | 2 +- Tests/Tests/Integration/Files/PNFilesIntegrationTests.m | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/PubNub/Data/Models/PNMessageType.m b/PubNub/Data/Models/PNMessageType.m index 86ed24bea..cc9935be9 100644 --- a/PubNub/Data/Models/PNMessageType.m +++ b/PubNub/Data/Models/PNMessageType.m @@ -110,7 +110,7 @@ + (NSString *)valueFromUserType:(NSString *)userMessageType pubNubMessageType:(P _pubNubMessageTypeMap = @[@"pn_message", @"pn_signal", @"pn_object", @"pn_messageAction", @"pn_file"]; }); - return userMessageType ? userMessageType : _pubNubMessageTypeMap[pubNubMessageType]; + return userMessageType.length ? userMessageType : _pubNubMessageTypeMap[pubNubMessageType]; } #pragma mark - diff --git a/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m b/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m index 07c48d07c..7f5df01fc 100644 --- a/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m +++ b/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m @@ -169,7 +169,7 @@ - (void)testItShouldSendFileFromDataAndReceiveFromHistory { XCTAssertEqual(messages.count, 1); XCTAssertNotNil(messages.firstObject[@"uuid"]); XCTAssertNotNil(messages.firstObject[@"messageType"]); - XCTAssertEqualObjects(((PNMessageType *)messages.firstObject[@"messageType"]).value, @"file"); + XCTAssertEqualObjects(((PNMessageType *)messages.firstObject[@"messageType"]).value, @"pn_file"); handler(); }); From b884aa9cf27e9ef43c7a28ccd0ec37cb1339297f Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Tue, 7 Mar 2023 14:53:41 +0100 Subject: [PATCH 08/10] test(contract): fix publish contract tests --- PubNub/Core/PubNub+Core.m | 3 +- PubNub/Network/PNNetwork.m | 1 - .../Publish/PNPublishContractTestSteps.m | 97 ++++++++++++++++++- Tests/Tests/Helpers/PNContractTestCase.m | 15 +++ 4 files changed, 113 insertions(+), 3 deletions(-) diff --git a/PubNub/Core/PubNub+Core.m b/PubNub/Core/PubNub+Core.m index f5c021ae5..85ef6a05b 100644 --- a/PubNub/Core/PubNub+Core.m +++ b/PubNub/Core/PubNub+Core.m @@ -547,7 +547,8 @@ - (void)processOperation:(PNOperationType)operationType - (void)processOperation:(PNOperationType)operationType withParameters:(PNRequestParameters *)parameters - data:(NSData *)data completionBlock:(id)block { + data:(NSData *)data + completionBlock:(id)block { [self addAuthParameter:parameters]; diff --git a/PubNub/Network/PNNetwork.m b/PubNub/Network/PNNetwork.m index 5817084ae..5494f7b84 100644 --- a/PubNub/Network/PNNetwork.m +++ b/PubNub/Network/PNNetwork.m @@ -687,7 +687,6 @@ - (NSURLRequest *)requestWithURL:(NSURL *)requestURL NSMutableDictionary *allHeaders = [httpRequest.allHTTPHeaderFields mutableCopy]; [allHeaders addEntriesFromDictionary: @{ @"Content-Type": @"application/json;charset=UTF-8", - @"Content-Length": @(postData.length).stringValue }]; if (isDataCompressed) { diff --git a/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m b/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m index 8a38f23ba..ef8e0fc0c 100644 --- a/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m @@ -5,7 +5,27 @@ #import "PNPublishContractTestSteps.h" -#pragma mark Interface implementation +NS_ASSUME_NONNULL_BEGIN + +#pragma mark Private interface declaration + +@interface PNPublishContractTestSteps () + + +#pragma mark - Helpers + +- (PNPublishAPICallBuilder *)publishBuilderForMessage:(id)message toChannel:(NSString *)channel; +- (id)message:(id)message castedToType:(NSString *)type; + +#pragma mark - + + +@end + +NS_ASSUME_NONNULL_END + + +#pragma mark - Interface implementation @implementation PNPublishContractTestSteps @@ -28,6 +48,61 @@ - (void)setup { }); }]; }); + + When(@"^I publish ('(.*)' (string|number|array|dictionary) as|too long) message to '(.*)' channel( with compression| as POST body)?$", + ^(NSArray *args, NSDictionary *userInfo) { + self.testedFeatureType = PNPublishOperation; + XCTAssertGreaterThanOrEqual(args.count, 2); + id message; + id channel; + + if ([args[0] isEqualToString:@"too long"]) { + NSMutableString *string = [NSMutableString new]; + for (NSUInteger count = 0; count < 2500; count += 6) [string appendString:@"hello-"]; + message = string; + channel = args[1]; + } else { + args = [args subarrayWithRange:NSMakeRange(1, args.count - 1)]; + message = [self message:args[0] castedToType:args[1]]; + channel = args[2]; + } + + PNPublishAPICallBuilder *publish = [self publishBuilderForMessage:message toChannel:channel]; + if (args.count == 4 && [args[3] isEqualToString:@" with compression"]) publish.compress(YES); + + [self callCodeSynchronously:^(dispatch_block_t completion) { + publish.performWithCompletion(^(PNPublishStatus *status) { + [self storeRequestStatus:status]; + completion(); + }); + }]; + }); + + When(@"^I publish '(.*)' (string|number|array|dictionary) as message to '(.*)' channel with '(.*)' set to '(.*)'$", + ^(NSArray *args, NSDictionary *userInfo) { + self.testedFeatureType = PNPublishOperation; + XCTAssertEqual(args.count, 5); + + id message = [self message:args[0] castedToType:args[1]]; + id channel = args[2]; + + PNPublishAPICallBuilder *publish = [self publishBuilderForMessage:message toChannel:channel]; + if (args.count == 5 && [args[3] isEqualToString:@"meta"]) { + NSString *metaType = [args[4] characterAtIndex:0] == '{' ? @"dictionary" : @"string"; + publish.metadata([self message:args[4] castedToType:metaType]); + } else if (args.count == 5 && [args[3] isEqualToString:@"store"]) { + publish.shouldStore([args[4] isEqualToString:@"1"]); + } else if (args.count == 5 && [args[3] isEqualToString:@"ttl"]) { + publish.ttl(args[4].integerValue); + } + + [self callCodeSynchronously:^(dispatch_block_t completion) { + publish.performWithCompletion(^(PNPublishStatus *status) { + [self storeRequestStatus:status]; + completion(); + }); + }]; + }); When(@"^I publish a message with (.*) metadata$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNPublishOperation; @@ -94,6 +169,26 @@ - (void)setup { }); } + +#pragma mark - Helpers + +- (PNPublishAPICallBuilder *)publishBuilderForMessage:(id)message toChannel:(NSString *)channel { + return self.client.publish().channel(channel).message(message); +} + +- (id)message:(id)message castedToType:(NSString *)type { + if ([type isEqualToString:@"number"]) { + NSNumberFormatter *formatter = [NSNumberFormatter new]; + formatter.numberStyle = NSNumberFormatterDecimalStyle; + message = [formatter numberFromString:message]; + } else if (![type isEqualToString:@"string"]) { + NSData *messageData = [message dataUsingEncoding:NSUTF8StringEncoding]; + message = [NSJSONSerialization JSONObjectWithData:messageData options:0 error:nil]; + } + + return message; +} + #pragma mark - diff --git a/Tests/Tests/Helpers/PNContractTestCase.m b/Tests/Tests/Helpers/PNContractTestCase.m index 3d17f891c..bdcb237d3 100644 --- a/Tests/Tests/Helpers/PNContractTestCase.m +++ b/Tests/Tests/Helpers/PNContractTestCase.m @@ -287,6 +287,14 @@ - (void)setup { // Nothing to do. Mock server will simulate proper error here. }); + Given(@"the wrong publish key", ^(NSArray *args, NSDictionary *userInfo) { + // Nothing to do. Mock server will simulate proper error here. + }); + + Given(@"the wrong subscribe key", ^(NSArray *args, NSDictionary *userInfo) { + // Nothing to do. Mock server will simulate proper error here. + }); + Then(@"I receive (a )?successful response", ^(NSArray *args, NSDictionary *userInfo) { PNStatus *status = [self lastStatus]; PNResult *result = [self lastResult]; @@ -316,6 +324,13 @@ - (void)setup { } }); + Match(@[@"*"], @"^the error status code is ([0-9]+)$", ^(NSArray *args, NSDictionary *userInfo) { + XCTAssertGreaterThan(args.count, 0); + PNStatus *status = [self lastStatus]; + + XCTAssertEqual(status.statusCode, args[0].integerValue); + }); + // Complete known contract steps configuration. [[PNAccessContractTestSteps new] setup]; [[PNFilesContractTestSteps new] setup]; From 2daaaaa2b2c489acfe139e684a854a33138ed71d Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 30 Mar 2023 10:47:34 +0200 Subject: [PATCH 09/10] refactor(message-type): rename `messageType` to `type` (#447) refactor(message-type): rename `messageType` to `type` Rename field in responses and request configuration from `messageType` to `type` and update history endpoint to include flags. --- .../project.pbxproj | 36 ------ Framework/PubNub/PubNub.h | 1 - PubNub/Core/PubNub+Files.h | 1 - PubNub/Core/PubNub+Files.m | 4 +- PubNub/Core/PubNub+History.m | 17 ++- PubNub/Core/PubNub+Publish.h | 1 - PubNub/Core/PubNub+Publish.m | 51 ++++---- .../API Call/Files/PNSendFileAPICallBuilder.h | 6 +- .../API Call/Files/PNSendFileAPICallBuilder.m | 6 +- .../History/PNHistoryAPICallBuilder.h | 16 +++ .../History/PNHistoryAPICallBuilder.m | 7 ++ .../Publish/PNPublishAPICallBuilder.h | 6 +- .../Publish/PNPublishAPICallBuilder.m | 6 +- .../PNPublishFileMessageAPICallBuilder.h | 6 +- .../PNPublishFileMessageAPICallBuilder.m | 6 +- .../Publish/PNPublishSizeAPICallBuilder.h | 27 ++++ .../Publish/PNPublishSizeAPICallBuilder.m | 16 ++- .../API Call/Publish/PNSignalAPICallBuilder.h | 7 +- .../API Call/Publish/PNSignalAPICallBuilder.m | 6 +- PubNub/Data/Managers/PNSubscriber.m | 4 +- PubNub/Data/Models/PNMessageType+Private.h | 38 ------ PubNub/Data/Models/PNMessageType.h | 76 ----------- PubNub/Data/Models/PNMessageType.m | 119 ------------------ PubNub/Data/PNEnvelopeInformation.h | 8 +- PubNub/Data/PNEnvelopeInformation.m | 19 ++- PubNub/Data/Service Objects/PNResult.m | 6 +- .../Data/Service Objects/PNSubscribeStatus.h | 6 +- .../Data/Service Objects/PNSubscribeStatus.m | 4 +- PubNub/Network/Parsers/PNHistoryParser.m | 12 +- PubNub/Network/Parsers/PNSubscribeParser.m | 2 +- .../Requests/Files/PNSendFileRequest.h | 6 +- .../Requests/Publish/PNBasePublishRequest.h | 6 +- .../Requests/Publish/PNBasePublishRequest.m | 5 +- .../Steps/Files/PNFilesContractTestSteps.m | 4 +- .../History/PNHistoryContractTestSteps.m | 33 ++--- .../Publish/PNPublishContractTestSteps.m | 8 +- .../Files/PNFilesIntegrationTests.m | 5 +- 37 files changed, 198 insertions(+), 389 deletions(-) delete mode 100644 PubNub/Data/Models/PNMessageType+Private.h delete mode 100644 PubNub/Data/Models/PNMessageType.h delete mode 100644 PubNub/Data/Models/PNMessageType.m diff --git a/Framework/PubNub Framework.xcodeproj/project.pbxproj b/Framework/PubNub Framework.xcodeproj/project.pbxproj index c3293db01..ba7338404 100644 --- a/Framework/PubNub Framework.xcodeproj/project.pbxproj +++ b/Framework/PubNub Framework.xcodeproj/project.pbxproj @@ -2493,21 +2493,6 @@ A5A7B0332349330F0060113B /* PNBaseMessageActionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A7AFF82349330F0060113B /* PNBaseMessageActionRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; A5A7B0342349330F0060113B /* PNBaseMessageActionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A7AFF82349330F0060113B /* PNBaseMessageActionRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; A5A7B0362349330F0060113B /* PNBaseMessageActionRequest.h in Headers */ = {isa = PBXBuildFile; fileRef = A5A7AFF82349330F0060113B /* PNBaseMessageActionRequest.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A5CE35612959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A5CE35622959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A5CE35632959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A5CE35642959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A5CE35652959C45B0038FD6F /* PNMessageType.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE355F2959C45B0038FD6F /* PNMessageType.h */; settings = {ATTRIBUTES = (Public, ); }; }; - A5CE35662959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; - A5CE35672959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; - A5CE35682959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; - A5CE35692959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; - A5CE356A2959C45B0038FD6F /* PNMessageType.m in Sources */ = {isa = PBXBuildFile; fileRef = A5CE35602959C45B0038FD6F /* PNMessageType.m */; }; - A5CE356C2959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; - A5CE356D2959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; - A5CE356E2959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; - A5CE356F2959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; - A5CE35702959C9260038FD6F /* PNMessageType+Private.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */; }; A5CE35732959D1E80038FD6F /* PNSpaceId.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE35712959D1E80038FD6F /* PNSpaceId.h */; settings = {ATTRIBUTES = (Public, ); }; }; A5CE35742959D1E80038FD6F /* PNSpaceId.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE35712959D1E80038FD6F /* PNSpaceId.h */; settings = {ATTRIBUTES = (Public, ); }; }; A5CE35752959D1E80038FD6F /* PNSpaceId.h in Headers */ = {isa = PBXBuildFile; fileRef = A5CE35712959D1E80038FD6F /* PNSpaceId.h */; settings = {ATTRIBUTES = (Public, ); }; }; @@ -3068,9 +3053,6 @@ A5A7AFF62349330E0060113B /* PNRemoveMessageActionRequest.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; name = PNRemoveMessageActionRequest.m; path = Message/PNRemoveMessageActionRequest.m; sourceTree = ""; }; A5A7AFF72349330F0060113B /* PNRemoveMessageActionRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PNRemoveMessageActionRequest.h; path = Message/PNRemoveMessageActionRequest.h; sourceTree = ""; }; A5A7AFF82349330F0060113B /* PNBaseMessageActionRequest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; name = PNBaseMessageActionRequest.h; path = Message/PNBaseMessageActionRequest.h; sourceTree = ""; }; - A5CE355F2959C45B0038FD6F /* PNMessageType.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PNMessageType.h; sourceTree = ""; }; - A5CE35602959C45B0038FD6F /* PNMessageType.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PNMessageType.m; sourceTree = ""; }; - A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PNMessageType+Private.h"; sourceTree = ""; }; A5CE35712959D1E80038FD6F /* PNSpaceId.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = PNSpaceId.h; sourceTree = ""; }; A5CE35722959D1E80038FD6F /* PNSpaceId.m */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.objc; path = PNSpaceId.m; sourceTree = ""; }; A5FADC322490270E001D7704 /* PubNub+Files.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "PubNub+Files.h"; sourceTree = ""; }; @@ -3822,9 +3804,6 @@ A55A86A722FD817E002D0A72 /* PNUUIDMetadata+Private.h */, A55A86A822FD817E002D0A72 /* PNUUIDMetadata.h */, A55A86A422FD817E002D0A72 /* PNUUIDMetadata.m */, - A5CE356B2959C9260038FD6F /* PNMessageType+Private.h */, - A5CE355F2959C45B0038FD6F /* PNMessageType.h */, - A5CE35602959C45B0038FD6F /* PNMessageType.m */, A5CE35712959D1E80038FD6F /* PNSpaceId.h */, A5CE35722959D1E80038FD6F /* PNSpaceId.m */, A58975E023005CFB0093BD9A /* PNMembership+Private.h */, @@ -4092,7 +4071,6 @@ 79AA8EC926EAB81500ADA747 /* PNConfiguration+Private.h in Headers */, A58975B223005AAC0093BD9A /* PNManageMembershipsStatus.h in Headers */, 79A238D01D2E70BD00D080CD /* NSURLSessionConfiguration+PNConfiguration.h in Headers */, - A5CE356C2959C9260038FD6F /* PNMessageType+Private.h in Headers */, 791582521BD709C60084FC70 /* PNPresenceChannelGroupHereNowResult.h in Headers */, 7932485E1D874D9F00FBDF36 /* PNPublishSequence.h in Headers */, 79A0D8441DC22C950039A264 /* PNAPNSAuditAPICallBuilder.h in Headers */, @@ -4204,7 +4182,6 @@ A55DAEFC24B1FE9E00766EE9 /* PNXML.h in Headers */, A55A87DC22FD8272002D0A72 /* PNBaseObjectsRequest.h in Headers */, A57A3089238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, - A5CE35612959C45B0038FD6F /* PNMessageType.h in Headers */, 79A0D86E1DC22C950039A264 /* PNAPICallBuilder+Private.h in Headers */, A57A30E9238DCAAF00DE8C68 /* PNAPNSNotificationTarget+Private.h in Headers */, A55A881B22FD8272002D0A72 /* PNFetchAllChannelsMetadataRequest.h in Headers */, @@ -4370,7 +4347,6 @@ 79AA8ECB26EAB81500ADA747 /* PNConfiguration+Private.h in Headers */, A58975B423005AAC0093BD9A /* PNManageMembershipsStatus.h in Headers */, 791583201BD709D10084FC70 /* PNPushNotificationsStateModificationParser.h in Headers */, - A5CE356E2959C9260038FD6F /* PNMessageType+Private.h in Headers */, 79A238D21D2E70BD00D080CD /* NSURLSessionConfiguration+PNConfiguration.h in Headers */, 791582FB1BD709D10084FC70 /* PNPresenceChannelGroupHereNowResult.h in Headers */, 793248601D874D9F00FBDF36 /* PNPublishSequence.h in Headers */, @@ -4482,7 +4458,6 @@ A55DAEFE24B1FE9E00766EE9 /* PNXML.h in Headers */, A55A87DE22FD8272002D0A72 /* PNBaseObjectsRequest.h in Headers */, A57A308B238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, - A5CE35632959C45B0038FD6F /* PNMessageType.h in Headers */, 791583111BD709D10084FC70 /* PNHistoryResult.h in Headers */, A57A30EB238DCAAF00DE8C68 /* PNAPNSNotificationTarget+Private.h in Headers */, A55A881D22FD8272002D0A72 /* PNFetchAllChannelsMetadataRequest.h in Headers */, @@ -4691,7 +4666,6 @@ A5A7B0132349330F0060113B /* PNAddMessageActionRequest.h in Headers */, A55BCCFB231D222B0019DB68 /* PNRemoveMessageActionAPICallBuilder.h in Headers */, 7960B6691F68122200FFAEBB /* PNDeleteMessageAPICallBuilder.h in Headers */, - A5CE35652959C45B0038FD6F /* PNMessageType.h in Headers */, A55DAF0B24B1FEC800766EE9 /* PNXML+Private.h in Headers */, A504E15824AA9CFB006DCF5B /* PNFilesAPICallBuilder.h in Headers */, A57A308E238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, @@ -4878,7 +4852,6 @@ 7925DB8C1D3FFCAC00857C0D /* PNLLogger.h in Headers */, 79CFA2BD26DE1C4900D206D4 /* PNPAMToken.h in Headers */, 79A3E4142215699900F2ADB9 /* PNMessageCountAPICallBuilder.h in Headers */, - A5CE35702959C9260038FD6F /* PNMessageType+Private.h in Headers */, A55A866222FD80B9002D0A72 /* PNFetchChannelMetadataAPICallBuilder.h in Headers */, 79ABD8961F01636B007634E0 /* PNTelemetry.h in Headers */, 7988427F1C18F286003E8948 /* PNNumber.h in Headers */, @@ -4925,7 +4898,6 @@ 79AA8ECA26EAB81500ADA747 /* PNConfiguration+Private.h in Headers */, A58975B323005AAC0093BD9A /* PNManageMembershipsStatus.h in Headers */, 79A8BC8D1C58F93900015BDE /* PNPushNotificationsStateModificationParser.h in Headers */, - A5CE356D2959C9260038FD6F /* PNMessageType+Private.h in Headers */, 79A238D11D2E70BD00D080CD /* NSURLSessionConfiguration+PNConfiguration.h in Headers */, 79A8BC681C58F93900015BDE /* PNPresenceChannelGroupHereNowResult.h in Headers */, 7932485F1D874D9F00FBDF36 /* PNPublishSequence.h in Headers */, @@ -5037,7 +5009,6 @@ A55DAEFD24B1FE9E00766EE9 /* PNXML.h in Headers */, A55A87DD22FD8272002D0A72 /* PNBaseObjectsRequest.h in Headers */, A57A308A238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, - A5CE35622959C45B0038FD6F /* PNMessageType.h in Headers */, 79A8BC7E1C58F93900015BDE /* PNHistoryResult.h in Headers */, A57A30EA238DCAAF00DE8C68 /* PNAPNSNotificationTarget+Private.h in Headers */, A55A881C22FD8272002D0A72 /* PNFetchAllChannelsMetadataRequest.h in Headers */, @@ -5203,7 +5174,6 @@ 79AA8ECC26EAB81500ADA747 /* PNConfiguration+Private.h in Headers */, A58975B523005AAC0093BD9A /* PNManageMembershipsStatus.h in Headers */, 79E20D2C1C8B0AD5001BC9CC /* PNPushNotificationsStateModificationParser.h in Headers */, - A5CE356F2959C9260038FD6F /* PNMessageType+Private.h in Headers */, 79A238D31D2E70BD00D080CD /* NSURLSessionConfiguration+PNConfiguration.h in Headers */, 79E20D2B1C8B0A70001BC9CC /* PNPresenceChannelGroupHereNowResult.h in Headers */, 793248611D874D9F00FBDF36 /* PNPublishSequence.h in Headers */, @@ -5315,7 +5285,6 @@ A55DAEFF24B1FE9E00766EE9 /* PNXML.h in Headers */, A55A87DF22FD8272002D0A72 /* PNBaseObjectsRequest.h in Headers */, A57A308C238D751400DE8C68 /* PNMPNSNotificationPayload.h in Headers */, - A5CE35642959C45B0038FD6F /* PNMessageType.h in Headers */, 79CBB11A1BD03DE4001FC34D /* PNConfiguration.h in Headers */, A57A30EC238DCAAF00DE8C68 /* PNAPNSNotificationTarget+Private.h in Headers */, A55A881E22FD8272002D0A72 /* PNFetchAllChannelsMetadataRequest.h in Headers */, @@ -6115,7 +6084,6 @@ A56865702300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEF9233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D8651DC22C950039A264 /* PNSubscribeAPIBuilder.m in Sources */, - A5CE35662959C45B0038FD6F /* PNMessageType.m in Sources */, A5046F2424784CAB0008C81E /* PNObjectsRemoveParser.m in Sources */, A5046F1D24784CAB0008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046F0B24784CAB0008C81E /* PNMembership.m in Sources */, @@ -6347,7 +6315,6 @@ A56865722300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEFB233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D96D1DC2313A0039A264 /* PNSubscribeChannelsOrGroupsAPIBuilder.m in Sources */, - A5CE35682959C45B0038FD6F /* PNMessageType.m in Sources */, A5046EC624784CAA0008C81E /* PNObjectsRemoveParser.m in Sources */, A5046EBF24784CAA0008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046EAD24784CAA0008C81E /* PNMembership.m in Sources */, @@ -6579,7 +6546,6 @@ A56865752300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEFE233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D96F1DC2313B0039A264 /* PNSubscribeChannelsOrGroupsAPIBuilder.m in Sources */, - A5CE356A2959C45B0038FD6F /* PNMessageType.m in Sources */, A5046E6824784CA90008C81E /* PNObjectsRemoveParser.m in Sources */, A5046E6124784CA90008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046E4F24784CA90008C81E /* PNMembership.m in Sources */, @@ -6811,7 +6777,6 @@ A56865712300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEFA233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D96E1DC2313A0039A264 /* PNSubscribeChannelsOrGroupsAPIBuilder.m in Sources */, - A5CE35672959C45B0038FD6F /* PNMessageType.m in Sources */, A5046EF524784CAB0008C81E /* PNObjectsRemoveParser.m in Sources */, A5046EEE24784CAB0008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046EDC24784CAB0008C81E /* PNMembership.m in Sources */, @@ -7043,7 +7008,6 @@ A56865732300709F0014E17C /* PNFetchMembershipsResult.m in Sources */, A56FAEFC233161570072ADD6 /* PubNub+MessageActions.m in Sources */, 79A0D9711DC2313C0039A264 /* PNSubscribeChannelsOrGroupsAPIBuilder.m in Sources */, - A5CE35692959C45B0038FD6F /* PNMessageType.m in Sources */, A5046E9724784CAA0008C81E /* PNObjectsRemoveParser.m in Sources */, A5046E9024784CAA0008C81E /* PNRemoveUUIDMetadataRequest.m in Sources */, A5046E7E24784CAA0008C81E /* PNMembership.m in Sources */, diff --git a/Framework/PubNub/PubNub.h b/Framework/PubNub/PubNub.h index 3f5960cd8..0bf203d24 100644 --- a/Framework/PubNub/PubNub.h +++ b/Framework/PubNub/PubNub.h @@ -55,7 +55,6 @@ FOUNDATION_EXPORT const unsigned char PubNubVersionString[]; #import "PNStatus.h" // Models -#import "PNMessageType.h" #import "PNSpaceId.h" // API diff --git a/PubNub/Core/PubNub+Files.h b/PubNub/Core/PubNub+Files.h index ec5b7afa9..ed21c8759 100644 --- a/PubNub/Core/PubNub+Files.h +++ b/PubNub/Core/PubNub+Files.h @@ -3,7 +3,6 @@ #import "PNDeleteFileRequest.h" #import "PNListFilesRequest.h" #import "PNSendFileRequest.h" -#import "PNMessageType.h" #import "PNSpaceId.h" #import "PNFile.h" diff --git a/PubNub/Core/PubNub+Files.m b/PubNub/Core/PubNub+Files.m index 19c8fec77..d3a479d18 100644 --- a/PubNub/Core/PubNub+Files.m +++ b/PubNub/Core/PubNub+Files.m @@ -189,7 +189,7 @@ - (void)sendFileRequestUsingBuilderParameters:(NSDictionary *)parameters { request.cipherKey = cipherKey ?: self.configuration.cipherKey; request.fileMessageMetadata = parameters[NSStringFromSelector(@selector(fileMessageMetadata))]; request.arbitraryQueryParameters = parameters[@"queryParam"]; - request.messageType = parameters[NSStringFromSelector(@selector(messageType))]; + request.type = parameters[NSStringFromSelector(@selector(type))]; request.spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; request.message = parameters[NSStringFromSelector(@selector(message))]; @@ -508,7 +508,7 @@ - (void)handleUploadFileSuccessWithFileIdentifier:(NSString *)fileIdentifier request.arbitraryQueryParameters = sendFileRequest.arbitraryQueryParameters; request.metadata = sendFileRequest.fileMessageMetadata; - request.messageType = sendFileRequest.messageType; + request.type = sendFileRequest.type; request.store = sendFileRequest.fileMessageStore; request.spaceId = sendFileRequest.spaceId; request.message = sendFileRequest.message; diff --git a/PubNub/Core/PubNub+History.m b/PubNub/Core/PubNub+History.m index 44b78dfb8..5ed345cdc 100644 --- a/PubNub/Core/PubNub+History.m +++ b/PubNub/Core/PubNub+History.m @@ -43,6 +43,8 @@ @interface PubNub (HistoryProtected) * not. * @param includeMessageType Whether event type should be included in response or not. * By default set to: \b YES. + * @param includeType Whether user-provided event type should be included in response or not. + * By default set to: \b YES. * @param includeSpaceId Whether identifier of space to which event has been sent should be included or not. * @param includeUUID Whether event publisher UUID should be included in response or not. * By default set to: \b YES. @@ -62,6 +64,7 @@ - (void)historyForChannels:(BOOL)multipleChannels reverse:(nullable NSNumber *)shouldReverseOrder includeTimeToken:(nullable NSNumber *)shouldIncludeTimeToken includeMessageType:(nullable NSNumber *)includeMessageType + includeType:(nullable NSNumber *)includeType includeSpaceId:(nullable NSNumber *)includeSpaceId includeUUID:(nullable NSNumber *)includeUUID includeMessageActions:(nullable NSNumber *)shouldIncludeMessageActions @@ -155,6 +158,7 @@ @implementation PubNub (History) NSNumber *reverse = parameters[NSStringFromSelector(@selector(reverse))]; NSNumber *includeTimeToken = parameters[NSStringFromSelector(@selector(includeTimeToken))]; NSNumber *includeMessageType = parameters[NSStringFromSelector(@selector(includeMessageType))]; + NSNumber *includeType = parameters[NSStringFromSelector(@selector(includeType))]; NSNumber *includeSpaceId = parameters[NSStringFromSelector(@selector(includeSpaceId))]; NSNumber *includeUUID = parameters[NSStringFromSelector(@selector(includeUUID))]; NSNumber *includeMetadata = parameters[NSStringFromSelector(@selector(includeMetadata))]; @@ -170,6 +174,7 @@ @implementation PubNub (History) reverse:reverse includeTimeToken:includeTimeToken includeMessageType:includeMessageType + includeType:includeType includeSpaceId:includeSpaceId includeUUID:includeUUID includeMessageActions:includeActions @@ -320,6 +325,7 @@ - (void)historyForChannel:(NSString *)channel reverse:@NO includeTimeToken:@NO includeMessageType:@YES + includeType:@YES includeSpaceId:@NO includeUUID:@YES includeMessageActions:@(shouldIncludeMessageActions) @@ -408,6 +414,7 @@ - (void)historyForChannel:(NSString *)channel reverse:@(shouldReverseOrder) includeTimeToken:@(shouldIncludeTimeToken) includeMessageType:@YES + includeType:@YES includeSpaceId:@NO includeUUID:@YES includeMessageActions:nil @@ -424,6 +431,7 @@ - (void)historyForChannels:(BOOL)multipleChannels reverse:(NSNumber *)shouldReverseOrder includeTimeToken:(NSNumber *)shouldIncludeTimeToken includeMessageType:(NSNumber *)includeMessageType + includeType:(NSNumber *)includeType includeSpaceId:(NSNumber *)includeSpaceId includeUUID:(NSNumber *)includeUUID includeMessageActions:(NSNumber *)shouldIncludeMessageActions @@ -443,10 +451,14 @@ - (void)historyForChannels:(BOOL)multipleChannels if (!limit || limit.unsignedIntValue == 0) { limit = nil; } - + if (!includeMessageType) { includeMessageType = @YES; } + + if (!includeType) { + includeType = @YES; + } if (!includeSpaceId) { includeSpaceId = @NO; @@ -519,7 +531,7 @@ - (void)historyForChannels:(BOOL)multipleChannels if (operation == PNHistoryWithActionsOperation || multipleChannels) { [parameters addQueryParameter:(includeMessageType.boolValue ? @"true" : @"false") forFieldName:@"include_message_type"]; - [parameters addQueryParameter:(includeMessageType.boolValue ? @"true" : @"false") + [parameters addQueryParameter:(includeType.boolValue ? @"true" : @"false") forFieldName:@"include_type"]; [parameters addQueryParameter:(includeSpaceId.boolValue ? @"true" : @"false") forFieldName:@"include_space_id"]; @@ -584,6 +596,7 @@ - (void)historyForChannels:(BOOL)multipleChannels reverse:shouldReverseOrder includeTimeToken:shouldIncludeTimeToken includeMessageType:includeMessageType + includeType:includeType includeSpaceId:includeSpaceId includeUUID:includeUUID includeMessageActions:shouldIncludeMessageActions diff --git a/PubNub/Core/PubNub+Publish.h b/PubNub/Core/PubNub+Publish.h index b2db8a6f8..5cbe88f3b 100644 --- a/PubNub/Core/PubNub+Publish.h +++ b/PubNub/Core/PubNub+Publish.h @@ -3,7 +3,6 @@ #import "PNPublishFileMessageRequest.h" #import "PNPublishRequest.h" -#import "PNMessageType.h" #import "PNSpaceId.h" #import "PNPublishFileMessageAPICallBuilder.h" diff --git a/PubNub/Core/PubNub+Publish.m b/PubNub/Core/PubNub+Publish.m index 307f9ccc8..7df188ec7 100644 --- a/PubNub/Core/PubNub+Publish.m +++ b/PubNub/Core/PubNub+Publish.m @@ -51,7 +51,7 @@ @interface PubNub (PublishProtected) * @since 4.8.2 */ - (void)publish:(nullable id)message - withType:(nullable PNMessageType *)type + withType:(nullable NSString *)type toChannel:(NSString *)channel spaceId:(nullable PNSpaceId *)spaceId mobilePushPayload:(nullable NSDictionary *)payloads @@ -74,7 +74,7 @@ - (void)publish:(nullable id)message * * @param message Object (\a NSString, \a NSNumber, \a NSArray, \a NSDictionary) which will be * sent with signal. - * @param messageType Type with which signal should be published. + * @param type Type with which signal should be published. * @param channel Name of the channel to which signal should be sent. * @param spaceId Identifier of space to which signal should be published. * @param queryParameters List arbitrary query parameters which should be sent along with original @@ -84,7 +84,7 @@ - (void)publish:(nullable id)message * @since 4.9.0 */ - (void)signal:(id)message - withType:(nullable PNMessageType *)messageType + withType:(nullable NSString *)type channel:(NSString *)channel spaceId:(nullable PNSpaceId *)spaceId withQueryParameters:(nullable NSDictionary *)queryParameters @@ -118,7 +118,7 @@ - (void)signal:(id)message * @since 4.8.2 */ - (void)sizeOfMessage:(id)message - withType:(nullable PNMessageType *)type + withType:(nullable NSString *)type toChannel:(NSString *)channel spaceId:(nullable PNSpaceId *)spaceId compressed:(BOOL)compressMessage @@ -174,7 +174,7 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags * @since 4.0 */ - (PNRequestParameters *)requestParametersForMessage:(NSString *)message - withType:(nullable PNMessageType *)type + withType:(nullable NSString *)type toChannel:(NSString *)channel spaceId:(nullable PNSpaceId *)spaceId compressed:(BOOL)compressMessage @@ -257,7 +257,7 @@ @implementation PubNub (Publish) PNPublishFileMessageRequest *request = [PNPublishFileMessageRequest requestWithChannel:channel fileIdentifier:identifier name:filename]; - request.messageType = parameters[NSStringFromSelector(@selector(messageType))]; + request.type = parameters[NSStringFromSelector(@selector(type))]; request.metadata = parameters[NSStringFromSelector(@selector(metadata))]; request.spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; request.message = parameters[NSStringFromSelector(@selector(message))]; @@ -295,7 +295,7 @@ @implementation PubNub (Publish) request.metadata = parameters[NSStringFromSelector(@selector(metadata))]; request.payloads = parameters[NSStringFromSelector(@selector(payloads))]; request.message = parameters[NSStringFromSelector(@selector(message))]; - request.messageType = parameters[NSStringFromSelector(@selector(messageType))]; + request.type = parameters[NSStringFromSelector(@selector(type))]; request.arbitraryQueryParameters = parameters[@"queryParam"]; request.store = (shouldStore ? shouldStore.boolValue : YES); request.replicate = (replicate ? replicate.boolValue : YES); @@ -336,14 +336,14 @@ @implementation PubNub (Publish) NSDictionary *parameters) { id message = parameters[NSStringFromSelector(@selector(message))]; - PNMessageType *messageType = parameters[NSStringFromSelector(@selector(messageType))]; + NSString *type = parameters[NSStringFromSelector(@selector(type))]; NSString *channel = parameters[NSStringFromSelector(@selector(channel))]; PNSpaceId *spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; NSDictionary *queryParam = parameters[@"queryParam"]; id block = parameters[@"block"]; [weakSelf signal:message - withType:messageType + withType:type channel:channel spaceId:spaceId withQueryParameters:queryParam @@ -361,7 +361,7 @@ @implementation PubNub (Publish) NSDictionary *parameters) { id message = parameters[NSStringFromSelector(@selector(message))]; - PNMessageType *messageType = parameters[NSStringFromSelector(@selector(messageType))]; + NSString *type = parameters[NSStringFromSelector(@selector(type))]; NSString *channel = parameters[NSStringFromSelector(@selector(channel))]; PNSpaceId *spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; NSNumber *shouldStore = parameters[NSStringFromSelector(@selector(shouldStore))]; @@ -377,7 +377,7 @@ @implementation PubNub (Publish) } [self sizeOfMessage:message - withType:messageType + withType:type toChannel:channel spaceId:spaceId compressed:compressed.boolValue @@ -442,8 +442,7 @@ - (void)publishWithRequest:(PNPublishRequest *)request completion:(PNPublishComp PNLogAPICall(self.logger, @" Publish%@ message%@ to '%@' channel%@%@%@%@", (request.shouldCompress ? @" compressed" : @""), - (request.messageType ? [NSString stringWithFormat:@" of '%@' type", - request.messageType.value] : @""), + (request.type ? [NSString stringWithFormat:@" of '%@' type", request.type] : @""), (request.channel ?: @""), (request.spaceId ? [NSString stringWithFormat:@" (space id: %@)", request.spaceId.value] : @""), @@ -695,7 +694,7 @@ - (void)publish:(id)message } - (void)publish:(id)message - withType:(PNMessageType *)messageType + withType:(NSString *)type toChannel:(NSString *)channel spaceId:(PNSpaceId *)spaceId mobilePushPayload:(NSDictionary *)payloads @@ -717,7 +716,7 @@ - (void)publish:(id)message request.payloads = payloads; request.store = shouldStore; request.message = message; - request.messageType = messageType; + request.type = type; [self publishWithRequest:request completion:block]; } @@ -733,7 +732,7 @@ - (void)signal:(id)message } - (void)signal:(id)message - withType:(PNMessageType *)messageType + withType:(NSString *)type channel:(NSString *)channel spaceId:(PNSpaceId *)spaceId withQueryParameters:(NSDictionary *)queryParameters @@ -771,8 +770,8 @@ - (void)signal:(id)message forPlaceholder:@"{message}"]; } - if (messageType) { - [parameters addQueryParameter:messageType.value forFieldName:@"type"]; + if (type) { + [parameters addQueryParameter:type forFieldName:@"type"]; } PNLogAPICall(strongSelf.logger, @" Signal to '%@' channel.", @@ -786,7 +785,7 @@ - (void)signal:(id)message if (status.isError) { status.retryBlock = ^{ [weakSelf signal:message - withType:messageType + withType:type channel:channel spaceId:spaceId withQueryParameters:queryParameters @@ -908,7 +907,7 @@ - (void)sizeOfMessage:(id)message } - (void)sizeOfMessage:(id)message - withType:(PNMessageType *)messageType + withType:(NSString *)type toChannel:(NSString *)channel spaceId:(PNSpaceId *)spaceId compressed:(BOOL)compressMessage @@ -956,7 +955,7 @@ - (void)sizeOfMessage:(id)message } PNRequestParameters *parameters = [self requestParametersForMessage:messageForPublish - withType:messageType + withType:type toChannel:channel spaceId:spaceId compressed:compressMessage @@ -991,7 +990,7 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags parameters:(NSDictionary *)parameters { id message = parameters[NSStringFromSelector(@selector(message))]; - PNMessageType *messageType = parameters[NSStringFromSelector(@selector(messageType))]; + NSString *type = parameters[NSStringFromSelector(@selector(type))]; NSString *channel = parameters[NSStringFromSelector(@selector(channel))]; PNSpaceId *spaceId = parameters[NSStringFromSelector(@selector(spaceId))]; NSDictionary *payloads = parameters[NSStringFromSelector(@selector(payloads))]; @@ -1003,7 +1002,7 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags NSDictionary *metadata = parameters[NSStringFromSelector(@selector(metadata))]; [self publish:message - withType:messageType + withType:type toChannel:channel spaceId:spaceId mobilePushPayload:payloads @@ -1020,7 +1019,7 @@ - (void)handlePublishBuilderExecutionWithFlags:(NSArray *)flags #pragma mark - Misc - (PNRequestParameters *)requestParametersForMessage:(NSString *)message - withType:(PNMessageType *)messageType + withType:(NSString *)type toChannel:(NSString *)channel spaceId:(PNSpaceId *)spaceId compressed:(BOOL)compressMessage @@ -1061,8 +1060,8 @@ - (PNRequestParameters *)requestParametersForMessage:(NSString *)message [parameters addPathComponent:targetMessage forPlaceholder:@"{message}"]; } - if (messageType) { - [parameters addQueryParameter:messageType.value forFieldName:@"type"]; + if (type) { + [parameters addQueryParameter:type forFieldName:@"type"]; } if ([metadata isKindOfClass:[NSString class]] && metadata.length) { diff --git a/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.h b/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.h index 77b7d06c4..ed6e89250 100644 --- a/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.h @@ -5,7 +5,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark Class forward -@class PNSpaceId, PNMessageType; +@class PNSpaceId; #pragma mark - Interface declaration @@ -104,13 +104,13 @@ NS_ASSUME_NONNULL_BEGIN /** * @brief Type of message which will be published. * - * @param type Custom type for published message. + * @param type User-provided type for published message. * * @return API call configuration builder. * * @version 5.2.0 */ -@property (nonatomic, readonly, strong) PNSendFileAPICallBuilder * (^messageType)(PNMessageType *type); +@property (nonatomic, readonly, strong) PNSendFileAPICallBuilder * (^type)(NSString *type); /** * @brief In-memory binary data which should be uploaded and available in target channel. diff --git a/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.m b/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.m index e1011bf25..08dedd86e 100644 --- a/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Files/PNSendFileAPICallBuilder.m @@ -82,9 +82,9 @@ @implementation PNSendFileAPICallBuilder }; } -- (PNSendFileAPICallBuilder * (^)(PNMessageType *messageType))messageType { - return ^PNSendFileAPICallBuilder * (PNMessageType *messageType) { - [self setValue:messageType forParameter:NSStringFromSelector(_cmd)]; +- (PNSendFileAPICallBuilder * (^)(NSString *type))type { + return ^PNSendFileAPICallBuilder * (NSString *type) { + [self setValue:type forParameter:NSStringFromSelector(_cmd)]; return self; }; } diff --git a/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h b/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h index aa875a3da..2cbd6ed8a 100644 --- a/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.h @@ -121,6 +121,22 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNHistoryAPICallBuilder * (^includeMessageType)(BOOL includeMessageType); +/** + * @brief Events' user-provided type presence flag. + * + * @note Available only when message fetched for multiple channels or should include message actions. + * @note Each fetched entry will contain published data under 'message' key and published message + * \c message \c type will be available under 'type' key. + * + * @param includeType Whether user-provided type should be included in response or not. + * By default set to: \b YES. + * + * @return API call configuration builder. + * + * @since 5.2.0 + */ +@property (nonatomic, readonly, strong) PNHistoryAPICallBuilder * (^includeType)(BOOL includeType); + /** * @brief Events' space presence flag. * diff --git a/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.m b/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.m index b97af1c83..792327055 100644 --- a/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/History/PNHistoryAPICallBuilder.m @@ -76,6 +76,13 @@ @implementation PNHistoryAPICallBuilder }; } +- (PNHistoryAPICallBuilder * _Nonnull (^)(BOOL includeType))includeType { + return ^PNHistoryAPICallBuilder * (BOOL includeType) { + [self setValue:@(includeType) forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNHistoryAPICallBuilder * _Nonnull (^)(BOOL includeSpaceId))includeSpaceId { return ^PNHistoryAPICallBuilder * (BOOL includeSpaceId) { [self setValue:@(includeSpaceId) forParameter:NSStringFromSelector(_cmd)]; diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h b/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h index c4ac94744..5794b221b 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.h @@ -4,7 +4,7 @@ #pragma mark Class forward -@class PNMessageType, PNSpaceId; +@class PNSpaceId; NS_ASSUME_NONNULL_BEGIN @@ -64,13 +64,13 @@ NS_ASSUME_NONNULL_BEGIN /** * @brief Type of message which will be published. * - * @param type Custom type for published message. + * @param type User-provided type for published message. * * @return API call configuration builder. * * @version 5.2.0 */ -@property (nonatomic, readonly, strong) PNPublishAPICallBuilder * (^messageType)(PNMessageType *type); +@property (nonatomic, readonly, strong) PNPublishAPICallBuilder * (^type)(NSString *type); /** * @brief Message metadata addition block. diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m b/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m index 09d4beaa2..93fb2b28c 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishAPICallBuilder.m @@ -41,9 +41,9 @@ @implementation PNPublishAPICallBuilder }; } -- (PNPublishAPICallBuilder * (^)(PNMessageType *messageType))messageType { - return ^PNPublishAPICallBuilder * (PNMessageType *messageType) { - [self setValue:messageType forParameter:NSStringFromSelector(_cmd)]; +- (PNPublishAPICallBuilder * (^)(NSString *messageType))type { + return ^PNPublishAPICallBuilder * (NSString *type) { + [self setValue:type forParameter:NSStringFromSelector(_cmd)]; return self; }; } diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.h b/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.h index d409807f5..785f274f9 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.h @@ -4,7 +4,7 @@ #pragma mark Class forward -@class PNMessageType, PNSpaceId; +@class PNSpaceId; NS_ASSUME_NONNULL_BEGIN @@ -77,13 +77,13 @@ NS_ASSUME_NONNULL_BEGIN /** * @brief Type of message which will be published. * - * @param type Custom type for published message. + * @param type User-provided type for published message. * * @return API call configuration builder. * * @version 5.2.0 */ -@property (nonatomic, readonly, strong) PNPublishFileMessageAPICallBuilder * (^messageType)(PNMessageType *type); +@property (nonatomic, readonly, strong) PNPublishFileMessageAPICallBuilder * (^type)(NSString *type); /** * @brief Message metadata. diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.m b/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.m index 72692341b..5e313e4fd 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishFileMessageAPICallBuilder.m @@ -64,9 +64,9 @@ @implementation PNPublishFileMessageAPICallBuilder }; } -- (PNPublishFileMessageAPICallBuilder * (^)(PNMessageType *messageType))messageType { - return ^PNPublishFileMessageAPICallBuilder * (PNMessageType *messageType) { - [self setValue:messageType forParameter:NSStringFromSelector(_cmd)]; +- (PNPublishFileMessageAPICallBuilder * (^)(NSString *type))type { + return ^PNPublishFileMessageAPICallBuilder * (NSString *type) { + [self setValue:type forParameter:NSStringFromSelector(_cmd)]; return self; }; } diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishSizeAPICallBuilder.h b/PubNub/Data/Builders/API Call/Publish/PNPublishSizeAPICallBuilder.h index 244afafe6..490f1f59c 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishSizeAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishSizeAPICallBuilder.h @@ -2,6 +2,11 @@ #import "PNStructures.h" +#pragma mark Class forward + +@class PNSpaceId; + + NS_ASSUME_NONNULL_BEGIN #pragma mark Interface declaration @@ -29,6 +34,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNPublishSizeAPICallBuilder * (^channel)(NSString *channel); +/** + * @brief Target space identifier name. + * + * @param spaceId Identifier of the space to which signal should be published. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNPublishSizeAPICallBuilder * (^spaceId)(PNSpaceId *spaceId); + /** * @brief Message payload addition block. * @@ -44,6 +60,17 @@ NS_ASSUME_NONNULL_BEGIN */ @property (nonatomic, readonly, strong) PNPublishSizeAPICallBuilder * (^message)(id message); +/** + * @brief Type of signal which will be published. + * + * @param type User-provided type for published signal. + * + * @return API call configuration builder. + * + * @version 5.2.0 + */ +@property (nonatomic, readonly, strong) PNPublishSizeAPICallBuilder * (^type)(NSString *type); + /** * @brief Message metadata addition block. * diff --git a/PubNub/Data/Builders/API Call/Publish/PNPublishSizeAPICallBuilder.m b/PubNub/Data/Builders/API Call/Publish/PNPublishSizeAPICallBuilder.m index 5a031b655..421971b58 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNPublishSizeAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Publish/PNPublishSizeAPICallBuilder.m @@ -20,21 +20,33 @@ @implementation PNPublishSizeAPICallBuilder #pragma mark - Configuration - (PNPublishSizeAPICallBuilder * (^)(NSString *channel))channel { - return ^PNPublishSizeAPICallBuilder * (NSString *channel) { [self setValue:channel forParameter:NSStringFromSelector(_cmd)]; return self; }; } +- (PNPublishSizeAPICallBuilder * _Nonnull (^)(PNSpaceId *spaceId))spaceId { + return ^PNPublishSizeAPICallBuilder * (PNSpaceId *spaceId) { + [self setValue:spaceId forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNPublishSizeAPICallBuilder * (^)(id message))message { - return ^PNPublishSizeAPICallBuilder * (id message) { [self setValue:message forParameter:NSStringFromSelector(_cmd)]; return self; }; } +- (PNPublishSizeAPICallBuilder * _Nonnull (^)(NSString *type))type { + return ^PNPublishSizeAPICallBuilder * (NSString *type) { + [self setValue:type forParameter:NSStringFromSelector(_cmd)]; + return self; + }; +} + - (PNPublishSizeAPICallBuilder * (^)(NSDictionary *metadata))metadata { return ^PNPublishSizeAPICallBuilder * (NSDictionary *metadata) { diff --git a/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h b/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h index b6771f736..121241480 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h +++ b/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.h @@ -4,7 +4,8 @@ #pragma mark Class forward -@class PNMessageType, PNSpaceId; +@class PNSpaceId; + NS_ASSUME_NONNULL_BEGIN @@ -59,13 +60,13 @@ NS_ASSUME_NONNULL_BEGIN /** * @brief Type of signal which will be published. * - * @param type Custom type for published signal. + * @param type User-provided type for published signal. * * @return API call configuration builder. * * @version 5.2.0 */ -@property (nonatomic, readonly, strong) PNSignalAPICallBuilder * (^messageType)(PNMessageType *type); +@property (nonatomic, readonly, strong) PNSignalAPICallBuilder * (^type)(NSString *type); #pragma mark - Execution diff --git a/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m b/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m index 2874d26e5..7505c94f4 100644 --- a/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m +++ b/PubNub/Data/Builders/API Call/Publish/PNSignalAPICallBuilder.m @@ -44,9 +44,9 @@ @implementation PNSignalAPICallBuilder }; } -- (PNSignalAPICallBuilder * (^)(PNMessageType * messageType))messageType { - return ^PNSignalAPICallBuilder * (PNMessageType *messageType) { - [self setValue:messageType forParameter:NSStringFromSelector(_cmd)]; +- (PNSignalAPICallBuilder * (^)(NSString * type))type { + return ^PNSignalAPICallBuilder * (NSString *type) { + [self setValue:type forParameter:NSStringFromSelector(_cmd)]; return self; }; } diff --git a/PubNub/Data/Managers/PNSubscriber.m b/PubNub/Data/Managers/PNSubscriber.m index 13e78262c..7435e74fd 100644 --- a/PubNub/Data/Managers/PNSubscriber.m +++ b/PubNub/Data/Managers/PNSubscriber.m @@ -1532,7 +1532,7 @@ - (void)handleLiveFeedEvents:(PNSubscribeStatus *)status forInitialSubscription: [self handleNewPresenceEvent:((PNPresenceEventResult *)eventResultObject)]; } else { PNEnvelopeInformation *envelope = event[@"envelope"]; - PNServiceMessageType messageType = envelope.pubNubMessageType; + PNServiceMessageType messageType = envelope.messageType; if (messageType == PNObjectMessageType) { [self handleNewObjectsEvent:eventResultObject]; @@ -1741,7 +1741,7 @@ - (void)deDuplicateMessages:(NSMutableArray *)events { NSMutableIndexSet *duplicateMessagesIndices = [NSMutableIndexSet indexSet]; [events enumerateObjectsUsingBlock:^(NSDictionary *event, NSUInteger eventIdx, BOOL *eventsEnumeratorStop) { - PNServiceMessageType messageType = ((PNEnvelopeInformation *)event[@"envelope"]).pubNubMessageType; + PNServiceMessageType messageType = ((PNEnvelopeInformation *)event[@"envelope"]).messageType; BOOL isMessageEvent = (messageType != PNFileMessageType && messageType != PNObjectMessageType && messageType != PNMessageActionType); diff --git a/PubNub/Data/Models/PNMessageType+Private.h b/PubNub/Data/Models/PNMessageType+Private.h deleted file mode 100644 index 6c63d9fe2..000000000 --- a/PubNub/Data/Models/PNMessageType+Private.h +++ /dev/null @@ -1,38 +0,0 @@ -#import "PNMessageType.h" -#import "PNPrivateStructures.h" - - -NS_ASSUME_NONNULL_BEGIN - -#pragma mark Interface extension declaration - -/** - * @brief Extension for public interface for parsers support. - * - * @author Serhii Mamontov - * @version 5.2.0 - * @since 5.2.0 - * @copyright © 2010-2022 PubNub Inc. All Rights Reserved. - */ -@interface PNMessageType (Private) - - -#pragma mark - Initialization and configuration - -/** - * @brief Create and configure message type based on type provided by \b PubNub and user. - * - * @param userMessageType Custom message type which should be used when publish message. - * @param pubNubMessageType One of pre-defined message / event types. - * - * @return Configured and ready to use message type instance. - */ -+ (instancetype)messageTypeFromString:(NSString *)userMessageType - pubNubMessageType:(PNServiceMessageType)pubNubMessageType; - -#pragma mark - - - -@end - -NS_ASSUME_NONNULL_END diff --git a/PubNub/Data/Models/PNMessageType.h b/PubNub/Data/Models/PNMessageType.h deleted file mode 100644 index e18f830fa..000000000 --- a/PubNub/Data/Models/PNMessageType.h +++ /dev/null @@ -1,76 +0,0 @@ -#import - - -NS_ASSUME_NONNULL_BEGIN - -#pragma mark Interface declaration - -/** - * @brief Published message representation model. - * - * @discussion This type let identify message received from subscriber later. - * There is five types which is set by \b PubNub service depending from used API endpoint: - * - \c message - * - \c signal - * - \c object - * - \c messageAction - * - \c file - * - * Additionally it is possible to specify custom type for published message using \b PNMessageType method - * - * @author Serhii Mamontov - * @version 5.2.0 - * @since 5.2.0 - * @copyright © 2010-2022 PubNub Inc. All Rights Reserved. - */ -@interface PNMessageType : NSObject - - -#pragma mark - Information - -/** - * @brief One of types associated with message when it has been published. - * - * @discussion This property may store \b PubNub defined types (like: message, signal, file, object, messageAction - */ -@property(nonatomic, readonly, copy) NSString *value; - - -#pragma mark - Initialization and configuration - -/** - * @brief Create and configure message type instance. - * - * @param type Custom message type which should be used when publish message. - * - * @return Configured and ready to use message type instance. - */ -+ (instancetype)messageTypeFromString:(NSString *)type; - -/** - * @brief Initialize message type instance. - * - * @note This method can't be used directly and will throw an exception. - * - * @return Message type instance. - */ -- (nullable instancetype)init NS_UNAVAILABLE; - - -#pragma mark - Helper - -/** - * @brief Check whether receiving message type is equal to another instance. - * - * @param otherMessageType Second instance against which check should be done. - * - * @return \c YES if \c otherMessageType is equal to receiver. - */ -- (BOOL)isEqualToMessageType:(PNMessageType *)otherMessageType; - -#pragma mark - - - -@end - -NS_ASSUME_NONNULL_END diff --git a/PubNub/Data/Models/PNMessageType.m b/PubNub/Data/Models/PNMessageType.m deleted file mode 100644 index cc9935be9..000000000 --- a/PubNub/Data/Models/PNMessageType.m +++ /dev/null @@ -1,119 +0,0 @@ -/** - * @author Serhii Mamontov - * @version 5.2.0 - * @since 5.2.0 - * @copyright © 2010-2022 PubNub Inc. All Rights Reserved. - */ -#import "PNMessageType+Private.h" - - -NS_ASSUME_NONNULL_BEGIN - -#pragma mark Protected interface declaration - -@interface PNMessageType () - -/** - * @brief One of types associated with message when it has been published. - * - * @discussion This property may store \b PubNub defined types (like: message, signal, file, object, messageAction - */ -@property(nonatomic, copy) NSString *value; - - -#pragma mark - Initialization and configuration - -/** - * @brief Create and configure instance from actual value. - * - * @param value Custom user type of stringified \b PubNub provided type. - */ -- (instancetype)initWithValueFromString:(NSString *)value NS_DESIGNATED_INITIALIZER; - - -#pragma mark - Helper - -/** - * @brief Transform provided data to string. - * - * @param userType User-provided type which should be used for message type. - * @param pnType \b PubNub provided message type which should be stringified. - * - * @return Proper message type which will be used by user and publish endpoints. - */ -+ (NSString *)valueFromUserType:(nullable NSString *)userType - pubNubMessageType:(PNServiceMessageType)pnType; - -#pragma mark - - - -@end - -NS_ASSUME_NONNULL_END - - -#pragma mark - Interface implementation - -@implementation PNMessageType - - -#pragma mark - Initialization and configuration - -+ (instancetype)messageTypeFromString:(NSString *)type { - return [self messageTypeFromString:type pubNubMessageType:PNRegularMessageType]; -} - -+ (instancetype)messageTypeFromString:(NSString *)userType pubNubMessageType:(PNServiceMessageType)pnType { - return [[self alloc] initWithValueFromString:[self valueFromUserType:userType pubNubMessageType:pnType]]; -} - -- (instancetype)init { - NSDictionary *errorInformation = @{ NSLocalizedRecoverySuggestionErrorKey: @"Use provided constructor" }; - @throw [NSException exceptionWithName:@"PNInterfaceNotAvailable" - reason:@"+new or -init methods unavailable." - userInfo:errorInformation]; - - return nil; -} - -- (instancetype)initWithValueFromString:(NSString *)value { - if ((self = [super init])) { - _value = [value copy]; - } - - return self; -} - - -#pragma mark - NSCopying - -- (id)copyWithZone:(NSZone *)zone { - return [[PNMessageType alloc] initWithValueFromString:self.value]; -} - - -#pragma mark - Helper - -- (BOOL)isEqual:(id)other { - return other && [other isKindOfClass:[self class]] ? [self isEqualToMessageType:other] : NO; -} - -- (BOOL)isEqualToMessageType:(PNMessageType *)otherMessageType { - return [self.value isEqualToString:otherMessageType.value]; -} - -+ (NSString *)valueFromUserType:(NSString *)userMessageType pubNubMessageType:(PNServiceMessageType)pubNubMessageType { - static NSArray *_pubNubMessageTypeMap; - static dispatch_once_t onceToken; - - dispatch_once(&onceToken, ^{ - _pubNubMessageTypeMap = @[@"pn_message", @"pn_signal", @"pn_object", @"pn_messageAction", @"pn_file"]; - }); - - return userMessageType.length ? userMessageType : _pubNubMessageTypeMap[pubNubMessageType]; -} - -#pragma mark - - - -@end diff --git a/PubNub/Data/PNEnvelopeInformation.h b/PubNub/Data/PNEnvelopeInformation.h index 53ce05adf..c48596cb9 100644 --- a/PubNub/Data/PNEnvelopeInformation.h +++ b/PubNub/Data/PNEnvelopeInformation.h @@ -4,7 +4,7 @@ #pragma mark Class forward -@class PNMessageType, PNSpaceId; +@class PNSpaceId; /** @@ -53,14 +53,14 @@ * * @since 5.2.0 */ -@property (atomic, readonly, assign) PNServiceMessageType pubNubMessageType; +@property (atomic, readonly, assign) PNServiceMessageType messageType; /** - * @brief Object's message type. + * @brief Object's user-provided type. * * @since 5.2.0 */ -@property (nonatomic, nullable, readonly, strong) PNMessageType *messageType; +@property (nonatomic, nullable, readonly, strong) NSString *type; /** * @brief Identifier of space from which message has been received. diff --git a/PubNub/Data/PNEnvelopeInformation.m b/PubNub/Data/PNEnvelopeInformation.m index da9624081..e0b209a9c 100644 --- a/PubNub/Data/PNEnvelopeInformation.m +++ b/PubNub/Data/PNEnvelopeInformation.m @@ -5,7 +5,6 @@ @copyright © 2010-2019 PubNub Inc. */ #import "PNEnvelopeInformation.h" -#import "PNMessageType+Private.h" #import "PNSpaceId.h" #import "PNJSON.h" @@ -45,10 +44,10 @@ /** * @brief Key under which stored \b PubNub defined object's message type. */ - __unsafe_unretained NSString *pubNubMessageTypeKey; + __unsafe_unretained NSString *messageTypeKey; /** - * @brief Key under which stored user-defined object's message type. + * @brief Key under which stored user-provided object's message type. */ __unsafe_unretained NSString *userMessageTypeKey; @@ -84,7 +83,7 @@ .senderIdentifier = @"i", .sequenceNumber = @"s", .subscribeKey = @"k", - .pubNubMessageTypeKey = @"e", + .messageTypeKey = @"e", .userMessageTypeKey = @"mt", .spaceIdKey = @"si", .replicationMap = @"r", @@ -108,8 +107,8 @@ @interface PNEnvelopeInformation () @property (nonatomic, copy) NSString *senderIdentifier; @property (nonatomic, copy) NSNumber *sequenceNumber; @property (nonatomic, copy) NSString *subscribeKey; -@property (atomic, assign) PNServiceMessageType pubNubMessageType; -@property (nonatomic, nullable, strong) PNMessageType *messageType; +@property (atomic, assign) PNServiceMessageType messageType; +@property (nonatomic, nullable, strong) NSString *type; @property (nonatomic, nullable, strong) PNSpaceId *spaceId; @property (nonatomic, copy) NSNumber *replicationMap; @property (nonatomic, copy) NSNumber *eatAfterReading; @@ -159,9 +158,8 @@ - (nonnull instancetype)initWithPayload:(nonnull NSDictionary *)payload { _metadata = [payload[PNDebugEventEnvelope.metadata] copy]; _waypoints = [payload[PNDebugEventEnvelope.waypoints] copy]; - _pubNubMessageType = ((NSNumber *)payload[PNDebugEventEnvelope.pubNubMessageTypeKey]).unsignedIntegerValue; - NSString *userMessageType = payload[PNDebugEventEnvelope.userMessageTypeKey]; - _messageType = [PNMessageType messageTypeFromString:userMessageType pubNubMessageType:_pubNubMessageType]; + _messageType = ((NSNumber *)payload[PNDebugEventEnvelope.messageTypeKey]).unsignedIntegerValue; + _type = payload[PNDebugEventEnvelope.userMessageTypeKey]; NSString *spaceId = payload[PNDebugEventEnvelope.spaceIdKey]; if (spaceId) { @@ -186,7 +184,8 @@ - (NSDictionary *)dictionaryRepresentation { @"Client Identifier": (self.senderIdentifier?: @""), @"Sequence number": (self.sequenceNumber?: @""), @"Subscribe key": (self.subscribeKey?: @""), - @"Message type": (self.messageType.value ?: @(self.pubNubMessageType)), + @"Message type": @(self.messageType), + @"User-provided type": (self.type ?: @""), @"Replication map": (self.replicationMap?: @""), @"Eat after reading": (self.eatAfterReading ? (self.shouldEatAfterReading ? @"YES" : @"NO") : @""), @"Metadata": (self.metadata ? [PNJSON JSONStringFrom:self.metadata withError:nil] : @""), diff --git a/PubNub/Data/Service Objects/PNResult.m b/PubNub/Data/Service Objects/PNResult.m index 4f4195be7..511cbd340 100644 --- a/PubNub/Data/Service Objects/PNResult.m +++ b/PubNub/Data/Service Objects/PNResult.m @@ -203,11 +203,10 @@ - (NSDictionary *)dictionaryRepresentation { - (NSDictionary *)dictionaryRepresentationFromDictionary:(NSDictionary *)dictionary { NSMutableDictionary *representation = [NSMutableDictionary new]; - Class messageTypeClass = NSClassFromString(@"PNMessageType"); Class spaceIdClass = NSClassFromString(@"PNSpaceId"); [dictionary enumerateKeysAndObjectsUsingBlock:^(NSString *key, id obj, BOOL *stop) { - if ([obj isKindOfClass:messageTypeClass] || [obj isKindOfClass:spaceIdClass]) { + if ([obj isKindOfClass:spaceIdClass]) { representation[key] = [obj valueForKey:@"value"]; } else if ([[obj class] isSubclassOfClass:[NSDictionary class]]) { representation[key] = [self dictionaryRepresentationFromDictionary:obj]; @@ -223,11 +222,10 @@ - (NSDictionary *)dictionaryRepresentationFromDictionary:(NSDictionary *)diction - (NSArray *)arrayRepresentationFromArray:(NSArray *)array { NSMutableArray *representation = [NSMutableArray new]; - Class messageTypeClass = NSClassFromString(@"PNMessageType"); Class spaceIdClass = NSClassFromString(@"PNSpaceId"); [array enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL * _Nonnull stop) { - if ([obj isKindOfClass:messageTypeClass] || [obj isKindOfClass:spaceIdClass]) { + if ([obj isKindOfClass:spaceIdClass]) { if ([obj valueForKey:@"value"]) [representation addObject:[obj valueForKey:@"value"]]; } else if ([[obj class] isSubclassOfClass:[NSDictionary class]]) { [representation addObject:[self dictionaryRepresentationFromDictionary:obj]]; diff --git a/PubNub/Data/Service Objects/PNSubscribeStatus.h b/PubNub/Data/Service Objects/PNSubscribeStatus.h index 754c04202..b66141ee7 100644 --- a/PubNub/Data/Service Objects/PNSubscribeStatus.h +++ b/PubNub/Data/Service Objects/PNSubscribeStatus.h @@ -4,7 +4,7 @@ #pragma mark Class forward -@class PNMessageType, PNSpaceId; +@class PNSpaceId; NS_ASSUME_NONNULL_BEGIN @@ -51,11 +51,11 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, readonly, strong) NSNumber *timetoken; /** - * @brief Type of message which has been published. + * @brief User-provided type of message which has been published. * * @since 5.2.0 */ -@property (nonatomic, nullable, readonly, strong) PNMessageType *messageType; +@property (nonatomic, nullable, readonly, strong) NSString *type; /** * @brief Stores reference on metadata information which has been passed along with received event. diff --git a/PubNub/Data/Service Objects/PNSubscribeStatus.m b/PubNub/Data/Service Objects/PNSubscribeStatus.m index 012dece3c..d5d973540 100644 --- a/PubNub/Data/Service Objects/PNSubscribeStatus.m +++ b/PubNub/Data/Service Objects/PNSubscribeStatus.m @@ -26,8 +26,8 @@ - (PNSpaceId *)spaceId { return self.envelope.spaceId; } -- (PNMessageType *)messageType { - return self.envelope.messageType; +- (NSString *)type { + return self.envelope.type; } - (NSString *)subscription { diff --git a/PubNub/Network/Parsers/PNHistoryParser.m b/PubNub/Network/Parsers/PNHistoryParser.m index 03627d572..be3753758 100644 --- a/PubNub/Network/Parsers/PNHistoryParser.m +++ b/PubNub/Network/Parsers/PNHistoryParser.m @@ -5,7 +5,7 @@ * @copyright © 2010-2019 PubNub, Inc. */ #import "PNHistoryParser.h" -#import "PNMessageType+Private.h" +#import "PNPrivateStructures.h" #import "PubNub+CorePrivate.h" #import "PNSpaceId.h" #import "PNConstants.h" @@ -236,10 +236,12 @@ + (NSMutableDictionary *)processedMessagesFrom:(NSArray *)messages if (timeToken || metadata || actions || pubNubMessageType || userMessageType || spaceId || senderUUID) { NSMutableDictionary *messageWithInfo = [@{ @"message": message } mutableCopy]; - if ([pubNubMessageType isKindOfClass:[NSNumber class]] || - [userMessageType isKindOfClass:[NSString class]]) { - messageWithInfo[@"messageType"] = [PNMessageType messageTypeFromString:userMessageType - pubNubMessageType:pubNubMessageType.unsignedIntValue]; + if ([pubNubMessageType isKindOfClass:[NSNumber class]]) { + messageWithInfo[@"messageType"] = pubNubMessageType; + } + + if ([userMessageType isKindOfClass:[NSString class]]) { + messageWithInfo[@"type"] = userMessageType; } if (spaceId) { diff --git a/PubNub/Network/Parsers/PNSubscribeParser.m b/PubNub/Network/Parsers/PNSubscribeParser.m index d204273cc..bc2a5cd9f 100644 --- a/PubNub/Network/Parsers/PNSubscribeParser.m +++ b/PubNub/Network/Parsers/PNSubscribeParser.m @@ -419,7 +419,7 @@ + (NSMutableDictionary *)eventFromData:(NSDictionary *)data event[@"subscription"] = (subscriptionMatch ?: channel); event[@"channel"] = channel; - PNServiceMessageType messageType = ((PNEnvelopeInformation *)event[@"envelope"]).pubNubMessageType; + PNServiceMessageType messageType = ((PNEnvelopeInformation *)event[@"envelope"]).messageType; BOOL isEncryptionSupported = messageType == PNRegularMessageType || messageType == PNFileMessageType; diff --git a/PubNub/Network/Requests/Files/PNSendFileRequest.h b/PubNub/Network/Requests/Files/PNSendFileRequest.h index 80e700ac0..3a3035212 100644 --- a/PubNub/Network/Requests/Files/PNSendFileRequest.h +++ b/PubNub/Network/Requests/Files/PNSendFileRequest.h @@ -6,7 +6,7 @@ NS_ASSUME_NONNULL_BEGIN #pragma mark Class forward -@class PNSpaceId, PNMessageType; +@class PNSpaceId; #pragma mark - Interface declaration @@ -72,11 +72,11 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nullable, strong) id message; /** - * @brief Custom type with which message should be published. + * @brief User-provided type with which message should be published. * * @since 5.2.0 */ -@property (nonatomic, nullable, strong) PNMessageType *messageType; +@property (nonatomic, nullable, strong) NSString *type; /** * @brief Name which should be used to store uploaded data. diff --git a/PubNub/Network/Requests/Publish/PNBasePublishRequest.h b/PubNub/Network/Requests/Publish/PNBasePublishRequest.h index e6c5f51af..aced50f66 100644 --- a/PubNub/Network/Requests/Publish/PNBasePublishRequest.h +++ b/PubNub/Network/Requests/Publish/PNBasePublishRequest.h @@ -4,7 +4,7 @@ #pragma mark Class forward -@class PNMessageType, PNSpaceId; +@class PNSpaceId; NS_ASSUME_NONNULL_BEGIN @@ -60,11 +60,11 @@ NS_ASSUME_NONNULL_BEGIN @property (nonatomic, nullable, strong) id message; /** - * @brief Custom type with which message should be published. + * @brief User-provided type with which message should be published. * * @since 5.2.0 */ -@property (nonatomic, nullable, strong) PNMessageType *messageType; +@property (nonatomic, nullable, strong) NSString *type; /** * @brief How long message should be stored in channel's storage. Pass \b 0 store message according to retention. diff --git a/PubNub/Network/Requests/Publish/PNBasePublishRequest.m b/PubNub/Network/Requests/Publish/PNBasePublishRequest.m index 259dfe20b..111a42457 100644 --- a/PubNub/Network/Requests/Publish/PNBasePublishRequest.m +++ b/PubNub/Network/Requests/Publish/PNBasePublishRequest.m @@ -6,7 +6,6 @@ */ #import "PNBasePublishRequest+Private.h" #import "PNRequest+Private.h" -#import "PNMessageType.h" #import "PNSpaceId.h" #import "PNHelpers.h" #import "PNAES.h" @@ -120,8 +119,8 @@ - (PNRequestParameters *)requestParameters { [parameters addQueryParameter:self.spaceId.value forFieldName:@"space-id"]; } - if (self.messageType) { - [parameters addQueryParameter:self.messageType.value forFieldName:@"type"]; + if (self.type) { + [parameters addQueryParameter:self.type forFieldName:@"type"]; } parameters.POSTBodyCompressed = self.shouldCompress; diff --git a/Tests/Tests/Contract/Steps/Files/PNFilesContractTestSteps.m b/Tests/Tests/Contract/Steps/Files/PNFilesContractTestSteps.m index 2f3ff5163..2217a98ed 100644 --- a/Tests/Tests/Contract/Steps/Files/PNFilesContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/Files/PNFilesContractTestSteps.m @@ -85,7 +85,7 @@ - (void)setup { }]; }); - When(@"^I send a file with '(.+)' space id and '(.+)' message type$", ^(NSArray *args, NSDictionary *userInfo) { + When(@"^I send a file with '(.+)' space id and '(.+)' type$", ^(NSArray *args, NSDictionary *userInfo) { XCTAssertEqual(args.count, 2); NSString *messageType = args.lastObject; NSString *spaceId = args.firstObject; @@ -96,7 +96,7 @@ - (void)setup { self.client.files() .sendFile(@"test", @"name.txt") .data([@"test file data" dataUsingEncoding:NSUTF8StringEncoding]) - .messageType([PNMessageType messageTypeFromString:messageType]) + .type(messageType) .spaceId([PNSpaceId spaceIdFromString:spaceId]) .performWithCompletion(^(PNSendFileStatus *status) { [self storeRequestStatus:status]; diff --git a/Tests/Tests/Contract/Steps/History/PNHistoryContractTestSteps.m b/Tests/Tests/Contract/Steps/History/PNHistoryContractTestSteps.m index d1315baca..f9e4609bd 100644 --- a/Tests/Tests/Contract/Steps/History/PNHistoryContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/History/PNHistoryContractTestSteps.m @@ -30,30 +30,35 @@ - (void)setup { }]; }); - Match(@[@"And"], @"^history response contains messages (with|without) ('(.*)' and '(.*)' )?message types$", + Match(@[@"And"], @"^history response contains messages (with|without) ('(.*)' and '(.*)' )?(message )?types$", ^(NSArray *args, NSDictionary *userInfo) { XCTAssertGreaterThan(args.count, 0); + BOOL pubNubMessageType = [args containsObject:@"message "]; NSString *inclusionFlag = args.firstObject; PNHistoryResult *result = (PNHistoryResult *)[self lastResult]; XCTAssertNotNil(result); NSArray *messages = result.data.channels.allValues.firstObject; XCTAssertGreaterThan(messages.count, 0); - NSArray *receivedMessageTypes = [messages valueForKeyPath:@"messageType.value"]; - NSMutableArray *filteredReceivedMessageTypes = [NSMutableArray arrayWithArray:receivedMessageTypes]; - [filteredReceivedMessageTypes removeObjectIdenticalTo:[NSNull null]]; + NSArray *receivedTypes = [messages valueForKeyPath:(pubNubMessageType ? @"messageType" : @"type")]; + NSMutableArray *filteredReceivedTypes = [NSMutableArray arrayWithArray:receivedTypes]; + [filteredReceivedTypes removeObjectIdenticalTo:[NSNull null]]; - XCTAssertFalse([inclusionFlag isEqual:@"with"] && filteredReceivedMessageTypes.count == 0); - XCTAssertFalse([inclusionFlag isEqual:@"without"] && filteredReceivedMessageTypes.count > 0); + XCTAssertFalse([inclusionFlag isEqual:@"with"] && filteredReceivedTypes.count == 0); + XCTAssertFalse([inclusionFlag isEqual:@"without"] && filteredReceivedTypes.count > 0); if (args.count > 1) { - SEL compare = @selector(caseInsensitiveCompare:); - NSArray *expectedMessageTypes = [[args subarrayWithRange:NSMakeRange(2, 2)] sortedArrayUsingSelector:compare]; - NSArray *receivedMessageTypes = [filteredReceivedMessageTypes sortedArrayUsingSelector:compare]; + SEL compare = pubNubMessageType ? @selector(compare:) : @selector(caseInsensitiveCompare:); + NSArray *expectedMessageTypes = [args subarrayWithRange:NSMakeRange(2, 2)]; + if (pubNubMessageType) { + expectedMessageTypes = [expectedMessageTypes valueForKey:@"intValue"]; + } + expectedMessageTypes = [expectedMessageTypes sortedArrayUsingSelector:compare]; + NSArray *receivedMessageTypes = [filteredReceivedTypes sortedArrayUsingSelector:compare]; XCTAssertEqualObjects(receivedMessageTypes, expectedMessageTypes); } else { XCTAssertEqual([inclusionFlag isEqual:@"with"] ? messages.count : 0, - filteredReceivedMessageTypes.count); + filteredReceivedTypes.count); } }); @@ -115,11 +120,11 @@ - (void)setup { ^(NSArray *args, NSDictionary *userInfo) { XCTAssertEqual(args.count, 3); self.testedFeatureType = PNHistoryWithActionsOperation; - BOOL includeMessageType = YES; BOOL includeSpaceId = NO; + BOOL includeType = YES; - if ([args.firstObject isEqual:@"includeMessageType"]) { - includeMessageType = [args[1] isEqual:@"true"]; + if ([args.firstObject isEqual:@"includeType"]) { + includeType = [args[1] isEqual:@"true"]; } else if ([args.firstObject isEqual:@"includeSpaceId"]) { includeSpaceId = [args[1] isEqual:@"true"]; } @@ -127,7 +132,7 @@ - (void)setup { [self callCodeSynchronously:^(dispatch_block_t completion) { self.client.history() .channels(@[args[2]]) - .includeMessageType(includeMessageType) + .includeType(includeType) .includeSpaceId(includeSpaceId) .performWithCompletion(^(PNHistoryResult *result, PNErrorStatus *status) { [self storeRequestResult:result]; diff --git a/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m b/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m index ef8e0fc0c..9546a3c58 100644 --- a/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/Publish/PNPublishContractTestSteps.m @@ -120,7 +120,7 @@ - (void)setup { }]; }); - When(@"^I publish message with '(.*)' space id and '(.*)' message type$", + When(@"^I publish message with '(.*)' space id and '(.*)' type$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNPublishOperation; @@ -128,7 +128,7 @@ - (void)setup { self.client.publish() .message(@"hello") .channel(@"test") - .messageType([PNMessageType messageTypeFromString:args.lastObject]) + .type(args.lastObject) .spaceId([PNSpaceId spaceIdFromString:args.firstObject]) .performWithCompletion(^(PNPublishStatus *status) { [self storeRequestStatus:status]; @@ -151,7 +151,7 @@ - (void)setup { }]; }); - When(@"^I send a signal with '(.*)' space id and '(.*)' message type$", + When(@"^I send a signal with '(.*)' space id and '(.*)' type$", ^(NSArray *args, NSDictionary *userInfo) { self.testedFeatureType = PNSignalOperation; @@ -159,7 +159,7 @@ - (void)setup { self.client.signal() .message(@"hello") .channel(@"test") - .messageType([PNMessageType messageTypeFromString:args.lastObject]) + .type(args.lastObject) .spaceId([PNSpaceId spaceIdFromString:args.firstObject]) .performWithCompletion(^(PNSignalStatus *status) { [self storeRequestStatus:status]; diff --git a/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m b/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m index 7f5df01fc..96d5d4f6b 100644 --- a/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m +++ b/Tests/Tests/Integration/Files/PNFilesIntegrationTests.m @@ -3,6 +3,7 @@ * @copyright © 2010-2020 PubNub, Inc. */ #import "PNRecordableTestCase.h" +#import #import #import "NSString+PNTest.h" @@ -169,7 +170,9 @@ - (void)testItShouldSendFileFromDataAndReceiveFromHistory { XCTAssertEqual(messages.count, 1); XCTAssertNotNil(messages.firstObject[@"uuid"]); XCTAssertNotNil(messages.firstObject[@"messageType"]); - XCTAssertEqualObjects(((PNMessageType *)messages.firstObject[@"messageType"]).value, @"pn_file"); + XCTAssertNotNil(messages.firstObject[@"type"]); + XCTAssertEqualObjects(messages.firstObject[@"type"], @""); + XCTAssertEqualObjects(messages.firstObject[@"messageType"], @(PNFileMessageType)); handler(); }); From 1c7e24392aa3252f8c445da0aec5b5129980e6bb Mon Sep 17 00:00:00 2001 From: Serhii Mamontov Date: Thu, 30 Mar 2023 12:04:09 +0200 Subject: [PATCH 10/10] test(contract): fix vsp subscribe test Fix issue with subscribe contract test after field rename. --- Tests/Tests/Contract/PNContractCucumberTest.m | 4 ++-- .../Steps/Subscribe/PNSubscribeContractTestSteps.m | 4 ++-- Tests/Tests/Helpers/PNRecordableTestCase.m | 10 ---------- 3 files changed, 4 insertions(+), 14 deletions(-) diff --git a/Tests/Tests/Contract/PNContractCucumberTest.m b/Tests/Tests/Contract/PNContractCucumberTest.m index c1b33bb45..86d01e417 100644 --- a/Tests/Tests/Contract/PNContractCucumberTest.m +++ b/Tests/Tests/Contract/PNContractCucumberTest.m @@ -41,6 +41,6 @@ void CucumberishInit(void) { NSBundle * bundle = [NSBundle bundleForClass:[PNContractTestCase class]]; [Cucumberish executeFeaturesInDirectory:@"Features" fromBundle:bundle - includeTags:nil - excludeTags:excludeTags]; + includeTags:@[@"featureSet=subscribeVSP"] + excludeTags:nil]; } diff --git a/Tests/Tests/Contract/Steps/Subscribe/PNSubscribeContractTestSteps.m b/Tests/Tests/Contract/Steps/Subscribe/PNSubscribeContractTestSteps.m index ec6298b2e..52335f271 100644 --- a/Tests/Tests/Contract/Steps/Subscribe/PNSubscribeContractTestSteps.m +++ b/Tests/Tests/Contract/Steps/Subscribe/PNSubscribeContractTestSteps.m @@ -72,7 +72,7 @@ - (void)setup { [self pauseMainQueueFor:0.5f]; }); - Match(@[@"And"], @"^response contains messages with '(.*)' and '(.*)' message types$", + Match(@[@"And"], @"^response contains messages with '(.*)' and '(.*)' types$", ^(NSArray *args, NSDictionary *userInfo) { XCTAssertEqual(args.count, 2); @@ -82,7 +82,7 @@ - (void)setup { SEL compare = @selector(caseInsensitiveCompare:); NSArray *expectedMessageTypes = [args sortedArrayUsingSelector:compare]; - NSArray *receivedMessageTypes = [[messages valueForKeyPath:@"data.messageType.value"] sortedArrayUsingSelector:compare]; + NSArray *receivedMessageTypes = [[messages valueForKeyPath:@"data.type"] sortedArrayUsingSelector:compare]; XCTAssertEqualObjects(receivedMessageTypes, expectedMessageTypes); }); diff --git a/Tests/Tests/Helpers/PNRecordableTestCase.m b/Tests/Tests/Helpers/PNRecordableTestCase.m index 0d16a03bb..710c52700 100644 --- a/Tests/Tests/Helpers/PNRecordableTestCase.m +++ b/Tests/Tests/Helpers/PNRecordableTestCase.m @@ -1207,7 +1207,6 @@ - (void)removeAllObjects { .uuid(uuid) .channels(channelNames) .performWithCompletion(^(PNManageMembershipsStatus *status) { - NSLog(@"%@ %@'s MEMBERSHIPS HAS BEEN REMOVED", @(channelNames.count), uuid); handler(); }); } else { @@ -1235,14 +1234,6 @@ - (void)removeAllObjects { } if (uuids.count || channels.count) { - if (uuids.count) { - NSLog(@"%@ UUIDs HAS BEEN REMOVED", @(uuids.count)); - } - - if (channels.count) { - NSLog(@"%@ CHANNELS HAS BEEN REMOVED", @(channels.count)); - } - [self waitTask:@"waitForDistribution" completionFor:1.f]; } } @@ -1855,7 +1846,6 @@ - (void)removeFiles:(NSArray *)files forChannel:(NSString *)chan } if (files.count) { - NSLog(@"%@ '%@' CHANNEL FILES HAS BEEN REMOVED", @(files.count), channel); [self waitTask:@"waitForDistribution" completionFor:1.f]; } }