22// Portions Copyright (c) 2016 Open Whisper Systems. All rights reserved.
33
44#import " OWSCall.h"
5+ #import " TSCall.h"
6+ #import " TSContactThread.h"
57#import < JSQMessagesViewController/JSQMessagesTimestampFormatter.h>
68#import < JSQMessagesViewController/UIImage+JSQMessages.h>
9+ #import < SignalServiceKit/TSCall.h>
10+
11+ NS_ASSUME_NONNULL_BEGIN
712
813@interface OWSCall ()
914
@@ -13,26 +18,76 @@ @interface OWSCall ()
1318@property (nonatomic ) BOOL shouldStartExpireTimer;
1419@property (nonatomic ) uint64_t expiresAtSeconds;
1520@property (nonatomic ) uint32_t expiresInSeconds;
21+ @property (nonatomic ) TSInteraction *interaction;
1622
1723@end
1824
1925@implementation OWSCall
2026
2127#pragma mark - Initialzation
2228
23- - (id ) init
29+ - (instancetype ) initWithCallRecord : (TSCall *) callRecord
2430{
25- NSAssert (NO ,
26- @" %s is not a valid initializer for %@ . Use %@ instead" ,
27- __PRETTY_FUNCTION__,
28- [self class ],
29- NSStringFromSelector (@selector (initWithCallerId:callerDisplayName:date:status:displayString: )));
30- return [self initWithCallerId: nil callerDisplayName: nil date: nil status: 0 displayString: nil ];
31+ TSThread *thread = callRecord.thread ;
32+ TSContactThread *contactThread;
33+ if ([thread isKindOfClass: [TSContactThread class ]]) {
34+ contactThread = (TSContactThread *)thread;
35+ } else {
36+ DDLogError (@" %@ Unexpected thread type: %@ " , self.tag , thread);
37+ }
38+
39+
40+ CallStatus status = 0 ;
41+ switch (callRecord.callType ) {
42+ case RPRecentCallTypeOutgoing:
43+ status = kCallOutgoing ;
44+ break ;
45+ case RPRecentCallTypeMissed:
46+ status = kCallMissed ;
47+ break ;
48+ case RPRecentCallTypeIncoming:
49+ status = kCallIncoming ;
50+ break ;
51+ default :
52+ status = kCallIncoming ;
53+ break ;
54+ }
55+
56+ NSString *name = contactThread.name ;
57+ NSString *detailString;
58+ switch (status) {
59+ case kCallMissed :
60+ detailString = [NSString stringWithFormat: NSLocalizedString(@" MSGVIEW_MISSED_CALL" , nil ), name];
61+ break ;
62+ case kCallIncoming :
63+ detailString = [NSString stringWithFormat: NSLocalizedString(@" MSGVIEW_RECEIVED_CALL" , nil ), name];
64+ break ;
65+ case kCallOutgoing :
66+ detailString = [NSString stringWithFormat: NSLocalizedString(@" MSGVIEW_YOU_CALLED" , nil ), name];
67+ break ;
68+ default :
69+ detailString = @" " ;
70+ break ;
71+ }
72+
73+ self = [self initWithCallerId: contactThread.contactIdentifier
74+ callerDisplayName: name
75+ date: callRecord.date
76+ status: status
77+ displayString: detailString];
78+
79+ if (!self) {
80+ return self;
81+ }
82+
83+ _interaction = callRecord;
84+
85+ return self;
3186}
3287
3388- (instancetype )initWithCallerId : (NSString *)senderId
3489 callerDisplayName : (NSString *)senderDisplayName
35- date : (NSDate *)date
90+ date : (nullable NSDate *)date
3691 status : (CallStatus)status
3792 displayString : (NSString *)detailString
3893{
@@ -105,11 +160,18 @@ - (NSString *)description
105160
106161- (BOOL )canPerformEditingAction : (SEL )action
107162{
108- return NO ;
163+ return action == @selector ( delete: ) ;
109164}
110165
111166- (void )performEditingAction : (SEL )action
112167{
168+ // Deletes are always handled by TSMessageAdapter
169+ if (action == @selector (delete: )) {
170+ DDLogDebug (@" %@ Deleting interaction with uniqueId: %@ " , self.tag , self.interaction .uniqueId );
171+ [self .interaction remove ];
172+ return ;
173+ }
174+
113175 // Shouldn't get here, as only supported actions should be exposed via canPerformEditingAction
114176 NSString *actionString = NSStringFromSelector (action);
115177 DDLogError (@" %@ '%@ ' action unsupported" , self.tag , actionString);
@@ -124,7 +186,7 @@ - (BOOL)isMediaMessage
124186
125187#pragma mark - NSCoding
126188
127- - (instancetype )initWithCoder : (NSCoder *)aDecoder
189+ - (nullable instancetype )initWithCoder : (NSCoder *)aDecoder
128190{
129191 NSString *senderId = [aDecoder decodeObjectForKey: NSStringFromSelector (@selector (senderId ))];
130192 NSString *senderDisplayName = [aDecoder decodeObjectForKey: NSStringFromSelector (@selector (senderDisplayName ))];
@@ -149,7 +211,7 @@ - (void)encodeWithCoder:(NSCoder *)aCoder
149211
150212#pragma mark - NSCopying
151213
152- - (instancetype )copyWithZone : (NSZone *)zone
214+ - (instancetype )copyWithZone : (nullable NSZone *)zone
153215{
154216 return [[[self class ] allocWithZone: zone] initWithCallerId: self .senderId
155217 callerDisplayName: self .senderDisplayName
@@ -181,3 +243,5 @@ - (NSString *)tag
181243}
182244
183245@end
246+
247+ NS_ASSUME_NONNULL_END
0 commit comments