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 SettingModel from '../model/SettingsModel'; 17 18let mSettingModel = new SettingModel(); 19import HiLog from '../utils/HiLog'; 20import common from '../data/commonData'; 21import LooseObject from '../data/LooseObject' 22import MmsPreferences from '../utils/MmsPreferences'; 23 24const TAG = 'SettingService'; 25 26export default { 27 28 /** 29 * Set Initial Value 30 * 31 * @param {Object} callback 32 */ 33 setOnSettingValueListener(callback) { 34 let result: LooseObject = { 35 'integrationSwitch': false, 36 'maliciousWebSwitch': false, 37 'showContactSwitch': false, 38 }; 39 mSettingModel.setOnSettingValueListener(settingValue => { 40 if (settingValue.integrationSwitch === common.bool.TRUE || settingValue.integrationSwitch === '') { 41 result.integrationSwitch = true; 42 } 43 if (settingValue.maliciousWebSwitch === common.bool.TRUE || settingValue.integrationSwitch === '') { 44 result.maliciousWebSwitch = true; 45 } 46 if (settingValue.showContactSwitch === common.bool.TRUE || settingValue.integrationSwitch === '') { 47 result.showContactSwitch = true; 48 } 49 }); 50 callback(result); 51 }, 52 53 /** 54 * Restore Page Defaults 55 * 56 * @param {Object} callback 57 */ 58 restoreSwitchValue(callback) { 59 mSettingModel.restoreSwitchValueToDefault(callback); 60 }, 61 62 /** 63 * Update related values 64 * @param code Updated code. 65 * @param actionData Updated Value 66 * @param callback 67 * @return 68 */ 69 updateSettingValue(code, actionData, callback) { 70 switch (code) { 71 case common.route.MESSAGE_CODE_UPDATE_DELIVERY_REPORTS_VALUE: 72 // Delivery Report 73 mSettingModel.updateSwitchValue(common.string.KEY_OF_DELIVERY_REPORT_SWITCH, 74 actionData.intValue, callback); 75 break; 76 case common.route.MESSAGE_CODE_UPDATE_AUTO_RETRIEVE_MMS_VALUE: 77 // Automatically downloading MMs 78 mSettingModel.updateSwitchValue(common.string.KEY_OF_AUTO_RETRIEVE_SWITCH, 79 actionData.intValue, callback); 80 break; 81 case common.route.MESSAGE_CODE_UPDATE_RECALL_MESSAGES_VALUE: 82 // Cancel Sending 83 mSettingModel.updateSwitchValue(common.string.KEY_OF_RECALL_MESSAGE_SWITCH, 84 actionData.booleanValue, callback); 85 break; 86 case common.route.MESSAGE_CODE_UPDATE_AUTO_DELETE_INFO_MESSAGES_VALUE: 87 // Automatically delete notification information 88 mSettingModel.updateSwitchValue(common.string.KEY_OF_AUTO_DELETE_INFO_SWITCH, 89 actionData.booleanValue, callback); 90 break; 91 case common.route.MESSAGE_CODE_UPDATE_ARCHIVE_INFO_MESSAGES_VALUE: 92 // Notification information integration 93 mSettingModel.updateSwitchValue(common.string.KEY_OF_INTEGRATION_SWITCH, 94 actionData.booleanValue, callback); 95 break; 96 case common.route.MESSAGE_CODE_UPDATE_MALICIOUS_WEBSITE_IDENTIFICATION_VALUE: 97 // Malicious Website Identification 98 mSettingModel.updateSwitchValue(common.string.KEY_OF_MALICIOUS_WEB_SWITCH, 99 actionData.booleanValue, callback); 100 break; 101 case common.route.MESSAGE_CODE_UPDATE_SHOW_CONTACT_PROFILE_PICS_VALUE: 102 // Display contact avatar 103 mSettingModel.updateSwitchValue(common.string.KEY_OF_SHOW_CONTACT_SWITCH, 104 actionData.booleanValue, callback); 105 break; 106 default: 107 HiLog.w(TAG, 'updateSettingValue, code is not exit'); 108 } 109 }, 110 111 /** 112 * Obtains the switch value on the advanced settings page. 113 * 114 * @param {Object} callback 115 */ 116 getAdvancedPageSwitchValue(callback) { 117 mSettingModel.getAdvancedPageSwitchValue(callback); 118 }, 119 120 /** 121 * Updating SMSC Numbers 122 * @param actionData 123 * @param callback 124 * @return 125 */ 126 updateSmscNumber(actionData) { 127 mSettingModel.updateSmscNumber(actionData, result => { 128 if (result.code == common.int.SUCCESS) { 129 HiLog.i(TAG, 'updateSmscNumber, success'); 130 } else { 131 HiLog.w(TAG, 'updateSmscNumber, fail'); 132 } 133 }); 134 }, 135 136 /** 137 * Share the selected content in the SMSC dialog box. 138 * @param actionData 139 * @param callback 140 * @return 141 */ 142 shareSmsEnterSelectedText(actionData) { 143 // The sharing API is not provided. 144 mSettingModel.shareSmsEnterSelectedText(actionData, result => { 145 if (result.code == common.int.SUCCESS) { 146 HiLog.i(TAG, 'shareSmsEnterSelectedText, success'); 147 } else { 148 } 149 }); 150 }, 151 152 /** 153 * Values of the notification information integration switch and whether to display contact avatars 154 */ 155 getSettingFlagForConvListPage() { 156 let result: LooseObject = { 157 'isShowContactHeadIcon': false, 158 'hasAggregate': false, 159 'recallMessagesFlag': false, 160 }; 161 mSettingModel.getSettingValue(settingValue => { 162 if (settingValue.code === common.int.SUCCESS) { 163 HiLog.i(TAG, 'getSettingFlagForConvListPage, Success'); 164 if (settingValue.abilityResult.isShowContactHeadIcon === common.bool.TRUE || 165 settingValue.abilityResult.isShowContactHeadIcon === '') { 166 result.isShowContactHeadIcon = true; 167 } 168 if (settingValue.abilityResult.hasAggregate == common.bool.TRUE || 169 settingValue.abilityResult.hasAggregate === '') { 170 result.hasAggregate = true; 171 } 172 if (settingValue.abilityResult.recallMessagesFlag == common.bool.TRUE || 173 settingValue.abilityResult.recallMessagesFlag === '') { 174 result.recallMessagesFlag = true; 175 } 176 } else { 177 HiLog.w(TAG, 'getSettingFlagForConvListPage, fail'); 178 } 179 }); 180 return result; 181 }, 182 183 /** 184 * Determine whether a delivery report is required. 185 * 186 * @param {boolean} isMms MMS or not 187 */ 188 judgeIsDeliveryReport(isMms) { 189 let deliveryReportSwitch = MmsPreferences.getInstance().getValueOfDeliveryReportSwitch(); 190 if (deliveryReportSwitch === common.DELIVERY_REPORTS.DISABLED) { 191 return false; 192 } 193 // For MMS and SMS messages, true is returned. 194 if (deliveryReportSwitch === common.DELIVERY_REPORTS.SMS_AND_MMS) { 195 return true; 196 } 197 // A delivery report is available only when a message is sent. 198 if (deliveryReportSwitch == common.DELIVERY_REPORTS.SMS && !isMms) { 199 return true; 200 } 201 // Delivery reports are available only when MMS messages are sent. 202 if (deliveryReportSwitch == common.DELIVERY_REPORTS.MMS && isMms) { 203 return true; 204 } 205 return false; 206 }, 207 208 /** 209 * Calculate Selected Values 210 * @param mmsList 211 * @param isAllSelect 212 */ 213 calculateChecked(simMessageList, isAllSelect) { 214 let count = 0; 215 let checkedList = []; 216 let result: LooseObject = {}; 217 let switchOff = false; 218 for (let item of simMessageList) { 219 // If you select all 220 if (isAllSelect || item.isCbChecked) { 221 switchOff = true; 222 } 223 if (switchOff) { 224 checkedList.push(item); 225 count++; 226 } 227 switchOff = false; 228 } 229 result.count = count; 230 result.checkedList = checkedList; 231 return result; 232 }, 233}