1// @ts-nocheck 2 3/** 4 * Copyright (c) 2022 Huawei Device Co., Ltd. 5 * Licensed under the Apache License, Version 2.0 (the "License"); 6 * you may not use this file except in compliance with the License. 7 * You may obtain a copy of the License at 8 * 9 * http://www.apache.org/licenses/LICENSE-2.0 10 * 11 * Unless required by applicable law or agreed to in writing, software 12 * distributed under the License is distributed on an "AS IS" BASIS, 13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 * See the License for the specific language governing permissions and 15 * limitations under the License. 16 */ 17 18import LooseObject from "../../data/LooseObject" 19import router from '@ohos.router'; 20import contactService from '../../service/ContractService'; 21import common from '../../data/commonData'; 22import commonService from '../../service/CommonService' 23import conversationListService from "../../service/ConversationListService"; 24import AvatarColor from "../../model/common/AvatarColor"; 25import DateUtil from "../../utils/DateUtil"; 26import TransmitMsgDataSource from "../../model/TransmitMsgDataSource"; 27// Log tool class 28import HiLog from "../../utils/HiLog"; 29 30const TAG = "TransmitMsgController" 31 32export default class TransmitMsgController { 33 private static sInstance: TransmitMsgController; 34 private routerParams: LooseObject = router.getParams() 35 // Total 36 total: 0; 37 // Information List 38 contractsList: Array<any> = []; 39 // List of contents forwarded by multiple messages 40 transmitContentList: Array<any> = []; 41 // Dual SIM card 42 doubleCard: boolean = false; 43 // Contents 44 content: string = ''; 45 // MMS attachment address 46 msgUriPath: string = ''; 47 // Number of Contacts 48 contactsNum: number = 0; 49 // Contact Name 50 contactName: string = ''; 51 // Format the mobile number. 52 telephoneFormat: string = ''; 53 // Multi-crowd hair only shows one person 54 contactNameSplit: string = ''; 55 // Only one mobile phone number is displayed for multiple people. 56 telephoneFormatSplit: string = ''; 57 // Mobile phone number 58 telephone: string = ''; 59 // Whether selected 60 isChecked: boolean = true; 61 // Indicates whether the message is an MMS message. 62 isMms: boolean = false; 63 // Card 1 64 simOne: number = 0; 65 // Card 2 66 simTwo: number = 1; 67 // Sending SMS message ID 68 threadId: string = ''; 69 // Forwarded Content Title 70 transmitContent: string = ''; 71 // Formatted forwarding content 72 transmitContentFormat: ''; 73 // Forwarding Content Editing Status Content 74 transmitContentEdit: string = ''; 75 // Display Forwarding Dialog Box 76 contractsPage: boolean = false; 77 // The font size of the dialog title is displayed. When the number of characters is small, the large font is 78 // displayed. When the number of characters is large, the small font is displayed. 79 titleChecked: boolean = false; 80 // Contact length threshold in dialog title 81 contactNameLen: number = 20; 82 // List pagination, number of pages 83 page: number = 0; 84 // Number of pages 85 limit: number = 15; 86 // Indicates whether the slide page is an MMS message. 87 isSlideDetail: boolean = false; 88 // MMS list data 89 mmsSource: Array<any> = []; 90 transmitItemSources: Array<any> = []; 91 reg: RegExp = /^[\u4e00-\u9fa5_a-zA-Z]+$/; 92 dialogMsg: LooseObject = {}; 93 DialogShow: false; 94 transmitMsgDataSource: TransmitMsgDataSource = new TransmitMsgDataSource(); 95 96 static getInstance() { 97 if (TransmitMsgController.sInstance == null) { 98 TransmitMsgController.sInstance = new TransmitMsgController(); 99 } 100 return TransmitMsgController.sInstance; 101 } 102 103 onInit() { 104 // List of contents forwarded by multiple messages 105 this.transmitContentList = router.getParams().transmitContentList; 106 this.dialogMsg.transmitContentList = this.transmitContentList; 107 this.dialogMsg.transmitContent = router.getParams().transmitContent; 108 this.threadId = router.getParams().threadId; 109 } 110 111 onShow() { 112 this.page = 0; 113 this.requestItem(); 114 } 115 116 // Obtaining List Data by Page 117 requestItem() { 118 let count = this.page * this.limit; 119 if (this.page === 0) { 120 this.page++; 121 this.queryAllMessages(); 122 } else if (count < this.total && this.contractsList.length > (this.page - 1) * this.limit) { 123 // The restriction on contractsList is to prevent multiple update requests during initialization. 124 this.page++; 125 this.queryAllMessages(); 126 } 127 } 128 129 // Queries all list information. 130 queryAllMessages() { 131 let that = this; 132 let actionData: LooseObject = {}; 133 actionData.page = this.page; 134 actionData.limit = this.limit; 135 conversationListService.querySessionList(actionData, result => { 136 if (result.code == common.int.SUCCESS) { 137 this.contractsList = this.buildSessionList(result);; 138 this.transmitMsgDataSource.refresh(this.contractsList); 139 this.total = result.total; 140 this.hasNoOrdinaryMsg = this.total == 0 ? true : false; 141 this.hasInfoMsg = result.hasInfoMsg; 142 } 143 }); 144 } 145 146 buildSessionList(result) { 147 let res = []; 148 result.response.forEach(item => { 149 // Inherit selected items 150 this.contractsList.some(oldItem => { 151 if (item.threadId === oldItem.threadId) { 152 item.isCbChecked = oldItem.isCbChecked; 153 return true; 154 } 155 }); 156 let obj: LooseObject = {}; 157 obj = item; 158 obj.isDelShow = false; 159 obj.itemLeft = 0; 160 obj.photoFirstName = common.string.EMPTY_STR; 161 if( obj.name !== common.string.EMPTY_STR && this.reg.test(obj.name.substring(0, 1))) { 162 obj.photoFirstName = obj.name.substring(0, 1).toUpperCase(); 163 } 164 obj.portraitColor = AvatarColor.background.Color[Math.abs(parseInt(obj.threadId, 10)) % 6]; 165 // Time conversion 166 DateUtil.convertDateFormatForItem(item, false); 167 // Processes the display of the MMS message content. 168 this.dealMmsListContent(item); 169 res.push(obj); 170 }); 171 return res; 172 } 173 174 dealMmsListContent(item) { 175 if (item.hasMms && item.hasAttachment) { 176 if (item.content == common.string.EMPTY_STR) { 177 item.content = $r("app.string.attachment_no_subject"); 178 } else { 179 item.content = $r("app.string.attachment", item.content); 180 } 181 } 182 if (item.hasMms && !item.hasAttachment && item.content == common.string.EMPTY_STR) { 183 item.content = $r("app.string.no_subject"); 184 } 185 } 186 // A dialog box is displayed when you touch a recent contact. 187 clickSendMessage(item) { 188 this.contactName = item.conversation.name; 189 let contactsParamMsg: LooseObject = {}; 190 contactsParamMsg.contactsNum = item.conversation.contactsNum; 191 contactsParamMsg.contactName = item.conversation.name; 192 contactsParamMsg.telephoneFormat = item.conversation.telephoneFormat; 193 contactsParamMsg.telephone = item.conversation.telephone; 194 contactsParamMsg.contactNameSplit = item.conversation.name.split(common.string.COMMA)[0]; 195 contactsParamMsg.telephoneFormatSplit = item.conversation.telephoneFormat.split(common.string.COMMA)[0]; 196 this.threadId = item.conversation.threadId; 197 this.dialogMsg.contactsParam = contactsParamMsg; 198 // Determine the font length of a contact. 199 this.checkContactNameLen(); 200 } 201 202 checkContactNameLen() { 203 if (this.contactName != null && this.contactName.length > this.contactNameLen) { 204 this.titleChecked = true; 205 } else { 206 this.titleChecked = false; 207 } 208 } 209 210 jumpToSelectContracts(callback) { 211 // The page for selecting a contact is displayed. 212 let actionData: LooseObject = {}; 213 actionData.pageFlag = common.contractPage.PAGE_FLAG_SINGLE_CHOOSE; 214 this.jumpToContractForResult(actionData, callback); 215 } 216 217 // Go to Contacts app 218 async jumpToContractForResult(actionData, callback) { 219 let str = commonService.commonContractParam(actionData); 220 let data = await globalThis.mmsContext.startAbilityForResult(str); 221 this.dialogMsg.data = data; 222 if (data.resultCode == 0 && JSON.parse(data.want.parameters.contactObjects).length != 0) { 223 this.DialogShow = true; 224 let contactsParam = contactService.dealContractParams(data.want.parameters.contactObjects); 225 let contactsParamMsg: LooseObject = {}; 226 contactsParamMsg.contactsNum = contactsParam.contactsNum; 227 contactsParamMsg.contactName = contactsParam.strContactsName; 228 contactsParamMsg.telephoneFormat = contactsParam.strContactsNumberFormat; 229 contactsParamMsg.telephone = contactsParam.strContactsNumber; 230 contactsParamMsg.contactNameSplit = contactsParam.strContactsName.split(common.string.COMMA)[0]; 231 contactsParamMsg.telephoneFormatSplit = contactsParam.strContactsNumberFormat.split(common.string.COMMA)[0]; 232 this.dialogMsg.contactsParam = contactsParamMsg; 233 conversationListService.querySessionByTelephone(this.telephone, res => { 234 let response = res.response; 235 if (res.code === common.int.SUCCESS && response.id > 0) { 236 this.threadId = response.id; 237 } else { 238 this.threadId = 0; 239 } 240 this.checkContactNameLen(); 241 }); 242 callback(); 243 244 } 245 } 246 247 // Include Forward Message Source Button Switch - SMS 248 changeValue(item, e) { 249 item.content = e.text; 250 } 251 252 transmit() { 253 let params = { 254 threadId: this.threadId, 255 strContactsName: this.dialogMsg.contactsParam.contactName, //Contact Name 256 strContactsNumber: this.dialogMsg.contactsParam.telephone, //Mobile phone number 257 strContactsNumberFormat: this.dialogMsg.contactsParam.telephoneFormat, //Format the mobile number. 258 transmitFlag: true, //Send Flag 259 contractsPage: false, //Display Forwarding Dialog Box 260 mmsSource: this.mmsSource, //MMS list data 261 isSlideDetail: this.isSlideDetail,//Indicates whether the slide page is an MMS message. 262 transmitSource: this.transmitContentList,//List of contents forwarded by multiple messages 263 isContainerOriginSource: this.isChecked //Whether selected 264 } 265 router.replaceUrl({ 266 url: 'pages/conversation/conversation', 267 params: params 268 }); 269 } 270} 271