Skip to content

Commit

Permalink
Merge pull request #280 from CleverTap/develop
Browse files Browse the repository at this point in the history
Release 5.1.2
  • Loading branch information
akashvercetti authored Jul 28, 2023
2 parents 3686688 + f27d8db commit cd70e19
Show file tree
Hide file tree
Showing 5 changed files with 49 additions and 84 deletions.
2 changes: 1 addition & 1 deletion .github/mini_flows/mandatory_filechanges/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ runs:
with:
filters: |
md: ['CHANGELOG.md']
podspec: ['CleverTap-iOS-SDK.podspec']
txt: ['sdk-version.txt']
h: ['CleverTapSDK/CleverTapBuildInfo.h']
- name: FAIL if mandatory files are not changed
Expand Down
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Change Log
All notable changes to this project will be documented in this file.

### [Version 5.1.2](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/5.1.2) (July 28, 2023)

#### Fixed
- Fixed a bug where the App Inbox would appear empty.

### [Version 5.1.1](https://github.com/CleverTap/clevertap-ios-sdk/releases/tag/5.1.1) (July 13, 2023)

#### Fixed
Expand Down
2 changes: 1 addition & 1 deletion CleverTapSDK/CleverTapBuildInfo.h
Original file line number Diff line number Diff line change
@@ -1 +1 @@
#define WR_SDK_REVISION @"50101"
#define WR_SDK_REVISION @"50102"
122 changes: 41 additions & 81 deletions CleverTapSDK/Inbox/controllers/CTInboxController.m
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,9 @@ - (instancetype)initWithAccountId:(NSString *)accountId guid:(NSString *)guid {
_guid = guid;
NSString *userIdentifier = [NSString stringWithFormat:@"%@:%@", accountId, guid];
_userIdentifier = userIdentifier;
[privateContext performBlock:^{
CT_TRY
[privateContext performBlockAndWait:^{
self->_user = [CTUserMO fetchOrCreateFromJSON:@{@"accountId":accountId, @"guid":guid, @"identifier": userIdentifier} forContext:privateContext];
[self _save];
CT_END_TRY
}];
}
}
Expand Down Expand Up @@ -87,14 +85,12 @@ - (void)staticInit {
- (void)updateMessages:(NSArray<NSDictionary*> *)messages {
if (!self.isInitialized) return;
[privateContext performBlock:^{
CT_TRY
CleverTapLogStaticInternal(@"%@: updating messages: %@", self.user, messages);
BOOL haveUpdates = [self.user updateMessages:messages forContext:privateContext];
if (haveUpdates) {
[self _save];
[self notifyUpdate];
}
CT_END_TRY
}];
}

Expand Down Expand Up @@ -127,20 +123,17 @@ - (void)deleteMessagesWithId:(NSArray *_Nonnull)messageIds {

- (void)markReadMessageWithId:(NSString *)messageId {
[privateContext performBlock:^{
CT_TRY
CTMessageMO *message = [self _messageForId:messageId];
if (message) {
[message setValue:@YES forKey:@"isRead"];
[self _save];
[self notifyUpdate];
}
CT_END_TRY
}];
}

- (void)markReadMessagesWithId:(NSArray *_Nonnull)messageIds {
[privateContext performBlock:^{
CT_TRY
for (NSString *ids in messageIds) {
if (ids != nil && ![ids isEqualToString:@""]){
CTMessageMO *message = [self _messageForId:ids];
Expand All @@ -157,7 +150,6 @@ - (void)markReadMessagesWithId:(NSArray *_Nonnull)messageIds {
}
[self _save];
[self notifyUpdate];
CT_END_TRY
}];
}

Expand Down Expand Up @@ -189,25 +181,21 @@ - (NSInteger)unreadCount {
BOOL hasMessages = ([[self.user.entity propertiesByName] objectForKey:@"messages"] != nil);
if (!hasMessages) return nil;

[privateContext performBlock:^{
CT_TRY
for (CTMessageMO *msg in self.user.messages) {
int ttl = (int)msg.expires;
if (ttl > 0 && now >= ttl) {
CleverTapLogStaticInternal(@"%@: message expires: %@, deleting", self, msg);
[toDelete addObject:msg];
} else {
[messages addObject:[msg toJSON]];
}
for (CTMessageMO *msg in self.user.messages) {
int ttl = (int)msg.expires;
if (ttl > 0 && now >= ttl) {
CleverTapLogStaticInternal(@"%@: message expires: %@, deleting", self, msg);
[toDelete addObject:msg];
} else {
[messages addObject:[msg toJSON]];
}
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
[messages sortUsingDescriptors:@[sortDescriptor]];

if ([toDelete count] > 0) {
[self _deleteMessages:toDelete];
}
CT_END_TRY
}];
}
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
[messages sortUsingDescriptors:@[sortDescriptor]];

if ([toDelete count] > 0) {
[self _deleteMessages:toDelete];
}
return messages;
}

Expand All @@ -217,32 +205,25 @@ - (NSInteger)unreadCount {
NSMutableArray *messages = [NSMutableArray new];
NSMutableArray *toDelete = [NSMutableArray new];


BOOL hasMessages = ([[self.user.entity propertiesByName] objectForKey:@"messages"] != nil);
if (!hasMessages) return nil;

[privateContext performBlock:^{
CT_TRY
NSOrderedSet *results = [self.user.messages filteredOrderedSetUsingPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"isRead == NO"]]];
for (CTMessageMO *msg in results) {
int ttl = (int)msg.expires;
if (ttl > 0 && now >= ttl) {
CleverTapLogStaticInternal(@"%@: message expires: %@, deleting", self, msg);
[toDelete addObject:msg];
} else {
[messages addObject:[msg toJSON]];
}
}
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
[messages sortUsingDescriptors:@[sortDescriptor]];

if ([toDelete count] > 0) {
[self _deleteMessages:toDelete];
NSOrderedSet *results = [self.user.messages filteredOrderedSetUsingPredicate:[NSPredicate predicateWithFormat:[NSString stringWithFormat:@"isRead == NO"]]];
for (CTMessageMO *msg in results) {
int ttl = (int)msg.expires;
if (ttl > 0 && now >= ttl) {
CleverTapLogStaticInternal(@"%@: message expires: %@, deleting", self, msg);
[toDelete addObject:msg];
} else {
[messages addObject:[msg toJSON]];
}
CT_END_TRY
}];

}
NSSortDescriptor *sortDescriptor = [[NSSortDescriptor alloc] initWithKey:@"date" ascending:NO];
[messages sortUsingDescriptors:@[sortDescriptor]];

if ([toDelete count] > 0) {
[self _deleteMessages:toDelete];
}
return messages;
}

Expand All @@ -254,55 +235,34 @@ - (CTMessageMO *)_messageForId:(NSString *)messageId {

BOOL hasMessages = ([[self.user.entity propertiesByName] objectForKey:@"messages"] != nil);
if (!hasMessages) return nil;
__block NSOrderedSet *results;

[privateContext performBlock:^{
CT_TRY
results = [self.user.messages filteredOrderedSetUsingPredicate:[NSPredicate predicateWithFormat:@"id == %@", messageId]];
CT_END_TRY
}];

NSOrderedSet *results = [self.user.messages filteredOrderedSetUsingPredicate:[NSPredicate predicateWithFormat:@"id == %@", messageId]];
BOOL existing = results && [results count] > 0;
return existing ? results[0] : nil;
}

- (void)_deleteMessages:(NSArray<CTMessageMO*>*)messages {
[privateContext performBlock:^{
CT_TRY
[privateContext performBlockAndWait:^{
for (CTMessageMO *msg in messages) {
[privateContext deleteObject:msg];
}
[self _save];
[self notifyUpdate];
CT_END_TRY
}];
}

// always call from inside privateContext performBlock
- (BOOL)_save {
__block BOOL res = YES;
[privateContext performBlock:^{
CT_TRY
NSError *error = nil;
if ([privateContext hasChanges]) {
res = [privateContext save:&error];
}
if (!res) {
CleverTapLogStaticDebug(@"Error saving core data main context: %@\n%@", [error localizedDescription], [error userInfo]);
}
CT_END_TRY
}];
[mainContext performBlock:^{
CT_TRY
NSError *error = nil;
if ([mainContext hasChanges]) {
res = [mainContext save:&error];
}
if (!res) {
CleverTapLogStaticDebug(@"Error saving core data main context: %@\n%@", [error localizedDescription], [error userInfo]);
}
CT_END_TRY
}];
NSError *error = nil;
BOOL res = YES;
res = [privateContext save:&error];
if (!res) {
CleverTapLogStaticDebug(@"Error saving core data private context: %@\n%@", [error localizedDescription], [error userInfo]);
}
res = [mainContext save:&error];
if (!res) {
CleverTapLogStaticDebug(@"Error saving core data main context: %@\n%@", [error localizedDescription], [error userInfo]);
}
return res;
}

Expand Down
2 changes: 1 addition & 1 deletion sdk-version.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
5.1.1
5.1.2

0 comments on commit cd70e19

Please sign in to comment.