2017-02-07 21:09:04 +01:00
|
|
|
//
|
|
|
|
// Copyright (c) 2017 Open Whisper Systems. All rights reserved.
|
|
|
|
//
|
2015-12-07 03:31:43 +01:00
|
|
|
|
|
|
|
#import "TSCall.h"
|
2016-07-28 01:58:49 +02:00
|
|
|
#import "TSContactThread.h"
|
2017-02-07 21:09:04 +01:00
|
|
|
#import <YapDatabase/YapDatabaseConnection.h>
|
|
|
|
#import <YapDatabase/YapDatabaseTransaction.h>
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2016-12-18 22:08:26 +01:00
|
|
|
NS_ASSUME_NONNULL_BEGIN
|
|
|
|
|
2017-02-07 21:09:04 +01:00
|
|
|
NSUInteger TSCallCurrentSchemaVersion = 1;
|
|
|
|
|
|
|
|
@interface TSCall ()
|
|
|
|
|
2017-05-25 18:17:45 +02:00
|
|
|
@property (nonatomic, getter=wasRead) BOOL read;
|
|
|
|
|
2017-02-07 21:09:04 +01:00
|
|
|
@property (nonatomic, readonly) NSUInteger callSchemaVersion;
|
|
|
|
|
|
|
|
@end
|
|
|
|
|
2017-05-25 18:17:45 +02:00
|
|
|
#pragma mark -
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2017-05-25 18:17:45 +02:00
|
|
|
@implementation TSCall
|
2017-02-07 21:09:04 +01:00
|
|
|
|
2016-12-18 22:08:26 +01:00
|
|
|
- (instancetype)initWithTimestamp:(uint64_t)timestamp
|
2015-12-07 03:31:43 +01:00
|
|
|
withCallNumber:(NSString *)contactNumber
|
|
|
|
callType:(RPRecentCallType)callType
|
2016-12-18 22:08:26 +01:00
|
|
|
inThread:(TSContactThread *)thread
|
|
|
|
{
|
|
|
|
self = [super initWithTimestamp:timestamp inThread:thread];
|
2015-12-07 03:31:43 +01:00
|
|
|
|
2017-02-07 21:09:04 +01:00
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
_callSchemaVersion = TSCallCurrentSchemaVersion;
|
|
|
|
_callType = callType;
|
2017-06-07 18:35:18 +02:00
|
|
|
if (_callType == RPRecentCallTypeMissed || _callType == RPRecentCallTypeMissedBecauseOfChangedIdentity) {
|
2017-02-07 21:09:04 +01:00
|
|
|
_read = NO;
|
|
|
|
} else {
|
|
|
|
_read = YES;
|
2015-12-07 03:31:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2017-02-07 21:09:04 +01:00
|
|
|
- (instancetype)initWithCoder:(NSCoder *)coder
|
|
|
|
{
|
|
|
|
self = [super initWithCoder:coder];
|
|
|
|
if (!self) {
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (self.callSchemaVersion < 1) {
|
|
|
|
// Assume user has already seen any call that predate read-tracking
|
|
|
|
_read = YES;
|
|
|
|
}
|
|
|
|
|
|
|
|
_callSchemaVersion = TSCallCurrentSchemaVersion;
|
|
|
|
|
|
|
|
return self;
|
|
|
|
}
|
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
- (NSString *)description {
|
|
|
|
switch (_callType) {
|
|
|
|
case RPRecentCallTypeIncoming:
|
|
|
|
return NSLocalizedString(@"INCOMING_CALL", @"");
|
|
|
|
case RPRecentCallTypeOutgoing:
|
|
|
|
return NSLocalizedString(@"OUTGOING_CALL", @"");
|
|
|
|
case RPRecentCallTypeMissed:
|
|
|
|
return NSLocalizedString(@"MISSED_CALL", @"");
|
2017-02-08 21:51:53 +01:00
|
|
|
case RPRecentCallTypeOutgoingIncomplete:
|
|
|
|
return NSLocalizedString(@"OUTGOING_INCOMPLETE_CALL", @"");
|
|
|
|
case RPRecentCallTypeIncomingIncomplete:
|
|
|
|
return NSLocalizedString(@"INCOMING_INCOMPLETE_CALL", @"");
|
2017-06-07 18:35:18 +02:00
|
|
|
case RPRecentCallTypeMissedBecauseOfChangedIdentity:
|
|
|
|
return NSLocalizedString(@"INFO_MESSAGE_MISSED_CALL_DUE_TO_CHANGED_IDENITY", @"info message text shown in conversation view");
|
2015-12-07 03:31:43 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-02-07 21:09:04 +01:00
|
|
|
#pragma mark - OWSReadTracking
|
|
|
|
|
2017-05-25 18:17:45 +02:00
|
|
|
- (BOOL)shouldAffectUnreadCounts
|
|
|
|
{
|
|
|
|
return YES;
|
|
|
|
}
|
|
|
|
|
2017-06-12 19:29:17 +02:00
|
|
|
- (void)markAsReadWithTransaction:(YapDatabaseReadWriteTransaction *)transaction
|
|
|
|
sendReadReceipt:(BOOL)sendReadReceipt
|
|
|
|
updateExpiration:(BOOL)updateExpiration
|
2017-02-07 21:09:04 +01:00
|
|
|
{
|
2017-06-12 17:51:25 +02:00
|
|
|
OWSAssert(transaction);
|
|
|
|
|
|
|
|
if (_read) {
|
|
|
|
return;
|
|
|
|
}
|
2017-02-08 15:57:45 +01:00
|
|
|
|
2017-06-22 16:10:30 +02:00
|
|
|
DDLogDebug(@"%@ marking as read uniqueId: %@ which has timestamp: %llu", self.tag, self.uniqueId, self.timestamp);
|
2017-02-07 21:09:04 +01:00
|
|
|
_read = YES;
|
|
|
|
[self saveWithTransaction:transaction];
|
|
|
|
[self touchThreadWithTransaction:transaction];
|
|
|
|
|
2017-06-12 19:29:17 +02:00
|
|
|
// Ignore sendReadReceipt and updateExpiration; they don't apply to calls.
|
2017-02-07 21:09:04 +01:00
|
|
|
}
|
|
|
|
|
2017-02-08 21:51:53 +01:00
|
|
|
#pragma mark - Methods
|
|
|
|
|
|
|
|
- (void)updateCallType:(RPRecentCallType)callType
|
|
|
|
{
|
2017-02-08 22:25:28 +01:00
|
|
|
DDLogInfo(@"%@ updating call type of call: %d with uniqueId: %@ which has timestamp: %llu",
|
|
|
|
self.tag,
|
|
|
|
(int)self.callType,
|
|
|
|
self.uniqueId,
|
|
|
|
self.timestamp);
|
|
|
|
|
2017-02-08 21:51:53 +01:00
|
|
|
_callType = callType;
|
|
|
|
|
|
|
|
[self.dbConnection readWriteWithBlock:^(YapDatabaseReadWriteTransaction *_Nonnull transaction) {
|
|
|
|
[self saveWithTransaction:transaction];
|
|
|
|
|
|
|
|
// redraw any thread-related unread count UI.
|
|
|
|
[self touchThreadWithTransaction:transaction];
|
|
|
|
}];
|
|
|
|
}
|
|
|
|
|
2017-02-08 15:57:45 +01:00
|
|
|
#pragma mark - Logging
|
|
|
|
|
|
|
|
+ (NSString *)tag
|
|
|
|
{
|
|
|
|
return [NSString stringWithFormat:@"[%@]", self.class];
|
|
|
|
}
|
|
|
|
|
|
|
|
- (NSString *)tag
|
|
|
|
{
|
|
|
|
return self.class.tag;
|
|
|
|
}
|
|
|
|
|
2015-12-07 03:31:43 +01:00
|
|
|
@end
|
2016-12-18 22:08:26 +01:00
|
|
|
|
|
|
|
NS_ASSUME_NONNULL_END
|