mirror of https://github.com/oxen-io/session-ios
				
				
				
			
			You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
	
	
		
			55 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Matlab
		
	
		
		
			
		
	
	
			55 lines
		
	
	
		
			1.9 KiB
		
	
	
	
		
			Matlab
		
	
| 
								 
											5 years ago
										 
									 | 
							
								//
							 | 
						||
| 
								 | 
							
								//  Copyright (c) 2019 Open Whisper Systems. All rights reserved.
							 | 
						||
| 
								 | 
							
								//
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#import "TSDatabaseSecondaryIndexes.h"
							 | 
						||
| 
								 | 
							
								#import "OWSStorage.h"
							 | 
						||
| 
								 | 
							
								#import "TSInteraction.h"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								NS_ASSUME_NONNULL_BEGIN
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								#define TSTimeStampSQLiteIndex @"messagesTimeStamp"
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@implementation TSDatabaseSecondaryIndexes
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								+ (NSString *)registerTimeStampIndexExtensionName
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    return @"idx";
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								+ (YapDatabaseSecondaryIndex *)registerTimeStampIndex {
							 | 
						||
| 
								 | 
							
								    YapDatabaseSecondaryIndexSetup *setup = [[YapDatabaseSecondaryIndexSetup alloc] init];
							 | 
						||
| 
								 | 
							
								    [setup addColumn:TSTimeStampSQLiteIndex withType:YapDatabaseSecondaryIndexTypeReal];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    YapDatabaseSecondaryIndexWithObjectBlock block =
							 | 
						||
| 
								 | 
							
								        ^(YapDatabaseReadTransaction *transaction, NSMutableDictionary *dict, NSString *collection, NSString *key, id object) {
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								          if ([object isKindOfClass:[TSInteraction class]]) {
							 | 
						||
| 
								 | 
							
								              TSInteraction *interaction = (TSInteraction *)object;
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								              [dict setObject:@(interaction.timestamp) forKey:TSTimeStampSQLiteIndex];
							 | 
						||
| 
								 | 
							
								          }
							 | 
						||
| 
								 | 
							
								        };
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    YapDatabaseSecondaryIndexHandler *handler = [YapDatabaseSecondaryIndexHandler withObjectBlock:block];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    YapDatabaseSecondaryIndex *secondaryIndex =
							 | 
						||
| 
								 | 
							
								        [[YapDatabaseSecondaryIndex alloc] initWithSetup:setup handler:handler versionTag:nil];
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								    return secondaryIndex;
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								+ (void)enumerateMessagesWithTimestamp:(uint64_t)timestamp
							 | 
						||
| 
								 | 
							
								                             withBlock:(void (^)(NSString *collection, NSString *key, BOOL *stop))block
							 | 
						||
| 
								 | 
							
								                      usingTransaction:(YapDatabaseReadTransaction *)transaction
							 | 
						||
| 
								 | 
							
								{
							 | 
						||
| 
								 | 
							
								    NSString *formattedString = [NSString stringWithFormat:@"WHERE %@ = %lld", TSTimeStampSQLiteIndex, timestamp];
							 | 
						||
| 
								 | 
							
								    YapDatabaseQuery *query   = [YapDatabaseQuery queryWithFormat:formattedString];
							 | 
						||
| 
								 | 
							
								    [[transaction ext:[self registerTimeStampIndexExtensionName]] enumerateKeysMatchingQuery:query usingBlock:block];
							 | 
						||
| 
								 | 
							
								}
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								@end
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
								NS_ASSUME_NONNULL_END
							 |