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 */ 15import router from '@system.router'; 16import Prompt from '@system.prompt'; 17import emitter from '@ohos.events.emitter'; 18 19import HiLog from '../../utils/HiLog' 20import common from '../../data/commonData' 21import commonEvent from '@ohos.commonEventManager'; 22import ContactsService from '../../service/ContactsService'; 23import ConversationService from '../../service/ConversationService'; 24import ConversationListService from '../../service/ConversationListService'; 25import LooseObject from '../../data/LooseObject' 26import commonService from '../../service/CommonService'; 27import settingService from '../../service/SettingService'; 28import { commonPasteboard } from '../../data/Pasteboard'; 29import telephoneUtil from '../../utils/TelephoneUtil'; 30import callService from '../../service/CallService'; 31import sendMsgService from '../../service/SendMsgService' 32import MmsPreferences from '../../utils/MmsPreferences'; 33import dateUtil from '../../utils/DateUtil'; 34import NotificationService from '../../service/NotificationService'; 35import simCardService from '../../service/SimCardService'; 36import commonCtrl from './common'; 37import AvatarColor from '../../model/common/AvatarColor'; 38 39const TAG = 'ConversationController'; 40const ANIMATION_DURATION = 1500; 41const TRANSFORM_SCALE_MIN = '1.0'; 42const TRANSFORM_SCALE_MAX = '3.0'; 43const COMMON_FILE_SIZE_STRING = '/300KB'; 44 45export default class ConversationController { 46 private static sInstance: ConversationController; 47 commonEventData: any = null; 48 commonCtrl = commonCtrl.getInstance(); 49 // SMS message list update flag 50 refresh: boolean = false; 51 // Message deletion prompt 52 strMsgDeleteDialogTip: Resource; 53 // Click Status 54 isClickStatus: boolean = false; 55 // Whether information is locked 56 hasLockMsg: boolean = false; 57 // Select Status 58 isSelectStatus: boolean = false; 59 // Whether to select lock information 60 isSelectLockMsg: boolean = false; 61 // More Actions 62 isShowMoreOperation: boolean = false; 63 // The default value is false for determining whether the current day is the same. 64 isLessOneDay: boolean = false; 65 // Check whether full-screen conditions are met. 66 isShowFullScreen: boolean = false; 67 // Check whether all the options are selected. 68 isMessageCheckAll: boolean = false; 69 // Is it just a recording? 70 isOnlyAudio: boolean = false; 71 // Deleted Count 72 selectDeleteMsgCount: number = 0; 73 // Text entered in the text box, which is also the content of the SMS message to be sent. 74 textValue: string = ''; 75 // Recording Animation Tasks 76 drawRecordingTaskId: number = 0; 77 // Tab option page. 0: Take a photo; 1: Take a picture; 2: Record a record; 3: More 78 tabIndex: number = 1; 79 // Text content of the tab option page 80 tabTextList: Array<any> = []; 81 // Recording Status 82 isRecordingStatus: boolean = true; 83 // Current recording time 84 curRecordingTime: string = '00:00'; 85 // Size of the current recording file (KB) 86 curSize: number = 0; 87 // Recording Start Time 88 startRecordTime: number = 0; 89 // Airplane mode 90 isFlightMode: boolean = false; 91 // Information Attachment Size Tips 92 msgSendTip: string = ''; 93 // Whether SMS messages can be sent. 94 canSendMessage: boolean = false; 95 // Whether the currently edited message is an MMS message 96 isEditMms: boolean = false; 97 // Size of the MM attachment to be edited. 98 curEdtFileSize: number = 0; 99 // Obtains the time display of a single selection. 100 mmsTime: string = ''; 101 // SMS and MMS 102 isMmsType: Resource; 103 // Recipient 104 isSendRecipient: boolean; 105 // Contact First Name 106 strContactsName: string = ''; 107 // Contact Phone Number 108 strContactsNumber: string = ''; 109 // Contact Phone Number Formatting 110 strContactsNumberFormat: string = ''; 111 // The attachment type is business card. 112 isVCard: boolean = false; 113 // Indicates whether the information is created. 114 isNewMsg: boolean = false; 115 // Number of Contacts 116 contactsNum: number = 0; 117 // business card 118 vCard: {}; 119 // MM Edit List 120 mmsEditList: Array<any> = []; 121 // Information List 122 mmsList: Array<any> = []; 123 // Index of the selected information 124 mmsIndex: number = 0; 125 // Initial x-position 126 rawX: string = ''; 127 // Initial y-position 128 rawY: string = ''; 129 // Thumbnails in Gallery 130 pictureListFromGallery: Array<any> = []; 131 // Tab Title 132 tabTitleText: Resource; 133 // Send Toolbar Distance from Bottom Position 134 sendBarMarginBottom: number = 0; 135 // Tab Height 136 tabHeight: number = common.int.TAB_HEIGHT; 137 // Restoration task ID. 138 restoreTimeoutId: number = 0; 139 // Whether the animation is actually executed 140 isTabHeightAnimation: boolean = false; 141 // 0: default; 1: slide; 2: full screen 142 tabSlideStatus: number = 0; 143 // Sliding distance 144 slideDistance: number = 0; 145 // Start point coordinate of the slide 146 slideStartPoint: LooseObject = { 147 'x': 0, 148 'y': 0 149 }; 150 // Whether to slide up 151 isTabSlideUp: number = 0; 152 // Contact list, which is obtained from the contact app and used as an attachment for sending MMS messages. 153 contactListFromContactApp: Array<any> = []; 154 // Card slot 155 slotId: number = 0; 156 // Selected Contacts 157 selectContacts: Array<any> = []; 158 // Content in the recipient text box 159 receiveContactValue: string = ''; 160 // Controls the display and hiding of the last div. 161 isSendStatus: boolean = false; 162 // ID of the session list. 163 threadId: number = 0; 164 // Indicates whether the page is a details page. 165 isDetail: boolean = true; 166 // Subscript to be resent 167 reSendIndex: number = 0; 168 // Whether the replication option is visible 169 showText: boolean = true; 170 // Search for the value passed 171 searchKey: string = ''; 172 // Is it grass? 173 isDraft: boolean = false; 174 // Contents of the draft 175 draftContent: string = ''; 176 draftGroupId: number = 0; 177 // Can I double-click to cancel sending 178 recallMessagesFlag: boolean = false; 179 // Double-click Cancel Status 180 doubleClickStatus: boolean = false; 181 // Dynamic change sign from bottom 182 distanceBottomFlag: boolean = false; 183 // Deleting a Details Page 184 hasDetailDelete: boolean = false; 185 // Whether a contact exists 186 hasExitContact: boolean = false; 187 // Create a page for fetching and sending. 188 isNewRecallMessagesFlag: boolean = false; 189 // Recording animation 190 recordingAnimation: LooseObject = {}; 191 // Animation Style Properties 192 animationOptions: LooseObject = {}; 193 // Animation Style Attribute Object 194 animationFrames: LooseObject = {}; 195 // Default rear camera 196 cameraPattern: string = 'back'; 197 pattern: string = ''; 198 // Lock or Not 199 hasLock: boolean = false; 200 // Highlight Message Type 201 highlightsType: number = 0; 202 // Highlight Message Content 203 highlightsText: string = ''; 204 timeFormat: string = '00:01'; 205 // 0: normal; 1: notification 206 smsType: number = 0; 207 isPicCheckboxClicked: boolean = false; 208 // Whether to support sending reports 209 hasReport: boolean = false; 210 messageType: number = common.MESSAGE_TYPE.NORMAL; 211 textareaDatasource: Array<any> = []; 212 pptTotalCount: number = 0; 213 selectedTextareaIdx: -1; 214 hasImage: boolean = false; 215 hasContent: boolean = false; 216 hasVcard: boolean = false; 217 mmsAddType: number = 0; 218 picItemSelectedIndex: number = -1; 219 slideDuration: number = 5; 220 slideDurations: Array<any> = []; 221 hasDouble: boolean = true; 222 searchContent: string = ''; 223 // Time 224 mmsDateSet: Set<any> = new Set(); 225 photoFirstName: string = ''; 226 portraitColor: string = ''; 227 reg: RegExp = /^[\u4e00-\u9fa5_a-zA-Z]+$/; 228 scroller: Scroller = new Scroller(); 229 230 static getInstance() { 231 if (ConversationController.sInstance == null) { 232 ConversationController.sInstance = new ConversationController(); 233 } 234 return ConversationController.sInstance; 235 } 236 237 onInit() { 238 HiLog.i(TAG, 'onInit'); 239 this.initRouterData(); 240 this.initData(); 241 if (this.hasDouble) { 242 this.initNewPageContacts(); 243 this.hasDouble = false; 244 } 245 // Obtains the actual data. You do not need to query the data when creating new data. 246 if (!this.isNewMsg) { 247 this.queryMessageDetail(this.strContactsNumber, this.threadId, () => { 248 }); 249 this.scroller.scrollToIndex(this.mmsList.length - 1) 250 } 251 let actionData: LooseObject = {}; 252 actionData.threadId = this.threadId; 253 actionData.hasRead = common.is_read.UN_READ; 254 NotificationService.getInstance().cancelMessageNotify(actionData); 255 NotificationService.getInstance().updateBadgeNumber(); 256 } 257 258 onShow() { 259 HiLog.i(TAG, 'onShow'); 260 // Check whether the Send button can be clicked. 261 this.judgeSendBtnCanClicked(); 262 // Subscribe to PA 263 this.subscribeDetail(); 264 // Check whether a contact exists. 265 this.judgeContactExists(); 266 // Initialize the forwarded data 267 this.initTransmitMeg(); 268 // Forwarding and sending 269 this.transmitSend(); 270 } 271 272 onHide() { 273 HiLog.i(TAG, 'onHide'); 274 this.unSubscribeDetail(); 275 } 276 277 initData() { 278 this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_con_tip2', 279 this.selectDeleteMsgCount 280 ); 281 this.tabTextList = [ 282 // $r('app.string.msg_take_photos'), 283 // $r('app.string.msg_picture'), 284 // $r('app.string.msg_record'), 285 // $r('app.string.more_low') 286 ]; 287 this.animationOptions = { 288 duration: ANIMATION_DURATION, 289 easing: 'linear', 290 fill: 'forwards', 291 iterations: 'Infinity', 292 }; 293 this.animationFrames = [ 294 { 295 transform: { 296 scale: TRANSFORM_SCALE_MIN 297 } 298 }, 299 { 300 transform: { 301 scale: TRANSFORM_SCALE_MAX 302 } 303 } 304 ]; 305 // this.pattern = $r('app.string.camera_post'); 306 this.initSlideDurations(); 307 } 308 309 initSlideDurations() { 310 let arr = []; 311 for (let i = 1; i <= 10; i++) { 312 arr.push(i); 313 } 314 this.slideDurations = arr; 315 } 316 317 release() { 318 this.textValue = ''; 319 this.receiveContactValue = ''; 320 this.isDraft = false; 321 this.mmsList = []; 322 } 323 324 initNewPageContacts() { 325 let transmitContacts = []; 326 if (this.strContactsNumber) { 327 let contactsNames = this.strContactsName.split(','); 328 let telephones = this.strContactsNumber.split(','); 329 let telephoneFormat = this.strContactsNumberFormat.split(','); 330 for (let index in contactsNames) { 331 let item: LooseObject = {}; 332 item.contactName = contactsNames[index]; 333 item.telephone = telephones[index]; 334 if (contactsNames[index] == common.string.EMPTY_STR && 335 telephoneFormat[index] == common.string.EMPTY_STR) { 336 item.telephoneFormat = telephones[index]; 337 } else { 338 item.telephoneFormat = telephoneFormat[index]; 339 } 340 item.headImage = common.string.EMPTY_STR; 341 item.select = false; 342 transmitContacts.push(item); 343 } 344 } 345 this.commonCtrl.paramContact.transmitContacts = transmitContacts; 346 this.commonCtrl.paramContact.isSelectContact = false; 347 this.commonCtrl.paramContact.isNewRecallMessagesFlag = false; 348 } 349 350 initRouterData() { 351 let routerParams: LooseObject = router.getParams(); 352 this.strContactsName = 353 routerParams.strContactsName == undefined ? '' : routerParams.strContactsName; 354 this.strContactsNumber = 355 routerParams.strContactsNumber == undefined ? '' : routerParams.strContactsNumber; 356 this.strContactsNumberFormat = 357 routerParams.strContactsNumberFormat == undefined ? '' : routerParams.strContactsNumberFormat; 358 this.contactsNum = routerParams.contactsNum == undefined ? 0 : routerParams.contactsNum; 359 this.threadId = routerParams.threadId == undefined ? 0 : routerParams.threadId; 360 this.isDraft = routerParams.isDraft == undefined ? false : routerParams.isDraft; 361 this.draftContent = routerParams.draftContent == undefined ? '' : routerParams.draftContent; 362 this.searchContent = routerParams.searchContent == undefined ? '' : routerParams.searchContent; 363 this.isNewMsg = routerParams.isNewMsg == undefined ? false : routerParams.isNewMsg; 364 this.portraitColor = AvatarColor.background.Color[Math.abs(this.threadId) % 6]; 365 this.photoFirstNameDeal(this.strContactsName); 366 this.dealSpecialPhoneNumber(); 367 } 368 369 photoFirstNameDeal(strContactsName) { 370 if (strContactsName !== common.string.EMPTY_STR && this.reg.test(strContactsName.substring(0, 1))) { 371 this.photoFirstName = strContactsName.substring(0, 1).toUpperCase() 372 } else { 373 this.photoFirstName = '-1' 374 } 375 } 376 377 // Handle invalid phone numbers that contain #, *, and dots in redirection from other applications. 378 // Replace them with spaces. 379 dealSpecialPhoneNumber() { 380 if (!this.isPhoneNumber(this.strContactsNumber)) { 381 this.strContactsNumber = this.replaceCode(this.strContactsNumber); 382 this.strContactsNumberFormat = this.replaceCode(this.strContactsNumberFormat); 383 if (this.strContactsName != common.string.EMPTY_STR) { 384 this.strContactsName = common.string.EMPTY_STR; 385 } 386 } 387 } 388 389 replaceCode(str) { 390 if (str != null && str.length != 0) { 391 return str.replace(new RegExp(/e|-|#|\*|\./, 'g'), common.string.EMPTY_STR); 392 } else { 393 return common.string.EMPTY_STR; 394 } 395 } 396 397 titleBarCancel() { 398 // Cancel button 399 this.cancelCheckedAll(); 400 this.setSelectStatus(false); 401 } 402 403 onBackPress() { 404 if (this.isSelectStatus) { 405 // Multi-choice status 406 this.isSelectStatus = false; 407 this.cancelCheckedAll(); 408 return true; 409 } 410 let source = this.getMmsSource(); 411 this.insertAndUpdateSessionDraft(source, () => { 412 this.release(); 413 router.back(); 414 }); 415 return true; 416 } 417 418 insertAndUpdateSessionDraft(source, callback) { 419 // Create a draft. If the selected contact or content is empty, delete the draft. 420 if (this.isNewMsg && this.isDraft) { 421 if ((this.selectContacts.length == 0 && this.receiveContactValue == common.string.EMPTY_STR) || 422 (this.textValue == common.string.EMPTY_STR && source.length == 0)) { 423 let condition: LooseObject = {}; 424 condition.threadId = this.threadId; 425 ConversationListService.getInstance().deleteSessionByCondition(condition, null, null); 426 this.deleteDraftData(); 427 } 428 } 429 let actionData: LooseObject = {}; 430 actionData.slotId = this.slotId; 431 actionData.threadId = this.threadId; 432 actionData.receiveContactValue = common.string.EMPTY_STR; 433 actionData.selectContacts = []; 434 actionData.content = this.textValue; 435 actionData.isReceive = false; 436 actionData.ownNumber = common.string.EMPTY_STR; 437 actionData.isSender = common.is_sender.NO; 438 actionData.hasDraft = common.has_draft.HAVE; 439 actionData.hasReport = settingService.judgeIsDeliveryReport(this.isEditMms); 440 actionData.isMms = this.isEditMms; 441 actionData.mmsSource = source; 442 actionData.groupId = this.draftGroupId; 443 actionData.messageType = this.messageType; 444 actionData.hasAttachment = commonService.judgeIsAttachment(source); 445 actionData.isDraft = this.isDraft; 446 // The draft does not exist or the draft needs to be updated. The draft data on the new page needs to be saved. 447 if (this.textValue != common.string.EMPTY_STR || source.length !== 0) { 448 actionData.isNewMsg = this.isNewMsg; 449 if (this.isNewMsg) { 450 // If the selected contact is not empty 451 if (this.selectContacts.length > 0) { 452 actionData.selectContacts = this.selectContacts; 453 ConversationListService.getInstance().insertSessionDraft(actionData, callback, null); 454 } 455 // If the recipient input field is not empty 456 else if (this.receiveContactValue != common.string.EMPTY_STR) { 457 actionData.receiveContactValue = this.receiveContactValue; 458 // If the number entered in the text box is invalid, the system does not save the draft when the 459 // Back key is pressed. 460 if (this.isPhoneNumber(this.receiveContactValue)) { 461 ConversationListService.getInstance().insertSessionDraft(actionData, callback, null); 462 } else if (this.isDraft) { 463 // If the current draft is in draft state and the entered number is invalid, the current draft 464 // is deleted. 465 let condition: LooseObject = {}; 466 condition.threadId = this.threadId; 467 ConversationListService.getInstance().deleteSessionByCondition(condition, null, null); 468 this.deleteDraftData(); 469 callback(); 470 } else { 471 callback(); 472 } 473 } else { 474 callback(); 475 } 476 } else { 477 // This is not a new scenario. 478 actionData.telephone = this.strContactsNumber; 479 ConversationListService.getInstance().insertSessionDraft(actionData, callback, null); 480 } 481 } else if (!this.isNewMsg && this.isDraft) { 482 // If a draft exists, perform the following operations: 483 this.dealSessionDraft(source); 484 callback(); 485 } else { 486 callback(); 487 } 488 } 489 490 // When the draft logic is set, the text content is empty and the page is not created, the session list data needs 491 // to be updated. 492 dealSessionDraft(source) { 493 let valueBucket: LooseObject = { 494 'content': common.string.EMPTY_STR, 495 'has_draft': common.has_draft.NO, 496 'time': new Date().getTime(), 497 'has_mms': common.has_mms.NO, 498 'has_attachment': common.has_attachment.NO 499 } 500 // Query the last content in the list 501 let length: number = this.mmsList.length; 502 if (length > 0) { 503 let item: LooseObject = this.mmsList[length - 1]; 504 valueBucket.content = item.content; 505 valueBucket.has_mms = item.isMsm ? common.has_mms.HAVE : common.has_mms.NO; 506 valueBucket.has_attachment = item.isMsm ? common.has_attachment.HAVE : common.has_attachment.NO; 507 } 508 let condition: LooseObject = {}; 509 condition.threadId = this.threadId; 510 ConversationListService.getInstance().updateSessionByCondition(condition, valueBucket, null, null); 511 this.deleteDraftData(); 512 this.isDraft = false; 513 } 514 515 cancelCheckedAll() { 516 for (let element of this.mmsList) { 517 element.isCbChecked = false; 518 } 519 } 520 521 clickGroupCheckAll() { 522 for (let element of this.mmsList) { 523 element.isCbChecked = !this.isMessageCheckAll; 524 } 525 if (this.isMessageCheckAll) { 526 this.setMessageCheckAll(common.int.CHECKBOX_SELECT_NONE); 527 } else { 528 this.setMessageCheckAll(common.int.CHECKBOX_SELECT_ALL); 529 } 530 } 531 532 setMessageCheckAll(type) { 533 HiLog.i(TAG, 'setMessageCheckAll, isSelectStatus=' + this.isSelectStatus); 534 if (!this.isSelectStatus) { 535 return; 536 } 537 if (type == common.int.CHECKBOX_SELECT_ALL) { 538 HiLog.i(TAG, 'setMessageCheckAll, CHECKBOX_SELECT_ALL'); 539 this.selectDeleteMsgCount = this.mmsList.length; 540 this.isMessageCheckAll = true; 541 this.hasReport = false; 542 let countLock = 0; 543 // Check whether all of them are locked. 544 for (let element of this.mmsList) { 545 if (element.isCbChecked && element.isLock) { 546 countLock++; 547 } 548 } 549 if (this.selectDeleteMsgCount == countLock) { 550 this.hasLock = true; 551 } 552 } else if (type == common.int.CHECKBOX_SELECT_NONE) { 553 HiLog.i(TAG, 'setMessageCheckAll, CHECKBOX_SELECT_NONE'); 554 this.selectDeleteMsgCount = 0; 555 this.isMessageCheckAll = false; 556 this.hasLock = false; 557 this.hasReport = false; 558 } else { 559 // The default value is CHECKBOX_SELECT_UNKNOWN. Check whether there is any unselected item. 560 HiLog.i(TAG, 'setMessageCheckAll, else'); 561 this.checkBoxSelectUnknow(); 562 } 563 } 564 565 checkBoxSelectUnknow() { 566 HiLog.i(TAG, 'checkBoxSelectUnknow, start'); 567 // The default value is CHECKBOX_SELECT_UNKNOWN. Check whether there is any unselected item. 568 this.isMessageCheckAll = true; 569 this.selectDeleteMsgCount = 0; 570 let countLock = 0; 571 let countReport = 0; 572 for (let element of this.mmsList) { 573 if (element.isCbChecked) { 574 this.selectDeleteMsgCount++; 575 } else if (this.isMessageCheckAll) { 576 this.isMessageCheckAll = false; 577 } 578 if (element.isCbChecked && element.isLock) { 579 countLock++; 580 } 581 if (element.isCbChecked && element.hasReport) { 582 countReport++; 583 } 584 } 585 // If one is selected and there is a lock 586 if (this.selectDeleteMsgCount == 1 && countLock > 0) { 587 this.hasLock = true; 588 } else { 589 this.hasLock = false; 590 } 591 // If all are checked and all are locked 592 if (this.selectDeleteMsgCount == countLock) { 593 this.hasLock = true; 594 } 595 if (countReport == 1) { 596 this.hasReport = true; 597 } else { 598 this.hasReport = false; 599 } 600 } 601 602 listCheckBoxChange(index, e) { 603 // When API 7 is used, the isOn type is not boolean but is of the number type. If the isOn type is displayed, 604 // an error may occur. 605 let isCheck: string = e 606 // this.messageList[index].isCbChecked = isCheck == '1' ? true : false; 607 let item = this.mmsList[index]; 608 item.isCbChecked = isCheck == '1' ? true : false; 609 HiLog.i(TAG, `listCheckBoxChange, isCbChecked=${item.isCbChecked}, index=${index}, mmsIndex=${this.mmsIndex}`); 610 this.mmsIndex = index; 611 this.hasReport = item.hasReport; 612 this.setMessageCheckAll(common.int.CHECKBOX_SELECT_UNKNOWN); 613 if (this.selectDeleteMsgCount == 1) { 614 let item; 615 for (let element of this.mmsList) { 616 if (element.isCbChecked) { 617 item = element; 618 break; 619 } 620 } 621 if (item != null) { 622 this.setGroupMoreMenu(item); 623 } 624 } 625 } 626 627 setGroupMoreMenu(item) { 628 if (!item.isMsm) { 629 this.hasContent = true; 630 return; 631 } 632 this.hasContent = commonService.judgeIsSelectText(item.mms); 633 this.hasImage = commonService.judgeIsImage(item.mms); 634 if (item.isMsm && item.mms.length == 1 && item.mms[0].type == common.MSG_ITEM_TYPE.CARD) { 635 this.hasVcard = true; 636 } else { 637 this.hasVcard = false; 638 } 639 } 640 641 longPressSelected(index) { 642 switch (index) { 643 case 0: 644 // duplicating 645 this.copyText(); 646 break; 647 case 1: 648 // Forwarding 649 this.transmitMsgSingle(); 650 break; 651 case 2: 652 // Delete 653 this.deleteDialogShow(); 654 break; 655 case 3: 656 // Select Text 657 this.gotoTextSelect(this.mmsIndex); 658 break; 659 case 4: 660 // more 661 this.more(); 662 break; 663 case 5: 664 // Save 665 this.saveImage(); 666 break; 667 default: 668 break; 669 } 670 } 671 672 // Initializing Forwarding Data 673 initTransmitMeg() { 674 let routerParams: LooseObject = router.getParams(); 675 if (routerParams.transmitFlag) { 676 this.threadId = routerParams.threadId; 677 this.slotId = MmsPreferences.getInstance().getSendMessageSlotId(); 678 this.contactsNum = this.contactsNum; 679 this.strContactsName = routerParams.strContactsName; 680 this.strContactsNumber = routerParams.strContactsNumber; 681 this.strContactsNumberFormat = routerParams.strContactsNumberFormat; 682 this.initNewPageContacts(); 683 } 684 } 685 686 // Forwarding and sending 687 transmitSend() { 688 // Send Flag 689 let transmitFlag = router.getParams().transmitFlag; 690 //Indicates whether the slide page is an MMS message. 691 let isSlideDetail = router.getParams().isSlideDetail; 692 if (transmitFlag) { 693 if (isSlideDetail) { 694 // Indicates whether the currently edited message is an MMS message. 695 this.isEditMms = true; 696 //this.mmsTransmitSend(); 697 } else { 698 this.generalTransmitSend(); 699 } 700 } 701 } 702 703 generalTransmitSend() { 704 let transmitSource: Array<LooseObject> = <Array<LooseObject>> router.getParams().transmitSource; 705 let isSource = router.getParams().isContainerOriginSource; 706 this.canSendMessage = false; 707 for (let element of transmitSource) { 708 let content = common.string.EMPTY_STR; 709 if (isSource && !element.isMsm) { 710 content = element.contentInfo + element.content; 711 } else { 712 content = element.content; 713 } 714 let actionData = { 715 content: content, 716 mmsSource: element.mms, 717 msgUriPath: element.msgUriPath 718 }; 719 this.delayTransmitSend(actionData, element.isMsm); 720 } 721 } 722 723 delayTransmitSend(element, isMms) { 724 this.queryMessageDetail(this.strContactsNumber, this.threadId, () => { 725 this.sendSms(element.content, element.msgUriPath, isMms, element.mmsSource); 726 }); 727 } 728 729 sendSms(content, msgUriPath, isMms, mmsSource): void { 730 // Sending an SMS Message on a Full-Screen Page 731 this.isSendStatus = true; 732 // Initialize the data to be sent. 733 this.initSendSms(content, msgUriPath, isMms, mmsSource); 734 this.slotId = MmsPreferences.getInstance().getSendMessageSlotId(); 735 let actionData: LooseObject = {}; 736 actionData.slotId = this.slotId; 737 actionData.destinationHost = this.strContactsNumber; 738 actionData.content = content; 739 actionData.isEditMms = isMms; 740 this.dealNewRecallMessagesFlag(this.mmsList); 741 HiLog.i(TAG, 'sendSms send start'); 742 // Cancel Sending and Normal Sending Methods 743 this.sendInterval(actionData, this.mmsList); 744 HiLog.i(TAG, 'sendSms send end'); 745 if (this.isEditMms) { 746 this.isEditMms = false; 747 } 748 } 749 750 initSendSms(content, msgUriPath, isMms, mmsSource) { 751 // Obtain the day of the week. 752 let item: LooseObject = {}; 753 item.date = common.string.EMPTY_STR; 754 item.time = $r('app.string.just'); 755 item.timeMillisecond = new Date().getTime(); 756 dateUtil.convertTimeStampToDateWeek(item, false); 757 dateUtil.fullDate(item); 758 item.content = content; 759 if (isMms) { 760 item.msgType = common.MSG_ITEM_TYPE.IMAGE; 761 item.msgUriPath = msgUriPath; 762 } 763 item.isFullScreenImg = false; 764 let time = (this.mmsEditList.length != 0 && (this.mmsEditList[0].type == 3 || this.mmsEditList[0].type == 5)) ? 765 this.mmsEditList[0].time : common.string.SUCCESS; 766 item.audioTime = time; 767 item.isCbChecked = false; 768 item.isLock = false; 769 item.isStared = false; 770 item.isReceive = false; 771 item.sendStatus = 1; 772 item.subId = this.slotId; 773 item.isMsm = isMms; 774 this.contactsNum = this.strContactsNumber.split(',').length; 775 item.contactsNum = this.contactsNum; 776 item.cancelTimeCount = common.int.CANCEL_TIME_COUNT; 777 item.mmsEditListTemp = this.fillmmsEditListTemp(msgUriPath, isMms); 778 if (this.contactsNum > 1) { 779 item.completeNumber = 0; 780 item.failuresNumber = 0; 781 } 782 item.hasReport = settingService.judgeIsDeliveryReport(item.isMsm); 783 item.mmsSource = mmsSource; 784 if (this.isEditMms || isMms) { 785 item.msgShowType = commonService.getDisplay(mmsSource); 786 commonService.setItemMmsContent(item, mmsSource); 787 item.content = this.dealItemContent(item.msgShowType, item.content, mmsSource); 788 } else { 789 item.msgShowType = common.MESSAGE_SHOW_TYPE.NORMAL; 790 } 791 this.mmsList.push(item); 792 } 793 794 fillmmsEditListTemp(msgUriPath, isMsm) { 795 let mmsEditListTemp = []; 796 if (this.recallMessagesFlag && isMsm) { 797 let item: LooseObject = {}; 798 item.type = common.MSG_ITEM_TYPE.IMAGE; 799 item.uriPath = msgUriPath; 800 mmsEditListTemp.push(item); 801 } 802 return mmsEditListTemp; 803 } 804 805 dealNewRecallMessagesFlag(mmsList) { 806 let count = common.int.MESSAGE_CODE_ZERO; 807 for (let index in mmsList) { 808 let item = mmsList[index]; 809 if (!item.isDraft) { 810 count++; 811 } 812 } 813 if (count == common.int.MESSAGE_CODE_ONE) { 814 this.isNewRecallMessagesFlag = true; 815 this.commonCtrl.paramContact.isNewRecallMessagesFlag = true; 816 } 817 if (count == common.int.MESSAGE_CODE_ZERO && this.isNewRecallMessagesFlag) { 818 this.isNewMsg = true; 819 this.isNewRecallMessagesFlag = false; 820 } 821 } 822 823 // Single Forwarding 824 transmitMsgSingle() { 825 // Forwarding a single message 826 let item: LooseObject = this.mmsList[this.mmsIndex]; 827 let transmitObj: LooseObject = {}; 828 let contactsName: string | Resource = common.string.EMPTY_STR; 829 if (this.strContactsName && this.strContactsName != common.string.EMPTY_STR) { 830 contactsName = $r('app.string.transmitContentReceive', this.strContactsName); 831 } else { 832 contactsName = $r('app.string.transmitContentReceive', this.strContactsNumberFormat); 833 } 834 transmitObj.contactsName = contactsName; 835 transmitObj.isMsm = item.isMsm; 836 transmitObj.msgShowType = item.msgShowType; 837 transmitObj.mms = item.mms; 838 transmitObj.content = item.content; 839 transmitObj.msgUriPath = item.msgUriPath ? item.msgUriPath : common.string.EMPTY_STR; 840 transmitObj.contentInfo = common.string.EMPTY_STR; 841 transmitObj.msgType = item.msgType; 842 let transmitContentList = []; 843 transmitContentList.push(transmitObj); 844 let transmitContent = item.isReceive ? contactsName : $r('app.string.transmitContent'); 845 this.jumpTransmitMsg(transmitContent, transmitContentList, item.isMsm); 846 } 847 848 jumpTransmitMsg(transmitContent, transmitContentList, isMms) { 849 router.push({ 850 uri: 'pages/transmitmsg/transmitMsg', 851 params: { 852 threadId: this.threadId, 853 doubleCard: false, 854 transmitContent: transmitContent, 855 transmitContentList: transmitContentList, 856 isMulti: true, 857 isMms: isMms, 858 isMyStartPage: false 859 } 860 }); 861 } 862 863 // Delete a dialog box. 864 deleteDialogShow() { 865 this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_con_tip1'); 866 let item = this.mmsList[this.mmsIndex]; 867 item.isShowMsgLongMenu = false 868 HiLog.i(TAG, 'deleteDialogShow, isShowMsgLongMenu=' + item.isShowMsgLongMenu); 869 this.hasLockMsg = item.isLock; 870 if (!item.isMsm) { 871 this.hasContent = true; 872 return; 873 } 874 } 875 876 // more 877 more() { 878 this.setTabOperationStatus(false); 879 this.distanceBottomFlag = false; 880 let item = this.mmsList[this.mmsIndex]; 881 882 item.isCbChecked = !item.isCbChecked; 883 item.isShowMsgLongMenu = false; 884 HiLog.i(TAG, 'more, isShowMsgLongMenu=' + item.isShowMsgLongMenu); 885 this.setSelectStatus(true); 886 this.hasDetailDelete = false; 887 this.setMessageCheckAll(common.int.CHECKBOX_SELECT_UNKNOWN); 888 this.hasReport = item.hasReport; 889 this.setGroupMoreMenu(item); 890 } 891 892 setTabOperationStatus(flag) { 893 this.isShowMoreOperation = flag; 894 // Value type. The HTML page is refreshed only when the value type is numeric. 895 if (flag) { 896 this.sendBarMarginBottom = common.int.TAB_HEIGHT; 897 } else { 898 this.sendBarMarginBottom = 0; 899 } 900 } 901 902 setSelectStatus(isSelect) { 903 this.isSelectStatus = isSelect; 904 } 905 906 // Event of pressing and holding an SMS message 907 mmsListLongPress(index) { 908 for (let i = 0; i < this.mmsList.length; i++) { 909 if (index == i) { 910 this.mmsList[index].isShowMsgLongMenu = true; 911 } else { 912 this.mmsList[i].isShowMsgLongMenu = false; 913 } 914 } 915 this.refresh = !this.refresh 916 this.mmsIndex = index; 917 if (this.isSelectStatus) { 918 this.mmsList[index].isCbChecked = !this.mmsList[index].isCbChecked; 919 this.setMessageCheckAll(common.int.CHECKBOX_SELECT_UNKNOWN); 920 return; 921 } 922 this.hasContent = false; 923 this.hasImage = false; 924 let item = this.mmsList[index]; 925 let menuId = common.string.EMPTY_STR; 926 if (item.isMsm) { 927 this.setGroupMoreMenu(item); 928 // menuId = 'menu_long_press_mms'; 929 } else { 930 // menuId = 'menu_long_press'; 931 } 932 // setTimeout(() => { 933 // this.$element(menuId).show({ 934 // x: this.rawX, 935 // y: this.rawY 936 // }); 937 // },100); 938 } 939 940 touchStart(e) { 941 this.rawX = e.globalX; 942 this.rawY = e.globalY; 943 944 } 945 946 deleteDialogCancel() { 947 // Cancel Ejection 948 this.isSelectLockMsg = false; 949 HiLog.i(TAG, 'deleteDialogCancel, isSelectLockMsg=false') 950 } 951 952 deleteDialogConfirm() { 953 let groupIds = []; 954 let mmsListCopy = []; 955 HiLog.i(TAG, 'deleteDialogConfirm, isSelectStatus=' + this.isSelectStatus); 956 if (this.isSelectStatus) { 957 // Delete the selected item through the filter. 958 for (let element of this.mmsList) { 959 if (!element.isCbChecked || (element.isLock && !this.isSelectLockMsg)) { 960 this.setDateShow(element, mmsListCopy); 961 mmsListCopy.push(element); 962 } else { 963 groupIds.push(element.groupId); 964 } 965 } 966 // Set to non-multi-choice status 967 this.setSelectStatus(false); 968 this.mmsList = mmsListCopy; 969 } else if ((this.mmsList[this.mmsIndex] != undefined && !this.mmsList[this.mmsIndex].isLock) || this.isSelectLockMsg) { 970 let item = this.mmsList[this.mmsIndex]; 971 for (let i = 0; i < this.mmsList.length; i++) { 972 if (this.mmsIndex == i) { 973 continue; 974 } else { 975 this.setDateShow(this.mmsList[i], mmsListCopy); 976 mmsListCopy.push(this.mmsList[i]); 977 } 978 } 979 this.mmsList = mmsListCopy; 980 HiLog.i(TAG, 'deleteDialogConfirm, mmsList.length=' + this.mmsList.length); 981 groupIds.push(item.groupId); 982 } 983 this.isSelectLockMsg = false; 984 this.cancelCheckedAll(); 985 if (groupIds.length > 0) { 986 this.deleteMessageByGroupIds(groupIds); 987 // Check whether the length of the deleted list is 0. 988 if (this.mmsList.length === 0 && this.textValue === common.string.EMPTY_STR) { 989 globalThis.needToUpdate = true; 990 this.deleteMessageById(this.threadId); 991 router.back(); 992 } else { 993 this.updateSessionLock(false); 994 this.updateLastItemContent(); 995 } 996 } 997 // After the deletion is complete, check whether all data is deleted. 998 } 999 1000 deleteMessageByGroupIds(groupIds): void { 1001 let actionData: LooseObject = {}; 1002 if (groupIds.length == 1) { 1003 actionData.groupId = groupIds[0]; 1004 } else { 1005 actionData.groupIds = groupIds; 1006 } 1007 // Invoke the database deletion method. 1008 ConversationService.getInstance().deleteSmsMmsInfoByCondition(actionData, null, null); 1009 } 1010 1011 // Updates the lock status of the session list. 1012 updateSessionLock(isLock) { 1013 let threadIds = [this.threadId]; 1014 let hasLock = isLock ? 1 : 0; 1015 let valueBucket = { 1016 'has_lock': hasLock, 1017 } 1018 if (!isLock) { 1019 // If you want to unlock the status, you must unlock all the statuses before unlocking the statuses. 1020 let unlockCount = 0; 1021 for (let element of this.mmsList) { 1022 if (!element.isLock) { 1023 unlockCount++; 1024 } 1025 } 1026 if (unlockCount != this.mmsList.length) { 1027 HiLog.w(TAG, 'updateSessionLock, it is not all select unlock'); 1028 return; 1029 } 1030 } 1031 let condition: LooseObject = {}; 1032 condition.threadId = this.threadId; 1033 ConversationListService.getInstance().updateSessionByCondition(condition, valueBucket, null, null); 1034 } 1035 1036 updateLastItemContent() { 1037 let actionData: LooseObject = { 1038 'mmsList': this.mmsList, 1039 'threadId': this.threadId, 1040 }; 1041 ConversationListService.getInstance().updateLastItemContent(actionData, null, null); 1042 } 1043 1044 deleteMessageById(threadId) { 1045 let threadIds = [threadId]; 1046 // Deleting Database Data 1047 let actionData = { 1048 threadIds: threadIds, 1049 }; 1050 ConversationListService.getInstance().deleteMessageById(actionData, null, null); 1051 } 1052 1053 clickGroupDelete() { 1054 if (this.selectDeleteMsgCount == 0) { 1055 return; 1056 } 1057 if (this.selectDeleteMsgCount == 1) { 1058 this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_con_tip1'); 1059 } else if (this.selectDeleteMsgCount == this.mmsList.length) { 1060 this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_con_tip3'); 1061 } else { 1062 this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_con_tip2', this.selectDeleteMsgCount); 1063 } 1064 this.hasLockMsg = (this.mmsList.some((element, index) => element.isCbChecked && element.isLock)); 1065 } 1066 1067 // Check whether a contact exists. 1068 judgeContactExists() { 1069 let actionData: LooseObject = {}; 1070 actionData.telephones = [this.strContactsNumber]; 1071 ContactsService.getInstance().judgeContactExist(actionData, result => { 1072 this.hasExitContact = result; 1073 }, globalThis.mmsContext); 1074 if (this.strContactsName == common.string.EMPTY_STR) { 1075 this.hasExitContact = false; 1076 } else { 1077 this.hasExitContact = true; 1078 } 1079 } 1080 1081 /** 1082 * Obtain information details. 1083 * 1084 * @param telephone 1085 * @param threadId 1086 * @param callback 1087 */ 1088 queryMessageDetail(telephone, threadId, callback) { 1089 let actionData: LooseObject = {}; 1090 if (telephone != common.string.EMPTY_STR) { 1091 actionData.telephone = telephone; 1092 } 1093 if (threadId != common.string.EMPTY_STR) { 1094 actionData.threadId = threadId; 1095 } 1096 actionData.contactsNum = this.contactsNum; 1097 ConversationService.getInstance().queryMessageDetail(actionData, result => { 1098 if (result.code == common.int.SUCCESS) { 1099 this.initIsShowMsgLongMenu(result); 1100 this.dealMessageDetailTime(result); 1101 this.dealMessageDetailContent(result); 1102 if (this.mmsList.length == 0 && this.isDraft) { 1103 HiLog.i(TAG, 'queryMessageDetail, isNewMsg = true'); 1104 this.isNewMsg = true; 1105 } 1106 } else { 1107 HiLog.w(TAG, 'queryMessageDetail, failed'); 1108 } 1109 if (this.isDraft) { 1110 this.setDraft(); 1111 } 1112 this.deleteDraftData(); 1113 }, null); 1114 if (callback) { 1115 callback(); 1116 } 1117 } 1118 1119 initIsShowMsgLongMenu(result) { 1120 for (let item of result.response) { 1121 item.isShowMsgLongMenu = false; 1122 } 1123 } 1124 1125 dealItemContent(showType, content, mmsSource) { 1126 let strContent = content; 1127 if (showType == common.MESSAGE_SHOW_TYPE.THEME_NO_IMAGE || showType == common.MESSAGE_SHOW_TYPE.THEME_IMAGE) { 1128 if (content !== common.string.EMPTY_STR) { 1129 strContent = $r('app.string.msg_theme') + ': ' + content; 1130 } 1131 } else if (showType == common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE) { 1132 strContent = (content == common.string.EMPTY_STR) ? $r('app.string.msg_slide') : content; 1133 } else if (showType == common.MESSAGE_SHOW_TYPE.PPT_IMAGE) { 1134 if (mmsSource[0].msgType == common.MSG_ITEM_TYPE.THEME && content !== common.string.EMPTY_STR) { 1135 strContent = $r('app.string.msg_theme') + ': ' + content; 1136 } else { 1137 strContent = (content == common.string.EMPTY_STR) ? $r('app.string.msg_slide') : content; 1138 } 1139 } 1140 return strContent; 1141 } 1142 1143 dealMessageDetailContent(result) { 1144 for (let item of result.response) { 1145 item.content = this.dealItemContent(item.msgShowType, item.content, item.mms); 1146 } 1147 } 1148 1149 dealMessageDetailTime(result) { 1150 if (result.response && result.response.length > 0) { 1151 let resultList = []; 1152 for (let item of result.response) { 1153 item.timeMillisecond = parseInt(item.timeMillisecond); 1154 dateUtil.fullDate(item); 1155 dateUtil.convertTimeStampToDateWeek(item, false); 1156 this.setDateShow(item, resultList); 1157 dateUtil.convertDateFormatForItem(item, false); 1158 if (item.sendStatus == common.int.SEND_DRAFT) { 1159 this.dealDraftData(item); 1160 } else { 1161 resultList.push(item); 1162 } 1163 } 1164 this.mmsList = resultList; 1165 } 1166 } 1167 1168 deleteDraftData() { 1169 if (this.isDraft && this.draftGroupId > 0) { 1170 let groupIds = [this.draftGroupId]; 1171 this.deleteMessageByGroupIds(groupIds); 1172 this.draftGroupId = 0; 1173 } 1174 } 1175 1176 getMmsDataSource(mmsSource, first) { 1177 this.pptTotalCount = (first.msgType == common.MSG_ITEM_TYPE.THEME) ? -1 : 0; 1178 let mms = []; 1179 let textareas = []; 1180 mmsSource.forEach((source, index) => { 1181 this.pptTotalCount++; 1182 let mmsObj = null; 1183 if (source.msgType == common.MSG_ITEM_TYPE.AUDIO || 1184 source.msgType == common.MSG_ITEM_TYPE.IMAGE || 1185 source.msgType == common.MSG_ITEM_TYPE.VIDEO) { 1186 mmsObj = { 1187 type: source.msgType, 1188 uriPath: source.msgUriPath, 1189 time: source.time, 1190 index: this.pptTotalCount, 1191 fileSize: first.fileSize 1192 }; 1193 mms.push(mmsObj); 1194 } 1195 let placeholder = $r('app.string.enter_text'); 1196 if (source.msgType == common.MSG_ITEM_TYPE.THEME) { 1197 placeholder = $r('app.string.msg_theme'); 1198 } else if (mmsSource[0].msgType == common.MSG_ITEM_TYPE.THEME && mmsSource.length == 2) { 1199 if (mmsObj) { 1200 placeholder = $r('app.string.msg_note_mms2'); 1201 } else { 1202 placeholder = $r('app.string.msg_note_mms'); 1203 } 1204 this.pptTotalCount = 0; 1205 } 1206 let obj = { 1207 textValue: source.content, 1208 placeholder: placeholder, 1209 pptIndex: this.pptTotalCount, 1210 mms: mmsObj 1211 }; 1212 textareas.push(obj); 1213 }); 1214 this.mmsEditList = mms; 1215 this.textareaDatasource = textareas; 1216 } 1217 1218 setMmsDataSource(mmsSource) { 1219 this.mmsEditList = []; 1220 this.textareaDatasource = []; 1221 let first = mmsSource[0]; 1222 this.messageType = first.messageType; 1223 if (this.messageType == common.MESSAGE_TYPE.NORMAL) { 1224 let arr = []; 1225 mmsSource.forEach(item => { 1226 let obj = { 1227 type: item.msgType, 1228 uriPath: item.msgUriPath, 1229 time: item.time, 1230 fileSize: item.fileSize 1231 } 1232 arr.push(obj); 1233 }); 1234 this.mmsEditList = arr; 1235 } else { 1236 this.getMmsDataSource(mmsSource, first); 1237 } 1238 } 1239 1240 dealDraftData(item) { 1241 // this.isDraft = true; 1242 this.draftContent = item.content; 1243 this.draftGroupId = item.groupId; 1244 if (item.isMsm) { 1245 this.isEditMms = true; 1246 this.setMmsDataSource(item.mms); 1247 } else { 1248 this.messageType = common.MESSAGE_TYPE.NORMAL; 1249 } 1250 } 1251 1252 // Set Draft Content 1253 setDraft() { 1254 // If the content is a draft, the draft content needs to be displayed. 1255 if (this.isDraft) { 1256 this.textValue = this.draftContent; 1257 this.canSendMessage = MmsPreferences.getInstance().haveSimCardReady(); 1258 } 1259 } 1260 1261 updateDetail(threadId, sendResult) { 1262 let sendResults: Array<LooseObject> = []; 1263 sendResults.push(sendResult); 1264 let actionData: LooseObject = {}; 1265 actionData.sendResults = sendResults; 1266 actionData.threadId = threadId; 1267 ConversationService.getInstance().updateSessionAndDetail(actionData); 1268 let sendStatus: number = sendResult.sendStatus; 1269 let deliveryReportSwitch: string = MmsPreferences.getInstance().getValueOfDeliveryReportSwitch(); 1270 HiLog.i(TAG, 'updateDetail, sendStatus=' + sendStatus + ', deliveryReportSwitch=' + deliveryReportSwitch); 1271 if ((deliveryReportSwitch == common.DELIVERY_REPORTS.SMS_AND_MMS || 1272 deliveryReportSwitch == common.DELIVERY_REPORTS.SMS) && sendStatus == common.int.SEND_MESSAGE_SUCCESS) { 1273 let msg: string = this.strContactsNumber + ' 已收到消息!' 1274 this.showToast(msg) 1275 } 1276 } 1277 1278 showToast(msg) { 1279 Prompt.showToast({ 1280 message: msg, 1281 duration: 2000, 1282 }); 1283 } 1284 1285 // Setting the Sending Status 1286 setCanSendMsgStatus() { 1287 if (this.receiveContactValue == common.string.EMPTY_STR && this.selectContacts.length == 0) { 1288 this.canSendMessage = false; 1289 } 1290 } 1291 1292 // Obtains the size of the current MMS file. 1293 getCurEdtFileSize() { 1294 this.curEdtFileSize = 0; 1295 if (!this.isEditMms || this.mmsEditList.length == 0) { 1296 return; 1297 } 1298 for (let element of this.mmsEditList) { 1299 this.curEdtFileSize += element.fileSize; 1300 } 1301 } 1302 1303 dealMmsSendResult(sendNumber, item, sendResult) { 1304 HiLog.i(TAG, 'dealMmsSendResult, start') 1305 // MMS Sending 1306 sendResult.sendStatus = common.int.SEND_MESSAGE_SUCCESS; 1307 item.sendStatus = common.int.SEND_MESSAGE_SUCCESS; 1308 this.updateDetail(this.threadId, sendResult); 1309 // The MMS message will be sent for receiving and using. 1310 if (sendNumber.length == 1 && sendResult.sendStatus == common.int.SEND_MESSAGE_SUCCESS) { 1311 setTimeout(() => { 1312 // this.publishData(sendResult.telephone, item.mmsSource); 1313 }, 1000); 1314 } 1315 let params = { 1316 mmsSource: item.mmsSource 1317 }; 1318 sendMsgService.sendMmsMessage(params, (sendStatus) => { 1319 }); 1320 } 1321 1322 dealSmsSendResult(params, item, sendResult) { 1323 sendMsgService.sendMessage(params, (sendStatus) => { 1324 HiLog.i(TAG, 'dealSmsSendResult, sendMessage sendStatus: ' + sendStatus); 1325 item.sendStatus = sendStatus; 1326 if (sendStatus === common.int.SEND_MESSAGE_FAILED) { 1327 item.failuresNumber = item.failuresNumber + 1; 1328 } 1329 item.completeNumber = item.completeNumber + 1; 1330 sendResult.sendStatus = sendStatus; 1331 // Update sending status 1332 this.updateDetail(this.threadId, sendResult); 1333 this.refresh = !this.refresh 1334 }); 1335 } 1336 1337 getSendMessageId(initDatas, telephone): number { 1338 for (let initData of initDatas) { 1339 if (initData == undefined || initData == null) { 1340 return; 1341 } 1342 if (initData.telephone == telephone) { 1343 try { 1344 if (initData.id == undefined || initData.id == null) { 1345 return; 1346 } 1347 } catch (err) { 1348 HiLog.e(TAG, 'this initData.id is undefined ' + JSON.stringify(err)); 1349 } 1350 return initData.id; 1351 } 1352 } 1353 } 1354 1355 convertingSms() { 1356 // Convert to SMS 1357 this.isEditMms = false; 1358 this.showToast($r('app.string.converting_sms')); 1359 } 1360 1361 dealSendResult(actionData, item, initDatas) { 1362 HiLog.i(TAG, 'dealSendResult, start') 1363 // Add sending information to the list. 1364 let sendNumbers: Array<string> = actionData.hosts; 1365 let content: string = actionData.content; 1366 for (let i = 0; i < sendNumbers.length; i++) { 1367 let params: LooseObject = { 1368 'slotId': actionData.slotId, 1369 'destinationHost': sendNumbers[i], 1370 'content': content, 1371 }; 1372 let id: number = this.getSendMessageId(initDatas, sendNumbers[i]); 1373 if (id == undefined || id == null) { 1374 return; 1375 } 1376 let sendResult: LooseObject = { 1377 'id': id, 1378 'telephone': sendNumbers[i], 1379 'content': content, 1380 } 1381 if (!item.isMsm) { 1382 this.dealSmsSendResult(params, item, sendResult); 1383 } else { 1384 this.dealMmsSendResult(sendNumbers, item, sendResult); 1385 } 1386 } 1387 } 1388 1389 insertInitData(actionData, item, callback): void { 1390 let sendNumbers: Array<string> = actionData.hosts; 1391 let insertSendResults: Array<LooseObject> = []; 1392 for (let i = 0; i < sendNumbers.length; i++) { 1393 let sendResult: LooseObject = { 1394 'slotId': actionData.slotId, 1395 'telephone': sendNumbers[i], 1396 'content': actionData.content, 1397 'sendStatus': common.int.SEND_MESSAGE_SENDING 1398 } 1399 if (item.isMsm) { 1400 sendResult.content = commonService.getMmsContent(item.mmsSource); 1401 } 1402 insertSendResults.push(sendResult); 1403 } 1404 let actionData_: LooseObject = {}; 1405 actionData_.sendResults = insertSendResults; 1406 actionData_.isReceive = false; 1407 actionData_.ownNumber = common.string.EMPTY_STR; 1408 actionData_.isSender = common.is_sender.NO; 1409 actionData_.hasDraft = this.isDraft; 1410 actionData_.hasReport = settingService.judgeIsDeliveryReport(item.isMsm) ? 1 : 0; 1411 actionData_.isMms = item.isMsm; 1412 actionData_.mmsSource = item.mmsSource; 1413 actionData_.hasAttachment = commonService.judgeIsAttachment(item.mmsSource); 1414 ConversationService.getInstance().insertSessionAndDetail(actionData_, callback, globalThis.mmsContext); 1415 } 1416 1417 changeReceiveContactValue(value) { 1418 this.receiveContactValue = value 1419 } 1420 1421 updatePreview(idx) { 1422 // Delete Preview 1423 HiLog.i(TAG, 'updatePreview, idx: ' + idx); 1424 // If not audio (picture or video) is deleted from the preview, you need to change the value of 1425 // checkbox in the thumbnail of the gallery. 1426 if (this.mmsEditList[idx].type != common.MSG_ITEM_TYPE.AUDIO) { 1427 let that = this; 1428 this.pictureListFromGallery.forEach(function (item) { 1429 if (item.path == that.mmsEditList[idx].uriPath) { 1430 item.checkedValue = false; 1431 that.curEdtFileSize -= that.mmsEditList[idx].fileSize; 1432 that.msgSendTip = Math.ceil(that.curEdtFileSize) + COMMON_FILE_SIZE_STRING; 1433 } 1434 }); 1435 } 1436 this.isOnlyAudio = !this.mmsEditList.some((item, index) => item.type != common.MSG_ITEM_TYPE.AUDIO); 1437 if (this.mmsEditList.length == 0) { 1438 this.convertingSms(); 1439 } 1440 } 1441 1442 initSendItem() { 1443 // Obtains the day of the week. 1444 HiLog.i(TAG, 'initSendItem, start') 1445 let item: LooseObject = {}; 1446 item.date = common.string.EMPTY_STR; 1447 item.time = $r('app.string.justNow'); 1448 item.timeMillisecond = new Date().getTime(); 1449 dateUtil.convertTimeStampToDateWeek(item, false); 1450 dateUtil.fullDate(item); 1451 item.content = this.textValue; 1452 item.msgType = this.mmsEditList.length != 0 ? this.mmsEditList[0].type : common.MSG_ITEM_TYPE.TEXT; 1453 item.isFullScreenImg = false; 1454 item.msgUriPath = this.mmsEditList.length != 0 ? this.mmsEditList[0].uriPath : common.string.EMPTY_STR; 1455 let time = (this.mmsEditList.length != 0 && (this.mmsEditList[0].type == 3 || this.mmsEditList[0].type == 5)) ? 1456 this.mmsEditList[0].time : common.string.SUCCESS; 1457 item.audioTime = time; 1458 item.isCbChecked = false; 1459 item.isLock = false; 1460 item.isStared = false; 1461 item.isReceive = false; 1462 item.sendStatus = 1; 1463 item.cancelTimeCount = common.int.CANCEL_TIME_COUNT; 1464 item.subId = this.slotId; 1465 item.mmsEditListTemp = this.mmsEditList; 1466 if (this.contactsNum > 1) { 1467 item.completeNumber = 0; 1468 item.failuresNumber = 0; 1469 } 1470 item.hasReport = settingService.judgeIsDeliveryReport(item.isMsm); 1471 item.msgShowType = this.getMsgShowType(item); 1472 item.mmsSource = this.getMmsSource(); 1473 item.isMsm = this.isEditMms; 1474 this.setDateShow(item, this.mmsList); 1475 this.mmsList.push(item); 1476 this.refresh = !this.refresh 1477 } 1478 1479 // Check whether the time on the top of each SMS message is displayed. 1480 setDateShow(item, list) { 1481 if (item == undefined || list == undefined) { 1482 returen; 1483 } 1484 item.dateShow = true; 1485 if (item.date == undefined || item.date == null) { 1486 return; 1487 } 1488 if (item.date.id == undefined || item.date.id == null) { 1489 return; 1490 } 1491 let tempDateId = item.date?.id; 1492 if (item.week == undefined || item.week == null) { 1493 return; 1494 } 1495 if (item.week.id == undefined || item.week.id == null) { 1496 return; 1497 } 1498 let tempWeekId = item.week?.id; 1499 if (list.length > 0) { 1500 item.dateShow = 1501 (tempDateId != (list[list.length-1]).date?.id) 1502 && (tempWeekId != (list[list.length-1]).week?.id) 1503 } 1504 } 1505 1506 getMmsSource() { 1507 HiLog.i(TAG, 'getMmsSource, start') 1508 let sources = []; 1509 this.dealTextareaDataSource(); 1510 if (this.messageType === common.MESSAGE_TYPE.NORMAL) { 1511 sources = this.dealMmsEditList(); 1512 } else { 1513 sources = this.getMmsSourceFromDataSource(); 1514 } 1515 return sources; 1516 } 1517 1518 dealTextareaDataSource() { 1519 HiLog.i(TAG, 'dealTextareaDataSource, start') 1520 if (this.messageType == common.MESSAGE_TYPE.THEME) { 1521 let first = this.textareaDatasource[0]; 1522 if (first.textValue == common.string.EMPTY_STR) { 1523 this.messageType = common.MESSAGE_TYPE.NORMAL; 1524 this.textValue = this.textareaDatasource[1].textValue; 1525 this.textareaDatasource = []; 1526 } 1527 } 1528 } 1529 1530 dealMmsEditList() { 1531 HiLog.i(TAG, 'dealMmsEditList, start') 1532 let sources = []; 1533 if (this.mmsEditList.length != 0) { 1534 this.mmsEditList.forEach((item, index) => { 1535 let mms = { 1536 msgType: item.type, 1537 msgUriPath: item.uriPath, 1538 content: common.string.EMPTY_STR, 1539 time: item.time, 1540 fileSize: item.fileSize 1541 } 1542 if (index === 0) { 1543 mms.content = this.textValue; 1544 } 1545 sources.push(mms); 1546 }); 1547 } 1548 return sources; 1549 } 1550 1551 getMmsSourceFromDataSource() { 1552 HiLog.i(TAG, 'getMmsSourceFromDataSource, start') 1553 let sources = []; 1554 this.textareaDatasource.forEach((item, index) => { 1555 let mms = { 1556 msgType: common.MSG_ITEM_TYPE.TEXT, 1557 msgUriPath: '', 1558 content: item.textValue, 1559 time: '', 1560 fileSize: 0 1561 }; 1562 if (index === 0 && (this.messageType === common.MESSAGE_TYPE.THEME || 1563 this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT)) { 1564 mms.msgType = common.MSG_ITEM_TYPE.THEME; 1565 sources.push(mms); 1566 } else if (this.messageType === common.MESSAGE_TYPE.THEME) { 1567 sources.push(mms); 1568 sources = this.getMmsSourceByTheme(sources, item, mms); 1569 } else { 1570 if (item.mms) { 1571 mms.msgType = item.mms.type; 1572 mms.msgUriPath = item.mms.uriPath; 1573 mms.time = item.mms.time; 1574 mms.fileSize = item.mms.fileSize; 1575 } 1576 sources.push(mms); 1577 } 1578 }); 1579 return sources; 1580 } 1581 1582 getMmsSourceByTheme(sources, item, mms) { 1583 HiLog.i(TAG, 'getMmsSourceByTheme, start') 1584 if (this.mmsEditList.length === 1) { 1585 let first = this.mmsEditList[0]; 1586 sources.unshift({ 1587 msgType: first.type, 1588 msgUriPath: first.uriPath, 1589 content: item.textValue, 1590 time: first.time, 1591 fileSize: first.fileSize 1592 }); 1593 } else { 1594 this.getMmsSourceByItem(sources, mms); 1595 } 1596 let arr = JSON.parse(JSON.stringify(sources)); 1597 return arr; 1598 } 1599 1600 getMmsSourceByItem(sources, mms) { 1601 HiLog.i(TAG, 'getMmsSourceByItem, start') 1602 this.mmsEditList.forEach((list, i) => { 1603 if (i === 0) { 1604 mms.msgType = list.type; 1605 mms.msgUriPath = list.uriPath; 1606 mms.time = list.time; 1607 mms.fileSize = list.fileSize; 1608 } else { 1609 let mmsObj = { 1610 msgType: list.type, 1611 msgUriPath: list.uriPath, 1612 content: common.string.EMPTY_STR, 1613 time: list.time, 1614 fileSize: list.fileSize 1615 }; 1616 sources.push(mmsObj); 1617 } 1618 }); 1619 } 1620 1621 getMsgShowType(item) { 1622 HiLog.i(TAG, 'getMsgShowType, start') 1623 let type = common.MESSAGE_SHOW_TYPE.NORMAL; 1624 let slideString = 'msg_slide'; 1625 if (this.messageType === common.MESSAGE_TYPE.NORMAL && this.mmsEditList.length <= 1) { 1626 type = common.MESSAGE_SHOW_TYPE.NORMAL; 1627 item.content = this.textValue; 1628 } else if (this.messageType === common.MESSAGE_TYPE.THEME && this.mmsEditList.length === 1) { 1629 type = common.MESSAGE_SHOW_TYPE.THEME_IMAGE; 1630 item.content = this.getThemeContent(); 1631 } else { 1632 type = this.getMsgShowTypePpt(item, slideString); 1633 } 1634 if (type == common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE || type == common.MESSAGE_SHOW_TYPE.PPT_IMAGE) { 1635 if (item.content == common.string.EMPTY_STR) { 1636 item.content = slideString; 1637 } 1638 } 1639 return type; 1640 } 1641 1642 getMsgShowTypePpt(item, slideString) { 1643 HiLog.i(TAG, 'getMsgShowTypePpt, start') 1644 let type = common.MESSAGE_SHOW_TYPE.NORMAL; 1645 let hasSource = this.textareaDatasource.length > 0 ? true : false; 1646 let firstStr = hasSource ? this.textareaDatasource[0].textValue : common.string.EMPTY_STR; 1647 if (this.mmsEditList.length === 0) { 1648 type = common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE; 1649 if (this.messageType === common.MESSAGE_TYPE.THEME || 1650 this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT) { 1651 item.content = this.getThemeContent(); 1652 } else { 1653 item.content = (firstStr == common.string.EMPTY_STR) ? slideString : firstStr; 1654 } 1655 } else { 1656 type = this.getPPTType(); 1657 this.getMsgShowTypeContent(item, firstStr, slideString); 1658 } 1659 return type; 1660 } 1661 1662 getPPTType() { 1663 HiLog.i(TAG, 'getPPTType, start') 1664 let type = common.MESSAGE_SHOW_TYPE.NORMAL; 1665 if (this.messageType === common.MESSAGE_TYPE.NORMAL && this.mmsEditList.length > 0) { 1666 type = common.MESSAGE_SHOW_TYPE.PPT_IMAGE; 1667 } else { 1668 let firstMms = null; 1669 if (this.messageType === common.MESSAGE_TYPE.THEME && this.mmsEditList.length > 1) { 1670 firstMms = this.mmsEditList[0]; 1671 } else if (this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT) { 1672 firstMms = this.textareaDatasource[1].mms; 1673 } else { 1674 firstMms = this.textareaDatasource[0].mms; 1675 } 1676 if (this.mmsEditList.length >= 1 && firstMms && 1677 (firstMms.type === common.MSG_ITEM_TYPE.IMAGE || firstMms.type === common.MSG_ITEM_TYPE.VIDEO)) { 1678 type = common.MESSAGE_SHOW_TYPE.PPT_IMAGE; 1679 } else { 1680 type = common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE; 1681 } 1682 } 1683 return type; 1684 } 1685 1686 getMsgShowTypeContent(item, firstStr, slideString) { 1687 HiLog.i(TAG, 'getMsgShowTypeContent, start') 1688 if (this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT || 1689 this.messageType === common.MESSAGE_TYPE.THEME) { 1690 item.content = this.getThemeContent(); 1691 } else { 1692 let content = common.string.EMPTY_STR; 1693 if (this.messageType === common.MESSAGE_TYPE.NORMAL) { 1694 content = (this.textValue == common.string.EMPTY_STR) ? slideString : this.textValue; 1695 } else { 1696 content = (firstStr == common.string.EMPTY_STR) ? slideString : firstStr; 1697 } 1698 item.content = content; 1699 } 1700 } 1701 1702 getThemeContent() { 1703 HiLog.i(TAG, 'getThemeContent, start') 1704 this.isEditMms = true; 1705 let content = ''; 1706 let first = this.textareaDatasource[0].textValue; 1707 let text = this.textareaDatasource[1].textValue; 1708 if (first !== common.string.EMPTY_STR) { 1709 content = $r('app.string.msg_theme') + ': ' + first; 1710 } 1711 if (text !== common.string.EMPTY_STR) { 1712 if (content === common.string.EMPTY_STR) { 1713 content = text; 1714 } else { 1715 content = content + '\n' + text; 1716 } 1717 } 1718 return content; 1719 } 1720 1721 sendMassMessage(actionData, item) { 1722 this.insertInitData(actionData, item, result => { 1723 // Processing the sent result 1724 if (this.threadId != result.rowId) { 1725 // When modifying the recipient information, click Send and delete the session before the modification. 1726 let condition: LooseObject = {}; 1727 condition.threadId = this.threadId; 1728 ConversationListService.getInstance().deleteSessionByCondition(condition, null, null); 1729 } 1730 this.threadId = result.rowId; 1731 this.portraitColor = AvatarColor.background.Color[Math.abs(this.threadId) % 6]; 1732 item.groupId = result.groupId; 1733 if (result.initDatas[0] == undefined || result.initDatas[0] == null) { 1734 return; 1735 } 1736 if (result.initDatas[0].id == undefined || result.initDatas[0].id == null) { 1737 return; 1738 } 1739 item.id = result.initDatas[0].id; 1740 this.refresh = !this.refresh 1741 // Sending and processing the sending result 1742 this.dealSendResult(actionData, item, result.initDatas); 1743 }); 1744 } 1745 1746 clearMsm() { 1747 if (this.isEditMms) { 1748 this.isEditMms = false; 1749 } 1750 // Deleting the preview image of an MMS message 1751 if (this.mmsEditList.length != 0) { 1752 for (let index in this.mmsEditList) { 1753 this.updatePreview(index); 1754 } 1755 this.mmsEditList = []; 1756 } 1757 } 1758 1759 resetMmsSource() { 1760 this.textareaDatasource = []; 1761 this.mmsEditList = []; 1762 this.pptTotalCount = 0; 1763 this.messageType = common.MESSAGE_TYPE.NORMAL; 1764 this.selectedTextareaIdx = -1; 1765 } 1766 1767 send() { 1768 HiLog.i(TAG, 'send, start'); 1769 // The Send button is dimmed and messages cannot be sent. 1770 if (!this.canSendMessage) { 1771 HiLog.w(TAG, 'send, canSendMessage=false'); 1772 return; 1773 } 1774 // Switching from the new state to the session state 1775 if (this.isNewMsg) { 1776 HiLog.i(TAG, 'send, isNewMsg=true'); 1777 this.newSend(() => { 1778 this.sendDataRefresh(); 1779 }); 1780 } else { 1781 this.sendDataRefresh(); 1782 } 1783 } 1784 1785 sendDataRefresh() { 1786 this.isSendStatus = true; 1787 this.slotId = MmsPreferences.getInstance().getSendMessageSlotId(); 1788 if (this.textValue != common.string.EMPTY_STR || this.mmsEditList.length != 0 || 1789 this.textareaDatasource.length != 0) { 1790 this.initSendItem(); 1791 } 1792 let actionData: LooseObject = {}; 1793 actionData.slotId = this.slotId; 1794 actionData.destinationHost = this.strContactsNumber; 1795 actionData.content = this.textValue; 1796 actionData.isEditMms = this.isEditMms; 1797 // Real SMS Sending 1798 this.sendInterval(actionData, this.mmsList); 1799 this.textValue = common.string.EMPTY_STR; 1800 this.canSendMessage = false; 1801 this.isShowFullScreen = false; 1802 this.clearMsm(); 1803 this.resetMmsSource(); 1804 this.setTabOperationStatus(false); 1805 this.distanceBottomFlag = false; 1806 this.receiveContactValue = common.string.EMPTY_STR; 1807 this.selectContacts = []; 1808 this.isNewMsg = false; 1809 } 1810 1811 isPhoneNumber(str) { 1812 // Determine whether the value is a number. 1813 let reg = /^\d{1,}$/; 1814 let pattern = new RegExp(reg); 1815 return pattern.test(str); 1816 } 1817 1818 newSend(callback) { 1819 // Check whether the entered content has a value. 1820 if (this.receiveContactValue != common.string.EMPTY_STR) { 1821 if (!this.isPhoneNumber(this.receiveContactValue)) { 1822 // Invalid Recipient 1823 this.showToast($r('app.string.invalid_receive', this.receiveContactValue)) 1824 HiLog.w(TAG, 'newSend, PhoneNumber is invalidate'); 1825 return; 1826 } 1827 } 1828 if (this.selectContacts.length > 0 && this.receiveContactValue != common.string.EMPTY_STR) { 1829 let selectContact = { 1830 telephone: this.receiveContactValue, 1831 telephoneFormat: this.receiveContactValue, 1832 contactName: common.string.EMPTY_STR 1833 } 1834 let selectContacts = this.selectContacts; 1835 selectContacts.push(selectContact); 1836 this.initNewSelectContacts(selectContacts); 1837 } else if (this.selectContacts.length > 0) { 1838 this.initNewSelectContacts(this.selectContacts); 1839 } else if (this.receiveContactValue != common.string.EMPTY_STR) { 1840 this.contactsNum = 1; 1841 this.strContactsNumber = this.receiveContactValue; 1842 this.strContactsNumberFormat = this.receiveContactValue; 1843 } else { 1844 HiLog.w(TAG, 'newSend, the contact condition is not met.') 1845 return; 1846 } 1847 this.isNewMsg = false; 1848 // To cancel sending, set this parameter to true. 1849 if (this.recallMessagesFlag) { 1850 this.isNewRecallMessagesFlag = true; 1851 this.commonCtrl.paramContact.isNewRecallMessagesFlag = true; 1852 } 1853 // When the new page is displayed in full screen mode, the following table data needs to be obtained. 1854 if (true) { 1855 this.queryOldMessageList(this.strContactsNumber, callback); 1856 } 1857 } 1858 1859 queryOldMessageList(telephone, callback) { 1860 HiLog.i(TAG, 'queryOldMessageList, start'); 1861 if (telephone == common.string.EMPTY_STR) { 1862 return; 1863 } 1864 let number: string = telephoneUtil.dealTelephoneSort(telephone); 1865 ConversationListService.getInstance().querySessionByTelephone(number, res => { 1866 if (res.response == undefined || res.response == null) { 1867 return; 1868 } 1869 if (res.response.id == undefined || res.response.id == null) { 1870 return; 1871 } 1872 HiLog.i(TAG, 'queryOldMessageList, querySessionByTelephone res.response.id: ' + res.response.id); 1873 if (res.code == common.int.SUCCESS && res.response.id > 0) { 1874 if (this.threadId != res.response.id) { 1875 // When modifying the recipient information, click Send and delete the session before the 1876 // modification. 1877 let condition: LooseObject = {}; 1878 condition.threadId = this.threadId; 1879 ConversationListService.getInstance().deleteSessionByCondition(condition, null, null); 1880 } 1881 this.isDraft = res.response.hasDraft; 1882 this.threadId = res.response.id; 1883 this.portraitColor = AvatarColor.background.Color[Math.abs(this.threadId) % 6]; 1884 this.queryMessageDetail(telephone, res.response.id, callback); 1885 this.scroller.scrollToIndex(this.mmsList.length - 1); 1886 } else { 1887 callback(); 1888 } 1889 }, null); 1890 } 1891 1892 initNewSelectContacts(selectContacts) { 1893 HiLog.i(TAG, 'initNewSelectContacts, start'); 1894 let contactsNumber = common.string.EMPTY_STR; 1895 let contactsName = common.string.EMPTY_STR; 1896 let contactsNumberFormat = common.string.EMPTY_STR; 1897 let contacts = telephoneUtil.dealSelectContactsSort(selectContacts); 1898 let length = contacts.length; 1899 for (let index in contacts) { 1900 let item = contacts[index]; 1901 contactsNumber = contactsNumber + item.telephone + common.string.COMMA; 1902 contactsNumberFormat = contactsNumberFormat + item.telephoneFormat + common.string.COMMA; 1903 if (item.contactName != common.string.EMPTY_STR) { 1904 contactsName += (item.contactName + common.string.COMMA); 1905 } 1906 } 1907 this.strContactsNumber = contactsNumber.substring(0, contactsNumber.length - 1); 1908 this.strContactsName = contactsName.substring(0, contactsName.length - 1); 1909 this.photoFirstNameDeal(this.strContactsName); 1910 this.strContactsNumberFormat = contactsNumberFormat.substring(0, contactsNumberFormat.length - 1); 1911 this.contactsNum = length; 1912 } 1913 1914 handleWithSend(actionData, item) { 1915 // Sending request processing 1916 let hosts: Array<string> = []; 1917 if (actionData.destinationHost.indexOf(',') == -1) { 1918 // single-shot 1919 hosts.push(actionData.destinationHost); 1920 } else { 1921 // Group Sending 1922 for (let host of actionData.destinationHost.split(',')) { 1923 hosts.push(telephoneUtil.formatTelephone(host)); 1924 } 1925 } 1926 actionData.hosts = hosts; 1927 this.sendMassMessage(actionData, item); 1928 } 1929 1930 sendInterval(actionData, mmsList) { 1931 // Send Timer 1932 let item = mmsList[mmsList.length - 1]; 1933 if (this.recallMessagesFlag) { 1934 item.intervalSendStatus = true; 1935 // Second countdown timer after the Send button is clicked 1936 item.sendIntervalId = setInterval(function () { 1937 item.cancelTimeCount--; 1938 }, 1000); 1939 // Transmit timer, which is sent after 6s. 1940 item.sendTimeoutId = setTimeout(() => { 1941 item.cancelTimeCount = 0; 1942 // Clear Timer 1943 clearTimeout(item.sendTimeoutId); 1944 clearInterval(item.sendIntervalId); 1945 this.handleWithSend(actionData, item); 1946 }, 6000); 1947 } else { 1948 this.handleWithSend(actionData, item); 1949 } 1950 } 1951 1952 changeValue(e) { 1953 this.textValue = e; 1954 if (e == null || e == common.string.EMPTY_STR) { 1955 if (this.mmsEditList.length != 0) { 1956 this.canSendMessage = true; 1957 } else { 1958 this.canSendMessage = false; 1959 } 1960 return; 1961 } 1962 // Whether to display full screen 1963 if (this.isEditMms) { 1964 this.isShowFullScreen = false; 1965 } else { 1966 this.isShowFullScreen = true; 1967 } 1968 if (this.isNewMsg) { 1969 if (this.receiveContactValue == '' && this.selectContacts.length == 0) { 1970 this.canSendMessage = false; 1971 return; 1972 } 1973 } 1974 if (this.textValue.length == 0) { 1975 this.canSendMessage = false; 1976 return; 1977 } else { 1978 this.canSendMessage = MmsPreferences.getInstance().haveSimCardReady() && !this.isFlightMode; 1979 } 1980 if (this.isNewMsg) { 1981 this.setCanSendMsgStatus(); 1982 } 1983 } 1984 1985 setTabTitleText() { 1986 // TabTitleText selected globally 1987 if (this.tabIndex != 1) { 1988 // Non-picture page 1989 this.tabTitleText = this.tabTextList[this.tabIndex]; 1990 return; 1991 } 1992 // On the image selection page, the number of selected images is displayed. 1993 let size = 0; 1994 for (let element of this.pictureListFromGallery) { 1995 if (element.checkedValue) { 1996 size++; 1997 } 1998 } 1999 this.tabTitleText = size == 0 ? $r('app.string.msg_unselected_tip') : $r('app.string.msg_selected_tip', { 2000 number: size 2001 }); 2002 } 2003 2004 // Check whether the sending icon can be highlighted. 2005 judgeSendBtnCanClicked() { 2006 if (MmsPreferences.getInstance().haveSimCardReady() && (this.mmsEditList.length != 0 || 2007 this.textValue != common.string.EMPTY_STR || this.textareaDatasource.length !== 0)) { 2008 if (this.isNewMsg) { 2009 if ((this.receiveContactValue !== '' && this.isPhoneNumber(this.receiveContactValue)) 2010 || this.selectContacts.length !== 0) { 2011 this.canSendMessage = true; 2012 } 2013 } else { 2014 this.canSendMessage = true; 2015 } 2016 } 2017 } 2018 2019 // Subscribing to Public Events 2020 subscribeDetail() { 2021 HiLog.i(TAG, 'subscribeDetail, start'); 2022 let events = [common.string.RECEIVE_TRANSMIT_EVENT] 2023 let commonEventSubscribeInfo = { 2024 events: events 2025 }; 2026 // Creating Subscription Information 2027 commonEvent.createSubscriber(commonEventSubscribeInfo, this.createSubscriberCallBack.bind(this)); 2028 } 2029 2030 createSubscriberCallBack(err, data) { 2031 this.commonEventData = data; 2032 // Received subscription 2033 commonEvent.subscribe(this.commonEventData, this.subscriberCallBack.bind(this)); 2034 } 2035 2036 subscriberCallBack(err, data) { 2037 HiLog.i(TAG, 'subscriberCallBack, start'); 2038 globalThis.needToUpdate = true; 2039 // Receiving SMS Updates 2040 this.queryMessageDetail(this.strContactsNumber, this.threadId, () => { 2041 }); 2042 setTimeout(() => { 2043 this.scroller.scrollToIndex(this.mmsList.length - 1); 2044 let actionData: LooseObject = {}; 2045 actionData.threadId = this.threadId; 2046 actionData.hasRead = common.is_read.UN_READ; 2047 NotificationService.getInstance().cancelMessageNotify(actionData); 2048 NotificationService.getInstance().updateBadgeNumber(); 2049 ConversationListService.getInstance().markAllToRead(actionData); 2050 let lastItem: LooseObject = this.mmsList[this.mmsList.length - 1]; 2051 if (lastItem != null && lastItem.subId != null) { 2052 this.notifySlotIdChange(lastItem.subId); 2053 } 2054 }, 500); 2055 } 2056 2057 // Unsubscribe 2058 unSubscribeDetail() { 2059 if (this.commonEventData != null) { 2060 commonEvent.unsubscribe(this.commonEventData, () => { 2061 HiLog.i(TAG, 'unSubscribeDetail, unsubscribe'); 2062 }); 2063 } 2064 } 2065 2066 notifySlotIdChange(slotId: number): void { 2067 if (MmsPreferences.getInstance().getSelectedSlotId() != slotId) { 2068 MmsPreferences.getInstance().setValueToMap(common.string.KEY_OF_SELECTED_SLOTID, slotId); 2069 HiLog.i(TAG, 'notifySlotIdChange, emit slotId: ' + slotId); 2070 emitter.emit(simCardService.SLOTID_CHANGE_EVENT, { 2071 data: { 2072 'slotId': slotId 2073 } 2074 }); 2075 } 2076 } 2077 2078 // In the selection mode, tap More. In the displayed menu, select 2079 moreSelected(e) { 2080 HiLog.i(TAG, 'moreSelected, e: ' + JSON.stringify(e)) 2081 switch (e) { 2082 case '0': 2083 // duplicating 2084 this.copyText(); 2085 break; 2086 case 1: 2087 // Share 2088 this.share(); 2089 break; 2090 case 2: 2091 // Select Text 2092 this.gotoTextSelect(this.mmsIndex); 2093 break; 2094 case 3: 2095 // lock 2096 //this.lock(); 2097 break; 2098 case 4: 2099 // Show Details 2100 this.showDetails(); 2101 break; 2102 case 5: 2103 // Unlock 2104 //this.unlock(); 2105 break; 2106 case 6: 2107 // View Reports 2108 this.showReport(this.mmsIndex); 2109 break; 2110 case 7: 2111 // Save Attachments 2112 this.saveImage(); 2113 break; 2114 case 8: 2115 // Querying vCard Details 2116 this.showVcarDetail(this.mmsIndex); 2117 break; 2118 default: 2119 break; 2120 } 2121 // Exit the multi-selection mode. 2122 this.exitMultiselect(); 2123 } 2124 2125 copyText() { 2126 commonPasteboard.setPasteboard(this.mmsList[this.mmsIndex].content); 2127 } 2128 2129 share() { 2130 for (let i = 0; i < this.mmsList.length; i++) { 2131 if (this.mmsList[i].isCbChecked == true) { 2132 let actionData: LooseObject = {}; 2133 actionData.content = this.mmsList[i].content; 2134 ConversationService.getInstance().gotoShare(actionData, null, null); 2135 } 2136 } 2137 } 2138 2139 gotoTextSelect(idx) { 2140 router.push({ 2141 uri: 'pages/text_select/text_select', 2142 params: this.mmsList[idx] 2143 }) 2144 } 2145 2146 showDetails() { 2147 for (let index = 0; index < this.mmsList.length; index++) { 2148 if (this.mmsList[index].isCbChecked == true) { 2149 var time = this.mmsList[index].timeMillisecond; 2150 var timeStash = this.getTime(time); 2151 this.mmsTime = timeStash + this.mmsList[index].time; 2152 if (this.mmsList[index].msgType == 0) { 2153 this.isMmsType = $r('app.string.sms'); 2154 } else { 2155 this.isMmsType = $r('app.string.mms'); 2156 } 2157 2158 if (this.mmsList[index].isReceive) { 2159 this.isSendRecipient = true; 2160 } else { 2161 this.isSendRecipient = false; 2162 } 2163 } 2164 } 2165 // this.$element('mms_details_dialog').show(); 2166 } 2167 2168 showReport(mmsIndex) { 2169 // View Reports 2170 let item = this.mmsList[mmsIndex]; 2171 router.push({ 2172 uri: 'pages/queryreport/queryReport', 2173 params: { 2174 isMsm: item.isMsm, 2175 telephone: this.strContactsNumber, 2176 sendStatus: item.sendStatus, 2177 timeMillisecond: item.timeMillisecond 2178 }, 2179 }); 2180 } 2181 2182 saveImage() { 2183 var actionData: LooseObject = {}; 2184 actionData.threadId = this.mmsList[this.mmsIndex]?.threadId; 2185 actionData.pduId = this.mmsList[this.mmsIndex]?.pduId; 2186 ConversationService.getInstance().saveImage(actionData, result => { 2187 this.showToast(result); 2188 }, null); 2189 } 2190 2191 showVcarDetail(mmsIndex) { 2192 2193 } 2194 2195 exitMultiselect() { 2196 // Exit the multi-selection state. 2197 this.isSelectStatus = false; 2198 this.cancelCheckedAll(); 2199 } 2200 2201 longPressMore(e) { 2202 switch (e) { 2203 case 0: 2204 // delete 2205 this.deleteDetail(); 2206 break; 2207 case 1: 2208 // New Contact 2209 this.createNewContact(this.strContactsNumber); 2210 break; 2211 case 2: 2212 // Save to Existing Contacts 2213 this.existingContact(this.strContactsNumber); 2214 break; 2215 case 3: 2216 // Edit Before Call 2217 this.callEditor(this.strContactsNumber); 2218 break; 2219 case 4: 2220 // Add to Blocklist 2221 this.callEditor(this.strContactsNumber); 2222 break; 2223 case 5: 2224 // View Contacts 2225 this.titleBarAvatar(); 2226 break; 2227 default: 2228 break; 2229 } 2230 } 2231 2232 // Delete 2233 deleteDetail() { 2234 if (this.mmsList.length == 1) { 2235 this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_con_tip3'); 2236 } else { 2237 this.hasDetailDelete = false; 2238 this.isSelectStatus = true; 2239 } 2240 } 2241 2242 // New Contact 2243 createNewContact(number) { 2244 var actionData: LooseObject = {}; 2245 actionData.phoneNumber = number; 2246 actionData.pageFlag = common.contactPage.PAGE_FLAG_SAVE_CONTACT; 2247 this.jumpToContact(actionData); 2248 } 2249 2250 // Edit Before Call 2251 callEditor(number) { 2252 var actionData: LooseObject = {}; 2253 actionData.phoneNumber = number; 2254 actionData.pageFlag = common.contactPage.PAGE_FLAG_EDIT_BEFORE_CALLING; 2255 this.jumpToContact(actionData); 2256 } 2257 2258 // Save to Existing Contacts 2259 existingContact(number) { 2260 var actionData: LooseObject = {}; 2261 actionData.phoneNumber = number; 2262 actionData.pageFlag = common.contactPage.PAGE_FLAG_SAVE_EXIST_CONTACT; 2263 this.jumpToContact(actionData); 2264 } 2265 2266 // Switching to the Contacts app 2267 jumpToContact(actionData) { 2268 let str = commonService.commonContactParam(actionData); 2269 globalThis.mmsContext.startAbility(str).then((data) => { 2270 HiLog.i(TAG, 'jumpToContact, startAbility Success'); 2271 }).catch((error) => { 2272 HiLog.e(TAG, 'jumpToContact, failed. Cause: ' + JSON.stringify(error.message)); 2273 }) 2274 } 2275 2276 // Tap a contact's avatar to go to the contact details page. 2277 titleBarAvatar() { 2278 var actionData = { 2279 phoneNumber: this.strContactsNumber, 2280 pageFlag: common.contactPage.PAGE_FLAG_CONTACT_DETAILS 2281 }; 2282 this.jumpToContact(actionData); 2283 } 2284 2285 clickCall() { 2286 this.call(this.strContactsNumber); 2287 } 2288 2289 call(telephone) { 2290 // Calling 2291 callService.call(telephone, result => { 2292 if (result.code == common.int.SUCCESS) { 2293 HiLog.i(TAG, 'call success'); 2294 } else { 2295 HiLog.w(TAG, 'call failed'); 2296 } 2297 }); 2298 } 2299 2300 getTime(nS) { 2301 var date = new Date(parseInt(nS)); 2302 var year = date.getFullYear(); 2303 var mon = date.getMonth() + 1; 2304 var day = date.getDate(); 2305 return year; // + $r('app.string.year') + mon + $r('app.string.month') + day + $r('app.string.day'); 2306 } 2307 2308 // Contact data returned on the new page 2309 setReceiveContactValue(receiverData) { 2310 let selectContacts = receiverData.selectContacts; 2311 let receiveContactValue = selectContacts.length > 0 ? common.string.EMPTY_STR : receiverData.contactValue; 2312 let hasBlur = receiverData.hasBlur; 2313 let telephone = common.string.EMPTY_STR; 2314 this.setCanSendMessage(selectContacts, receiveContactValue) 2315 if (receiveContactValue != this.strContactsName && router.getParams[0]?.isDraft == null) { 2316 this.isDraft = false; 2317 } 2318 if (hasBlur && receiveContactValue != common.string.EMPTY_STR) { 2319 let index = -1; 2320 for (let i = 0; i < selectContacts.length; i++) { 2321 let contact = selectContacts[i]; 2322 if (contact.telephone == receiveContactValue) { 2323 index = i; 2324 break; 2325 } 2326 } 2327 if (index >= 0) { 2328 selectContacts.splice(index, 1); 2329 } 2330 } 2331 if (receiveContactValue != common.string.EMPTY_STR) { 2332 this.receiveContactValue = receiveContactValue; 2333 } else { 2334 this.receiveContactValue = common.string.EMPTY_STR; 2335 } 2336 if (selectContacts.length > 0) { 2337 for (let item of selectContacts) { 2338 if (!this.isPhoneNumber(item.telephone)) { 2339 item.telephone = this.replaceCode(item.telephone); 2340 item.telephoneFormat = this.replaceCode(item.telephoneFormat); 2341 if (item.contactName != common.string.EMPTY_STR) { 2342 item.contactName = common.string.EMPTY_STR; 2343 } 2344 } 2345 if (this.selectContacts.length > 1) { 2346 break 2347 } 2348 this.selectContacts = selectContacts; 2349 } 2350 } else { 2351 this.selectContacts = []; 2352 } 2353 if (this.selectContacts.length > 0) { 2354 for (let element of this.selectContacts) { 2355 telephone += element.telephone + common.string.COMMA; 2356 } 2357 } 2358 if (this.receiveContactValue != common.string.EMPTY_STR) { 2359 telephone += this.receiveContactValue + common.string.COMMA; 2360 } 2361 if (telephone != common.string.EMPTY_STR) { 2362 telephone = telephone.substring(0, telephone.length - 1); 2363 } 2364 if (!hasBlur && telephone != '') { 2365 this.queryOldMessageList(telephone, () => { 2366 }); 2367 } 2368 } 2369 2370 setCanSendMessage(selectContacts, receiveContactValue) { 2371 if (this.textValue != common.string.EMPTY_STR || this.isEditMms) { 2372 if (this.canSendMessage) { 2373 if (selectContacts.length == 0 && receiveContactValue == common.string.EMPTY_STR) { 2374 this.canSendMessage = false; 2375 } 2376 } else if ((selectContacts.length != 0 || receiveContactValue != common.string.EMPTY_STR) 2377 && MmsPreferences.getInstance().haveSimCardReady()) { 2378 this.canSendMessage = true; 2379 } 2380 } 2381 } 2382}