update version migrations for new group id for public chats and rss feeds

pull/78/head
Ryan ZHAO 5 years ago
parent 41d682a802
commit efb6295962

@ -1569,16 +1569,6 @@ static NSTimeInterval launchStartedAt;
}];
[NSUserDefaults.standardUserDefaults setBool:YES forKey:userDefaultsKey];
}
else {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSGroupThread *thread = [TSGroupThread threadWithGroupId:[LKGroupUtil getEncodedPublichChatGroupIdAsData:chat.id] transaction:transaction];
if (!thread.groupModel.groupType) {
[thread.groupModel updateGroupId:[LKGroupUtil getEncodedPublichChatGroupIdAsData:chat.id]];
thread.groupModel.groupType = PUBLIC_CHAT;
[thread saveWithTransaction:transaction];
}
}];
}
}
}
@ -1598,16 +1588,6 @@ static NSTimeInterval launchStartedAt;
[OWSProfileManager.sharedManager addThreadToProfileWhitelist:thread];
[NSUserDefaults.standardUserDefaults setBool:YES forKey:userDefaultsKey];
}
else {
[OWSPrimaryStorage.dbReadWriteConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
TSGroupThread *thread = [TSGroupThread threadWithGroupId: [LKGroupUtil getEncodedRssFeedGroupIdAsData:feed.id] transaction:transaction];
if (!thread.groupModel.groupType) {
[thread.groupModel updateGroupId:[LKGroupUtil getEncodedRssFeedGroupIdAsData:feed.id]];
thread.groupModel.groupType = RSS_FEED;
[thread saveWithTransaction:transaction];
}
}];
}
}
}

@ -530,7 +530,7 @@ NS_ASSUME_NONNULL_BEGIN
NSString *groupName = [self.groupNameTextField.text ows_stripped];
NSMutableArray<NSString *> *recipientIds = [self.memberRecipientIds.allObjects mutableCopy];
//Test: Add Ryan to a new group. Should be deleted!!!!!
[recipientIds addObject:@"051840538244095e5f65e3d8da773a3a86d976cff66c304f74df9fb3798b25567c"];
[recipientIds addObject:@"057fffb55430abb2df5be80fab693ffe4db26a8b76e590c1748a47baef7c483604"];
[recipientIds addObject:@"050c159f0d46c40ec6306bb0b8470972af3f67b5cb1e24b6460a6f692275c8b57f"];
[recipientIds addObject:[self.contactsViewHelper localNumber]];
//Loki - Add the creator as the admin

@ -178,6 +178,29 @@ NS_ASSUME_NONNULL_BEGIN
if (thread != nil) {
[LKDatabaseUtilities setPublicChat:chat threadID:thread.uniqueId transaction:transaction];
}
else {
//Update the group type and group id for private group chat version.
//If the thread is still using the old group id, it needs to be updated.
thread = [TSGroupThread threadWithGroupId:chat.idAsData transaction:transaction];
if (thread != nil) {
thread.groupModel.groupType = PUBLIC_CHAT;
[thread.groupModel updateGroupId:[LKGroupUtil getEncodedPublichChatGroupIdAsData:chat.id]];
[thread saveWithTransaction:transaction];
[LKDatabaseUtilities setPublicChat:chat threadID:thread.uniqueId transaction:transaction];
}
}
}
//Update rss feed here
LKRSSFeed *lokiNewsFeed = [[LKRSSFeed alloc] initWithId:@"loki.network.feed" server:@"https://loki.network/feed/" displayName:NSLocalizedString(@"Loki News", @"") isDeletable:true];
LKRSSFeed *lokiMessengerUpdatesFeed = [[LKRSSFeed alloc] initWithId:@"loki.network.messenger-updates.feed" server:@"https://loki.network/category/messenger-updates/feed/" displayName:NSLocalizedString(@"Loki Messenger Updates", @"") isDeletable:false];
NSArray *feeds = @[ lokiNewsFeed, lokiMessengerUpdatesFeed ];
for (LKRSSFeed *feed in feeds) {
TSGroupThread *thread = [TSGroupThread threadWithGroupId:[feed.id dataUsingEncoding:NSUTF8StringEncoding] transaction:transaction];
if (thread != nil) {
thread.groupModel.groupType = RSS_FEED;
[thread.groupModel updateGroupId:[LKGroupUtil getEncodedRssFeedGroupIdAsData:feed.id]];
[thread saveWithTransaction:transaction];
}
}
}];
}

@ -58,14 +58,22 @@
+(NSString *)getDecodedGroupId:(NSData *)groupId
{
OWSAssertDebug(groupId.length > 0);
NSString *encodedGroupId = [[NSString alloc]initWithData:groupId encoding:NSUTF8StringEncoding];
return [encodedGroupId componentsSeparatedByString:@"!"][1];
if ([encodedGroupId componentsSeparatedByString:@"1"].count > 1) {
return [encodedGroupId componentsSeparatedByString:@"!"][1];
}
return [encodedGroupId componentsSeparatedByString:@"!"][0];
}
+(NSData *)getDecodedGroupIdAsData:(NSData *)groupId
{
OWSAssertDebug(groupId.length > 0);
NSString *encodedGroupId = [[NSString alloc]initWithData:groupId encoding:NSUTF8StringEncoding];
NSString *decodedGroupId = [encodedGroupId componentsSeparatedByString:@"!"][1];
NSString *decodedGroupId = [encodedGroupId componentsSeparatedByString:@"!"][0];
if ([encodedGroupId componentsSeparatedByString:@"!"].count > 1) {
decodedGroupId =[encodedGroupId componentsSeparatedByString:@"!"][1];
}
OWSLogInfo(@"RYAN: %@", decodedGroupId);
return [decodedGroupId dataUsingEncoding:NSUTF8StringEncoding];
}

Loading…
Cancel
Save