1/** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import CallLogBuilder from '../entity/CallLogBuilder'; 17import {Direction, AnswerState} from '../contract/Calls'; 18 19export enum CallType { 20 IN = 1, 21 OUT = 2, 22 VOICEMAIL = 4, 23 MISSED = 3, 24 REJECTED = 5 25} 26 27export class CallLog { 28 readonly id: number = -1; 29 readonly phoneNumber: string; 30 readonly displayName: string; 31 readonly callDirection: number; 32 readonly voicemailUri: string; 33 readonly simId: number; 34 readonly simType: number; 35 readonly isHD: boolean; 36 readonly isRead: boolean; 37 readonly ringDuration: number; 38 readonly talkDuration: number; 39 readonly formattedNumber: string; 40 readonly quickSearchKey: string; 41 readonly numberType: number; 42 readonly numberTypeName: string; 43 readonly beginTime: number; 44 readonly endTime: number; 45 readonly answerState: number; 46 readonly createTime: number; 47 readonly numberLocation: string; 48 readonly photoId: number; 49 readonly photoUri: string; 50 readonly countryIsoCode: number; 51 readonly callType: number; 52 constructor(builder: CallLogBuilder) { 53 this.id = builder.id; 54 this.phoneNumber = builder.phoneNumber; 55 this.displayName = builder.displayName; 56 this.callDirection = builder.callDirection; 57 this.simId = builder.simId; 58 this.simType = builder.simType; 59 this.isHD = builder.isHD; 60 this.isRead = builder.isRead; 61 this.ringDuration = builder.ringDuration; 62 this.talkDuration = builder.talkDuration; 63 this.formattedNumber = builder.formattedNumber; 64 this.quickSearchKey = builder.quickSearchKey; 65 this.numberType = builder.numberType; 66 this.numberTypeName = builder.numberTypeName; 67 this.beginTime = builder.beginTime; 68 this.endTime = builder.endTime; 69 this.answerState = builder.answerState; 70 this.createTime = builder.createTime; 71 this.numberLocation = builder.numberLocation; 72 this.photoId = builder.photoId; 73 this.photoUri = builder.photoUri; 74 this.countryIsoCode = builder.countryIsoCode; 75 this.callType = this.getCallLogType(); 76 } 77 78 private getCallLogType() { 79 if (this.callDirection == Direction.IN) { 80 if (this.answerState == AnswerState.RECEIVED) { 81 return CallType.IN; 82 } 83 if (this.answerState == AnswerState.MISSED) { 84 return CallType.MISSED; 85 } 86 if (this.answerState == AnswerState.REJECT) { 87 return CallType.REJECTED; 88 } 89 } else { 90 return CallType.OUT; 91 } 92 } 93 94 linkContact() { 95 } 96 97 /** 98 * Configure Call Logs as Read 99 */ 100 read() { 101 } 102}