mirror of https://github.com/oxen-io/session-ios
Tweak system messages; incomplete vs. missed calls.
parent
8b3bdb88f3
commit
158aa3abc4
@ -1,23 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "system_message_group@1x.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "system_message_group@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "system_message_group@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 1.4 KiB |
Binary file not shown.
Before Width: | Height: | Size: 1.9 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.3 KiB |
@ -1,23 +0,0 @@
|
||||
{
|
||||
"images" : [
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "system_message_info@1x.png",
|
||||
"scale" : "1x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "system_message_info@2x.png",
|
||||
"scale" : "2x"
|
||||
},
|
||||
{
|
||||
"idiom" : "universal",
|
||||
"filename" : "system_message_info@3x.png",
|
||||
"scale" : "3x"
|
||||
}
|
||||
],
|
||||
"info" : {
|
||||
"version" : 1,
|
||||
"author" : "xcode"
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.2 KiB |
Binary file not shown.
Before Width: | Height: | Size: 2.8 KiB |
@ -0,0 +1,29 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
@class OWSPrimaryStorage;
|
||||
@class OWSStorage;
|
||||
|
||||
@interface OWSIncompleteCallsJob : NSObject
|
||||
|
||||
- (instancetype)init NS_UNAVAILABLE;
|
||||
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage NS_DESIGNATED_INITIALIZER;
|
||||
|
||||
- (void)run;
|
||||
|
||||
+ (NSString *)databaseExtensionName;
|
||||
+ (void)asyncRegisterDatabaseExtensionsWithPrimaryStorage:(OWSStorage *)storage;
|
||||
|
||||
#ifdef DEBUG
|
||||
/**
|
||||
* Only use the sync version for testing, generally we'll want to register extensions async
|
||||
*/
|
||||
- (void)blockingRegisterDatabaseExtensions;
|
||||
#endif
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
@ -0,0 +1,150 @@
|
||||
//
|
||||
// Copyright (c) 2018 Open Whisper Systems. All rights reserved.
|
||||
//
|
||||
|
||||
#import "OWSIncompleteCallsJob.h"
|
||||
#import "OWSPrimaryStorage.h"
|
||||
#import "TSCall.h"
|
||||
#import <YapDatabase/YapDatabase.h>
|
||||
#import <YapDatabase/YapDatabaseQuery.h>
|
||||
#import <YapDatabase/YapDatabaseSecondaryIndex.h>
|
||||
|
||||
NS_ASSUME_NONNULL_BEGIN
|
||||
|
||||
static NSString *const OWSIncompleteCallsJobCallTypeColumn = @"call_type";
|
||||
static NSString *const OWSIncompleteCallsJobCallTypeIndex = @"index_calls_on_call_type";
|
||||
|
||||
@interface OWSIncompleteCallsJob ()
|
||||
|
||||
@property (nonatomic, readonly) OWSPrimaryStorage *primaryStorage;
|
||||
|
||||
@end
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@implementation OWSIncompleteCallsJob
|
||||
|
||||
- (instancetype)initWithPrimaryStorage:(OWSPrimaryStorage *)primaryStorage
|
||||
{
|
||||
self = [super init];
|
||||
if (!self) {
|
||||
return self;
|
||||
}
|
||||
|
||||
_primaryStorage = primaryStorage;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
- (NSArray<NSString *> *)fetchIncompleteCallIdsWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssert(transaction);
|
||||
|
||||
NSMutableArray<NSString *> *messageIds = [NSMutableArray new];
|
||||
|
||||
NSString *formattedString = [NSString stringWithFormat:@"WHERE %@ == %d OR %@ == %d",
|
||||
OWSIncompleteCallsJobCallTypeColumn,
|
||||
(int)RPRecentCallTypeOutgoingIncomplete,
|
||||
OWSIncompleteCallsJobCallTypeColumn,
|
||||
(int)RPRecentCallTypeIncomingIncomplete];
|
||||
YapDatabaseQuery *query = [YapDatabaseQuery queryWithFormat:formattedString];
|
||||
[[transaction ext:OWSIncompleteCallsJobCallTypeIndex]
|
||||
enumerateKeysMatchingQuery:query
|
||||
usingBlock:^void(NSString *collection, NSString *key, BOOL *stop) {
|
||||
[messageIds addObject:key];
|
||||
}];
|
||||
|
||||
return [messageIds copy];
|
||||
}
|
||||
|
||||
- (void)enumerateIncompleteCallsWithBlock:(void (^)(TSCall *call))block
|
||||
transaction:(YapDatabaseReadWriteTransaction *)transaction
|
||||
{
|
||||
OWSAssert(transaction);
|
||||
|
||||
// Since we can't directly mutate the enumerated "incomplete" calls, we store only their ids in hopes
|
||||
// of saving a little memory and then enumerate the (larger) TSCall objects one at a time.
|
||||
for (NSString *callId in [self fetchIncompleteCallIdsWithTransaction:transaction]) {
|
||||
TSCall *_Nullable call = [TSCall fetchObjectWithUniqueID:callId transaction:transaction];
|
||||
if ([call isKindOfClass:[TSCall class]]) {
|
||||
block(call);
|
||||
} else {
|
||||
DDLogError(@"%@ unexpected object: %@", self.logTag, call);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
- (void)run
|
||||
{
|
||||
__block uint count = 0;
|
||||
|
||||
[[self.primaryStorage newDatabaseConnection] readWriteWithBlock:^(YapDatabaseReadWriteTransaction *transaction) {
|
||||
[self
|
||||
enumerateIncompleteCallsWithBlock:^(TSCall *call) {
|
||||
if (call.callType == RPRecentCallTypeOutgoingIncomplete) {
|
||||
DDLogDebug(@"%@ marking call as missed: %@", self.logTag, call.uniqueId);
|
||||
[call updateCallType:RPRecentCallTypeOutgoingMissed transaction:transaction];
|
||||
OWSAssert(call.callType == RPRecentCallTypeOutgoingMissed);
|
||||
} else if (call.callType == RPRecentCallTypeIncomingIncomplete) {
|
||||
DDLogDebug(@"%@ marking call as missed: %@", self.logTag, call.uniqueId);
|
||||
[call updateCallType:RPRecentCallTypeIncomingMissed transaction:transaction];
|
||||
OWSAssert(call.callType == RPRecentCallTypeIncomingMissed);
|
||||
} else {
|
||||
OWSProdLogAndFail(
|
||||
@"%@ call has unexpected call type: %@", self.logTag, NSStringFromCallType(call.callType));
|
||||
return;
|
||||
}
|
||||
count++;
|
||||
}
|
||||
transaction:transaction];
|
||||
}];
|
||||
|
||||
DDLogDebug(@"%@ Marked %u calls as missed", self.logTag, count);
|
||||
}
|
||||
|
||||
#pragma mark - YapDatabaseExtension
|
||||
|
||||
+ (YapDatabaseSecondaryIndex *)indexDatabaseExtension
|
||||
{
|
||||
YapDatabaseSecondaryIndexSetup *setup = [YapDatabaseSecondaryIndexSetup new];
|
||||
[setup addColumn:OWSIncompleteCallsJobCallTypeColumn withType:YapDatabaseSecondaryIndexTypeInteger];
|
||||
|
||||
YapDatabaseSecondaryIndexHandler *handler =
|
||||
[YapDatabaseSecondaryIndexHandler withObjectBlock:^(YapDatabaseReadTransaction *transaction,
|
||||
NSMutableDictionary *dict,
|
||||
NSString *collection,
|
||||
NSString *key,
|
||||
id object) {
|
||||
if (![object isKindOfClass:[TSCall class]]) {
|
||||
return;
|
||||
}
|
||||
TSCall *call = (TSCall *)object;
|
||||
|
||||
dict[OWSIncompleteCallsJobCallTypeColumn] = @(call.callType);
|
||||
}];
|
||||
|
||||
return [[YapDatabaseSecondaryIndex alloc] initWithSetup:setup handler:handler versionTag:nil];
|
||||
}
|
||||
|
||||
#ifdef DEBUG
|
||||
// Useful for tests, don't use in app startup path because it's slow.
|
||||
- (void)blockingRegisterDatabaseExtensions
|
||||
{
|
||||
[self.primaryStorage registerExtension:[self.class indexDatabaseExtension]
|
||||
withName:OWSIncompleteCallsJobCallTypeIndex];
|
||||
}
|
||||
#endif
|
||||
|
||||
+ (NSString *)databaseExtensionName
|
||||
{
|
||||
return OWSIncompleteCallsJobCallTypeIndex;
|
||||
}
|
||||
|
||||
+ (void)asyncRegisterDatabaseExtensionsWithPrimaryStorage:(OWSStorage *)storage
|
||||
{
|
||||
[storage asyncRegisterExtension:[self indexDatabaseExtension] withName:OWSIncompleteCallsJobCallTypeIndex];
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
NS_ASSUME_NONNULL_END
|
Loading…
Reference in New Issue