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.
		
		
		
		
		
			
		
			
				
	
	
		
			33 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Swift
		
	
			
		
		
	
	
			33 lines
		
	
	
		
			1.4 KiB
		
	
	
	
		
			Swift
		
	
| // Copyright © 2022 Rangeproof Pty Ltd. All rights reserved.
 | |
| 
 | |
| extension Storage{
 | |
|     
 | |
|     private static let recentSearchResultDatabaseCollection = "RecentSearchResultDatabaseCollection"
 | |
|     private static let recentSearchResultKey = "RecentSearchResult"
 | |
|     
 | |
|     public func getRecentSearchResults() -> [String] {
 | |
|         var result: [String]?
 | |
|         Storage.read { transaction in
 | |
|             result = transaction.object(forKey: Storage.recentSearchResultKey, inCollection: Storage.recentSearchResultDatabaseCollection) as? [String]
 | |
|         }
 | |
|         return result ?? []
 | |
|     }
 | |
|     
 | |
|     public func clearRecentSearchResults() {
 | |
|         Storage.write { transaction in
 | |
|             transaction.removeObject(forKey: Storage.recentSearchResultKey, inCollection: Storage.recentSearchResultDatabaseCollection)
 | |
|         }
 | |
|     }
 | |
|     
 | |
|     public func addSearchResults(threadID: String) -> [String] {
 | |
|         var recentSearchResults = getRecentSearchResults()
 | |
|         if recentSearchResults.count > 20 { recentSearchResults.remove(at: 0) } // Limit the size of the collection to 20
 | |
|         if let index = recentSearchResults.firstIndex(of: threadID) { recentSearchResults.remove(at: index) }
 | |
|         recentSearchResults.append(threadID)
 | |
|         Storage.write { transaction in
 | |
|             transaction.setObject(recentSearchResults, forKey: Storage.recentSearchResultKey, inCollection: Storage.recentSearchResultDatabaseCollection)
 | |
|         }
 | |
|         return recentSearchResults
 | |
|     }
 | |
| }
 |