Merge branch 'charlesmchen/searchOversizeText'
This commit is contained in:
commit
18c1f1ef31
|
@ -214,7 +214,6 @@ public class SystemContactsFetcher: NSObject {
|
|||
self.contactStoreAdapter.requestAccess { (granted, error) in
|
||||
if let error = error {
|
||||
Logger.error("\(self.TAG) error fetching contacts: \(error)")
|
||||
Logger.flush()
|
||||
completion(error)
|
||||
return
|
||||
}
|
||||
|
|
|
@ -58,6 +58,9 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
- (BOOL)writeData:(NSData *)data error:(NSError **)error;
|
||||
- (BOOL)writeDataSource:(DataSource *)dataSource;
|
||||
|
||||
- (BOOL)isOversizeText;
|
||||
- (nullable NSString *)readOversizeText;
|
||||
|
||||
+ (void)deleteAttachments;
|
||||
+ (NSString *)attachmentsFolder;
|
||||
|
||||
|
|
|
@ -672,6 +672,27 @@ NS_ASSUME_NONNULL_BEGIN
|
|||
return [OWSBackupFragment fetchObjectWithUniqueID:self.lazyRestoreFragmentId];
|
||||
}
|
||||
|
||||
- (BOOL)isOversizeText
|
||||
{
|
||||
return [self.contentType isEqualToString:OWSMimeTypeOversizeTextMessage];
|
||||
}
|
||||
|
||||
- (nullable NSString *)readOversizeText
|
||||
{
|
||||
if (!self.isOversizeText) {
|
||||
OWSFail(@"%@ oversize text attachment has unexpected content type.", self.logTag);
|
||||
return nil;
|
||||
}
|
||||
NSError *error;
|
||||
NSData *_Nullable data = [self readDataFromFileWithError:&error];
|
||||
if (error || !data) {
|
||||
OWSFail(@"%@ could not read oversize text attachment: %@.", self.logTag, error);
|
||||
return nil;
|
||||
}
|
||||
NSString *_Nullable string = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
|
||||
return string;
|
||||
}
|
||||
|
||||
#pragma mark - Update With... Methods
|
||||
|
||||
- (void)markForLazyRestoreWithFragment:(OWSBackupFragment *)lazyRestoreFragment
|
||||
|
|
|
@ -194,7 +194,39 @@ public class FullTextSearchFinder: NSObject {
|
|||
}
|
||||
|
||||
private static let messageIndexer: SearchIndexer<TSMessage> = SearchIndexer { (message: TSMessage) in
|
||||
return message.body ?? ""
|
||||
if let body = message.body, body.count > 0 {
|
||||
return body
|
||||
}
|
||||
if let oversizeText = oversizeText(forMessage: message) {
|
||||
return oversizeText
|
||||
}
|
||||
return ""
|
||||
}
|
||||
|
||||
private static func oversizeText(forMessage message: TSMessage) -> String? {
|
||||
guard message.hasAttachments() else {
|
||||
return nil
|
||||
}
|
||||
let dbConnection = OWSPrimaryStorage.shared().dbReadConnection
|
||||
var oversizeText: String?
|
||||
dbConnection.read({ (transaction) in
|
||||
guard let attachment = message.attachment(with: transaction) else {
|
||||
owsFail("Could not load attachment for search indexing.")
|
||||
return
|
||||
}
|
||||
guard let attachmentStream = attachment as? TSAttachmentStream else {
|
||||
return
|
||||
}
|
||||
guard attachmentStream.isOversizeText() else {
|
||||
return
|
||||
}
|
||||
guard let text = attachmentStream.readOversizeText() else {
|
||||
owsFail("Could not load oversize text attachment")
|
||||
return
|
||||
}
|
||||
oversizeText = text
|
||||
})
|
||||
return oversizeText
|
||||
}
|
||||
|
||||
private class func indexContent(object: Any) -> String? {
|
||||
|
@ -236,6 +268,8 @@ public class FullTextSearchFinder: NSObject {
|
|||
}
|
||||
|
||||
private class var dbExtensionConfig: YapDatabaseFullTextSearch {
|
||||
SwiftAssertIsOnMainThread(#function)
|
||||
|
||||
let contentColumnName = "content"
|
||||
|
||||
let handler = YapDatabaseFullTextSearchHandler.withObjectBlock { (dict: NSMutableDictionary, _: String, _: String, object: Any) in
|
||||
|
|
Loading…
Reference in New Issue