Path: blob/main/SignalServiceKit/Calls/Individual/TSCall.m
1 views
//1// Copyright 2017 Signal Messenger, LLC2// SPDX-License-Identifier: AGPL-3.0-only3//45#import "TSCall.h"6#import <SignalServiceKit/SignalServiceKit-Swift.h>78NS_ASSUME_NONNULL_BEGIN910NSString *NSStringFromCallType(RPRecentCallType callType)11{12switch (callType) {13case RPRecentCallTypeIncoming:14return @"RPRecentCallTypeIncoming";15case RPRecentCallTypeOutgoing:16return @"RPRecentCallTypeOutgoing";17case RPRecentCallTypeIncomingMissed:18return @"RPRecentCallTypeIncomingMissed";19case RPRecentCallTypeOutgoingIncomplete:20return @"RPRecentCallTypeOutgoingIncomplete";21case RPRecentCallTypeIncomingIncomplete:22return @"RPRecentCallTypeIncomingIncomplete";23case RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity:24return @"RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity";25case RPRecentCallTypeIncomingDeclined:26return @"RPRecentCallTypeIncomingDeclined";27case RPRecentCallTypeOutgoingMissed:28return @"RPRecentCallTypeOutgoingMissed";29case RPRecentCallTypeIncomingAnsweredElsewhere:30return @"RPRecentCallTypeIncomingAnsweredElsewhere";31case RPRecentCallTypeIncomingDeclinedElsewhere:32return @"RPRecentCallTypeIncomingDeclinedElsewhere";33case RPRecentCallTypeIncomingBusyElsewhere:34return @"RPRecentCallTypeIncomingBusyElsewhere";35case RPRecentCallTypeIncomingMissedBecauseOfDoNotDisturb:36return @"RPRecentCallTypeIncomingMissedBecauseOfDoNotDisturb";37case RPRecentCallTypeIncomingMissedBecauseBlockedSystemContact:38return @"RPRecentCallTypeIncomingMissedBecauseBlockedSystemContact";39}40}4142@interface TSCall ()4344@property (nonatomic) TSRecentCallOfferType offerType;4546@end4748#pragma mark -4950@implementation TSCall5152- (instancetype)initWithCallType:(RPRecentCallType)callType53offerType:(TSRecentCallOfferType)offerType54thread:(TSContactThread *)thread55sentAtTimestamp:(uint64_t)sentAtTimestamp56{57self = [super initWithTimestamp:sentAtTimestamp58receivedAtTimestamp:[NSDate ows_millisecondTimeStamp]59thread:thread];6061if (!self) {62return self;63}6465_callType = callType;66_offerType = offerType;6768// Ensure users are notified of missed calls.69switch (callType) {70case RPRecentCallTypeIncomingMissed:71case RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity:72case RPRecentCallTypeIncomingMissedBecauseOfDoNotDisturb:73case RPRecentCallTypeIncomingMissedBecauseBlockedSystemContact:74_read = NO;75break;76default:77_read = YES;78break;79}8081return self;82}8384// --- CODE GENERATION MARKER8586// This snippet is generated by /Scripts/sds_codegen/sds_generate.py. Do not manually edit it, instead run87// `sds_codegen.sh`.8889// clang-format off9091- (instancetype)initWithGrdbId:(int64_t)grdbId92uniqueId:(NSString *)uniqueId93receivedAtTimestamp:(uint64_t)receivedAtTimestamp94sortId:(uint64_t)sortId95timestamp:(uint64_t)timestamp96uniqueThreadId:(NSString *)uniqueThreadId97callType:(RPRecentCallType)callType98offerType:(TSRecentCallOfferType)offerType99read:(BOOL)read100{101self = [super initWithGrdbId:grdbId102uniqueId:uniqueId103receivedAtTimestamp:receivedAtTimestamp104sortId:sortId105timestamp:timestamp106uniqueThreadId:uniqueThreadId];107108if (!self) {109return self;110}111112_callType = callType;113_offerType = offerType;114_read = read;115116return self;117}118119// clang-format on120121// --- CODE GENERATION MARKER122123- (NSUInteger)hash124{125NSUInteger result = [super hash];126result ^= self.callType;127result ^= self.offerType;128result ^= self.read;129return result;130}131132- (BOOL)isEqual:(id)other133{134if (![super isEqual:other]) {135return NO;136}137TSCall *typedOther = (TSCall *)other;138if (self.callType != typedOther.callType) {139return NO;140}141if (self.offerType != typedOther.offerType) {142return NO;143}144if (self.read != typedOther.read) {145return NO;146}147return YES;148}149150- (OWSInteractionType)interactionType151{152return OWSInteractionType_Call;153}154155- (NSString *)previewTextWithTransaction:(DBReadTransaction *)transaction156{157// We don't actually use the `transaction` but other sibling classes do.158switch (_callType) {159case RPRecentCallTypeIncoming:160case RPRecentCallTypeIncomingIncomplete:161case RPRecentCallTypeIncomingAnsweredElsewhere: {162switch (_offerType) {163case TSRecentCallOfferTypeAudio:164return OWSLocalizedString(@"INCOMING_VOICE_CALL", @"info message text in conversation view");165case TSRecentCallOfferTypeVideo:166return OWSLocalizedString(@"INCOMING_VIDEO_CALL", @"info message text in conversation view");167}168}169case RPRecentCallTypeOutgoing:170case RPRecentCallTypeOutgoingIncomplete: {171switch (_offerType) {172case TSRecentCallOfferTypeAudio:173return OWSLocalizedString(@"OUTGOING_VOICE_CALL", @"info message text in conversation view");174case TSRecentCallOfferTypeVideo:175return OWSLocalizedString(@"OUTGOING_VIDEO_CALL", @"info message text in conversation view");176}177}178case RPRecentCallTypeOutgoingMissed: {179switch (_offerType) {180case TSRecentCallOfferTypeAudio:181return OWSLocalizedString(@"OUTGOING_MISSED_VOICE_CALL", @"info message text in conversation view");182case TSRecentCallOfferTypeVideo:183return OWSLocalizedString(@"OUTGOING_MISSED_VIDEO_CALL", @"info message text in conversation view");184}185}186case RPRecentCallTypeIncomingMissed:187case RPRecentCallTypeIncomingMissedBecauseOfChangedIdentity:188case RPRecentCallTypeIncomingBusyElsewhere: {189switch (_offerType) {190case TSRecentCallOfferTypeAudio:191return OWSLocalizedString(@"MISSED_VOICE_CALL", @"info message text in conversation view");192case TSRecentCallOfferTypeVideo:193return OWSLocalizedString(@"MISSED_VIDEO_CALL", @"info message text in conversation view");194}195}196case RPRecentCallTypeIncomingDeclined:197case RPRecentCallTypeIncomingDeclinedElsewhere: {198switch (_offerType) {199case TSRecentCallOfferTypeAudio:200return OWSLocalizedString(@"DECLINED_VOICE_CALL", @"info message text in conversation view");201case TSRecentCallOfferTypeVideo:202return OWSLocalizedString(@"DECLINED_VIDEO_CALL", @"info message text in conversation view");203}204}205case RPRecentCallTypeIncomingMissedBecauseOfDoNotDisturb:206return OWSLocalizedString(207@"MISSED_CALL_FOCUS_MODE", @"info message text in conversation view (use Apple's name for 'Focus')");208case RPRecentCallTypeIncomingMissedBecauseBlockedSystemContact:209return OWSLocalizedString(@"MISSED_CALL_BLOCKED_SYSTEM_CONTACT",210@"info message text in conversation view for when a call was dropped because the contact is blocked in "211@"iOS settings");212}213}214215@end216217NS_ASSUME_NONNULL_END218219220