Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
signalapp
GitHub Repository: signalapp/Signal-iOS
Path: blob/main/SignalServiceKit/Calls/Individual/TSCall.m
1 views
1
//
2
// Copyright 2017 Signal Messenger, LLC
3
// SPDX-License-Identifier: AGPL-3.0-only
4
//
5
6
#import "TSCall.h"
7
#import <SignalServiceKit/SignalServiceKit-Swift.h>
8
9
NS_ASSUME_NONNULL_BEGIN
10
11
NSString *NSStringFromCallType(RPRecentCallType callType)
12
{
13
switch (callType) {
14
case RPRecentCallTypeIncoming:
15
return @"RPRecentCallTypeIncoming";
16
case RPRecentCallTypeOutgoing:
17
return @"RPRecentCallTypeOutgoing";
18
case RPRecentCallTypeIncomingMissed:
19
return @"RPRecentCallTypeIncomingMissed";
20
case RPRecentCallTypeOutgoingIncomplete:
21
return @"RPRecentCallTypeOutgoingIncomplete";
22
case RPRecentCallTypeIncomingIncomplete:
23
return @"RPRecentCallTypeIncomingIncomplete";
24
case RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity:
25
return @"RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity";
26
case RPRecentCallTypeIncomingDeclined:
27
return @"RPRecentCallTypeIncomingDeclined";
28
case RPRecentCallTypeOutgoingMissed:
29
return @"RPRecentCallTypeOutgoingMissed";
30
case RPRecentCallTypeIncomingAnsweredElsewhere:
31
return @"RPRecentCallTypeIncomingAnsweredElsewhere";
32
case RPRecentCallTypeIncomingDeclinedElsewhere:
33
return @"RPRecentCallTypeIncomingDeclinedElsewhere";
34
case RPRecentCallTypeIncomingBusyElsewhere:
35
return @"RPRecentCallTypeIncomingBusyElsewhere";
36
case RPRecentCallTypeIncomingMissedBecauseOfDoNotDisturb:
37
return @"RPRecentCallTypeIncomingMissedBecauseOfDoNotDisturb";
38
case RPRecentCallTypeIncomingMissedBecauseBlockedSystemContact:
39
return @"RPRecentCallTypeIncomingMissedBecauseBlockedSystemContact";
40
}
41
}
42
43
@interface TSCall ()
44
45
@property (nonatomic) TSRecentCallOfferType offerType;
46
47
@end
48
49
#pragma mark -
50
51
@implementation TSCall
52
53
- (instancetype)initWithCallType:(RPRecentCallType)callType
54
offerType:(TSRecentCallOfferType)offerType
55
thread:(TSContactThread *)thread
56
sentAtTimestamp:(uint64_t)sentAtTimestamp
57
{
58
self = [super initWithTimestamp:sentAtTimestamp
59
receivedAtTimestamp:[NSDate ows_millisecondTimeStamp]
60
thread:thread];
61
62
if (!self) {
63
return self;
64
}
65
66
_callType = callType;
67
_offerType = offerType;
68
69
// Ensure users are notified of missed calls.
70
switch (callType) {
71
case RPRecentCallTypeIncomingMissed:
72
case RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity:
73
case RPRecentCallTypeIncomingMissedBecauseOfDoNotDisturb:
74
case RPRecentCallTypeIncomingMissedBecauseBlockedSystemContact:
75
_read = NO;
76
break;
77
default:
78
_read = YES;
79
break;
80
}
81
82
return self;
83
}
84
85
// --- CODE GENERATION MARKER
86
87
// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run
88
// `sds_codegen.sh`.
89
90
// clang-format off
91
92
- (instancetype)initWithGrdbId:(int64_t)grdbId
93
uniqueId:(NSString *)uniqueId
94
receivedAtTimestamp:(uint64_t)receivedAtTimestamp
95
sortId:(uint64_t)sortId
96
timestamp:(uint64_t)timestamp
97
uniqueThreadId:(NSString *)uniqueThreadId
98
callType:(RPRecentCallType)callType
99
offerType:(TSRecentCallOfferType)offerType
100
read:(BOOL)read
101
{
102
self = [super initWithGrdbId:grdbId
103
uniqueId:uniqueId
104
receivedAtTimestamp:receivedAtTimestamp
105
sortId:sortId
106
timestamp:timestamp
107
uniqueThreadId:uniqueThreadId];
108
109
if (!self) {
110
return self;
111
}
112
113
_callType = callType;
114
_offerType = offerType;
115
_read = read;
116
117
return self;
118
}
119
120
// clang-format on
121
122
// --- CODE GENERATION MARKER
123
124
- (NSUInteger)hash
125
{
126
NSUInteger result = [super hash];
127
result ^= self.callType;
128
result ^= self.offerType;
129
result ^= self.read;
130
return result;
131
}
132
133
- (BOOL)isEqual:(id)other
134
{
135
if (![super isEqual:other]) {
136
return NO;
137
}
138
TSCall *typedOther = (TSCall *)other;
139
if (self.callType != typedOther.callType) {
140
return NO;
141
}
142
if (self.offerType != typedOther.offerType) {
143
return NO;
144
}
145
if (self.read != typedOther.read) {
146
return NO;
147
}
148
return YES;
149
}
150
151
- (OWSInteractionType)interactionType
152
{
153
return OWSInteractionType_Call;
154
}
155
156
- (NSString *)previewTextWithTransaction:(DBReadTransaction *)transaction
157
{
158
// We don't actually use the `transaction` but other sibling classes do.
159
switch (_callType) {
160
case RPRecentCallTypeIncoming:
161
case RPRecentCallTypeIncomingIncomplete:
162
case RPRecentCallTypeIncomingAnsweredElsewhere: {
163
switch (_offerType) {
164
case TSRecentCallOfferTypeAudio:
165
return OWSLocalizedString(@"INCOMING_VOICE_CALL", @"info message text in conversation view");
166
case TSRecentCallOfferTypeVideo:
167
return OWSLocalizedString(@"INCOMING_VIDEO_CALL", @"info message text in conversation view");
168
}
169
}
170
case RPRecentCallTypeOutgoing:
171
case RPRecentCallTypeOutgoingIncomplete: {
172
switch (_offerType) {
173
case TSRecentCallOfferTypeAudio:
174
return OWSLocalizedString(@"OUTGOING_VOICE_CALL", @"info message text in conversation view");
175
case TSRecentCallOfferTypeVideo:
176
return OWSLocalizedString(@"OUTGOING_VIDEO_CALL", @"info message text in conversation view");
177
}
178
}
179
case RPRecentCallTypeOutgoingMissed: {
180
switch (_offerType) {
181
case TSRecentCallOfferTypeAudio:
182
return OWSLocalizedString(@"OUTGOING_MISSED_VOICE_CALL", @"info message text in conversation view");
183
case TSRecentCallOfferTypeVideo:
184
return OWSLocalizedString(@"OUTGOING_MISSED_VIDEO_CALL", @"info message text in conversation view");
185
}
186
}
187
case RPRecentCallTypeIncomingMissed:
188
case RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity:
189
case RPRecentCallTypeIncomingBusyElsewhere: {
190
switch (_offerType) {
191
case TSRecentCallOfferTypeAudio:
192
return OWSLocalizedString(@"MISSED_VOICE_CALL", @"info message text in conversation view");
193
case TSRecentCallOfferTypeVideo:
194
return OWSLocalizedString(@"MISSED_VIDEO_CALL", @"info message text in conversation view");
195
}
196
}
197
case RPRecentCallTypeIncomingDeclined:
198
case RPRecentCallTypeIncomingDeclinedElsewhere: {
199
switch (_offerType) {
200
case TSRecentCallOfferTypeAudio:
201
return OWSLocalizedString(@"DECLINED_VOICE_CALL", @"info message text in conversation view");
202
case TSRecentCallOfferTypeVideo:
203
return OWSLocalizedString(@"DECLINED_VIDEO_CALL", @"info message text in conversation view");
204
}
205
}
206
case RPRecentCallTypeIncomingMissedBecauseOfDoNotDisturb:
207
return OWSLocalizedString(
208
@"MISSED_CALL_FOCUS_MODE", @"info message text in conversation view (use Apple's name for 'Focus')");
209
case RPRecentCallTypeIncomingMissedBecauseBlockedSystemContact:
210
return OWSLocalizedString(@"MISSED_CALL_BLOCKED_SYSTEM_CONTACT",
211
@"info message text in conversation view for when a call was dropped because the contact is blocked in "
212
@"iOS settings");
213
}
214
}
215
216
@end
217
218
NS_ASSUME_NONNULL_END
219
220