1// @ts-nocheck 2/** 3 * Copyright (c) 2022 Huawei Device Co., Ltd. 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16import router from "@system.router"; 17import Prompt from "@system.prompt"; 18import commonEvent from "@ohos.commonEvent"; 19import emitter from '@ohos.events.emitter'; 20import HiLog from "../../utils/HiLog" 21import common from "../../data/commonData" 22import commonEvent from "@ohos.commonEventManager"; 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 hasExitContract: 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.initNewPageContracts(); 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 NotificationService.getInstance().cancelMessageNotify({ 252 threadIds: this.threadId, 253 hasRead: 0 254 }, res => {}); 255 } 256 257 onShow() { 258 HiLog.i(TAG, "onShow"); 259 // Check whether the Send button can be clicked. 260 this.judgeSendBtnCanClicked(); 261 // Subscribe to PA 262 this.subscribeDetail(); 263 // Check whether a contact exists. 264 this.judgeContactExists(); 265 // Initialize the forwarded data 266 this.initTransmitMeg(); 267 // Forwarding and sending 268 this.transmitSend(); 269 } 270 271 onHide() { 272 HiLog.i(TAG, "onHide"); 273 this.unSubscribeDetail(); 274 } 275 276 initData() { 277 this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_tip2", 278 this.selectDeleteMsgCount 279 ); 280 this.tabTextList = [ 281 // $r("app.string.msg_take_photos"), 282 // $r("app.string.msg_picture"), 283 // $r("app.string.msg_record"), 284 // $r("app.string.more_low") 285 ]; 286 this.animationOptions = { 287 duration: ANIMATION_DURATION, 288 easing: "linear", 289 fill: "forwards", 290 iterations: "Infinity", 291 }; 292 this.animationFrames = [ 293 { 294 transform: { 295 scale: TRANSFORM_SCALE_MIN 296 } 297 }, 298 { 299 transform: { 300 scale: TRANSFORM_SCALE_MAX 301 } 302 } 303 ]; 304 // this.pattern = $r("app.string.camera_post"); 305 this.initSlideDurations(); 306 } 307 308 initSlideDurations() { 309 let arr = []; 310 for (let i = 1; i <= 10; i++) { 311 arr.push(i); 312 } 313 this.slideDurations = arr; 314 } 315 316 release() { 317 this.textValue = ''; 318 this.receiveContactValue = ''; 319 this.isDraft = false; 320 this.mmsList = []; 321 } 322 323 initNewPageContracts() { 324 let transmitContracts = []; 325 if (this.strContactsNumber) { 326 let contactsNames = this.strContactsName.split(","); 327 let telephones = this.strContactsNumber.split(","); 328 let telephoneFormat = this.strContactsNumberFormat.split(","); 329 for (let index in contactsNames) { 330 let item: LooseObject = {}; 331 item.contactName = contactsNames[index]; 332 item.telephone = telephones[index]; 333 if (contactsNames[index] == common.string.EMPTY_STR && 334 telephoneFormat[index] == common.string.EMPTY_STR) { 335 item.telephoneFormat = telephones[index]; 336 } else { 337 item.telephoneFormat = telephoneFormat[index]; 338 } 339 item.headImage = common.string.EMPTY_STR; 340 item.select = false; 341 transmitContracts.push(item); 342 } 343 } 344 this.commonCtrl.paramContact.transmitContracts = transmitContracts; 345 this.commonCtrl.paramContact.isSelectContact = false; 346 this.commonCtrl.paramContact.isNewRecallMessagesFlag = false; 347 } 348 349 initRouterData() { 350 let routerParams: LooseObject = router.getParams(); 351 this.strContactsName = 352 routerParams.strContactsName == undefined ? '' : routerParams.strContactsName; 353 this.strContactsNumber = 354 routerParams.strContactsNumber == undefined ? '' : routerParams.strContactsNumber; 355 this.strContactsNumberFormat = 356 routerParams.strContactsNumberFormat == undefined ? '' : routerParams.strContactsNumberFormat; 357 this.contactsNum = routerParams.contactsNum == undefined ? 0 : routerParams.contactsNum; 358 this.threadId = routerParams.threadId == undefined ? 0 : routerParams.threadId; 359 this.isDraft = routerParams.isDraft == undefined ? false : routerParams.isDraft; 360 this.draftContent = routerParams.draftContent == undefined ? '' : routerParams.draftContent; 361 this.searchContent = routerParams.searchContent == undefined ? '' : routerParams.searchContent; 362 this.isNewMsg = routerParams.isNewMsg == undefined ? false : routerParams.isNewMsg; 363 this.portraitColor = AvatarColor.background.Color[Math.abs(parseInt(this.threadId, 10)) % 6]; 364 this.photoFirstNameDeal(this.strContactsName); 365 this.dealSpecialPhoneNumber(); 366 } 367 368 photoFirstNameDeal(strContactsName) { 369 if(strContactsName !== common.string.EMPTY_STR && this.reg.test(strContactsName.substring(0, 1))) { 370 this.photoFirstName = strContactsName.substring(0, 1).toUpperCase() 371 } else { 372 this.photoFirstName = '-1' 373 } 374 } 375 376 // Handle invalid phone numbers that contain #, *, and dots in redirection from other applications. 377 // Replace them with spaces. 378 dealSpecialPhoneNumber() { 379 if (!this.isPhoneNumber(this.strContactsNumber)) { 380 this.strContactsNumber = this.replaceCode(this.strContactsNumber); 381 this.strContactsNumberFormat = this.replaceCode(this.strContactsNumberFormat); 382 if (this.strContactsName != common.string.EMPTY_STR) { 383 this.strContactsName = common.string.EMPTY_STR; 384 } 385 } 386 } 387 388 replaceCode(str) { 389 if (str != null && str.length != 0) { 390 return str.replace(new RegExp(/e|-|#|\*|\./, "g"), common.string.EMPTY_STR); 391 } else { 392 return common.string.EMPTY_STR; 393 } 394 } 395 396 titleBarCancel() { 397 // Cancel button 398 this.cancleCheckedAll(); 399 this.setSelectStatus(false); 400 } 401 402 onBackPress() { 403 if (this.isSelectStatus) { 404 // Multi-choice status 405 this.isSelectStatus = false; 406 this.cancleCheckedAll(); 407 return true; 408 } 409 let source = this.getMmsSource(); 410 this.insertAndUpdateSessionDraft(source, ()=> { 411 this.release(); 412 router.back(); 413 }); 414 return true; 415 } 416 417 insertAndUpdateSessionDraft(source, callback) { 418 // Create a draft. If the selected contact or content is empty, delete the draft. 419 if (this.isNewMsg && this.isDraft) { 420 if ((this.selectContacts.length == 0 && this.receiveContactValue == common.string.EMPTY_STR) || 421 (this.textValue == common.string.EMPTY_STR && source.length == 0)) { 422 conversationListService.deleteMessageBySessionId([this.threadId]); 423 this.deleteDraftData(); 424 } 425 } 426 let hasReport = settingService.judgeIsDeliveryReport(this.isEditMms); 427 let hasAttachment = commonService.judgeIsAttachment(source); 428 let actionData: LooseObject = {}; 429 actionData = { 430 slotId: MmsPreferences.getInstance().getSendMessageSlotId(), 431 threadId: this.threadId, 432 receiveContactValue: common.string.EMPTY_STR, 433 selectContacts: [], 434 content: this.textValue, 435 isReceive: false, 436 ownNumber: common.string.EMPTY_STR, 437 isSender: 0, 438 hasDraft: 1, 439 hasReport: hasReport, 440 isMms: this.isEditMms, 441 mmsSource: source, 442 groupId: this.draftGroupId, 443 messageType: this.messageType, 444 hasAttachment: hasAttachment 445 } 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.insertSessionDraft(actionData, callback); 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.insertSessionDraft(actionData, callback); 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 conversationListService.deleteMessageBySessionId([this.threadId]); 466 this.deleteDraftData(); 467 callback(); 468 } else { 469 callback(); 470 } 471 } else { 472 callback(); 473 } 474 } else { 475 // This is not a new scenario. 476 actionData.telephone = this.strContactsNumber; 477 conversationListService.insertSessionDraft(actionData, callback); 478 } 479 } else if (!this.isNewMsg && this.isDraft) { 480 // If a draft exists, perform the following operations: 481 this.dealSessionDraft(source); 482 callback(); 483 } else { 484 callback(); 485 } 486 } 487 488 // When the draft logic is set, the text content is empty and the page is not created, the session list data needs 489 // to be updated. 490 dealSessionDraft(source) { 491 // Query the last content in the list 492 let length = this.mmsList.length; 493 let item = this.mmsList[length - 1]; 494 // Updating list data 495 let threadIds = [this.threadId]; 496 let time = new Date(); 497 let content = item.content; 498 let hasAttachment = false; 499 if (item.isMsm) { 500 content = commonService.getMmsContent(item.mms); 501 hasAttachment = commonService.judgeIsAttachment(source); 502 } 503 let valueBucket = { 504 "content": item.content, 505 "has_draft": 0, 506 "time": time.getTime(), 507 "has_mms": item.isMsm ? 1 : 0, 508 "has_attachment": hasAttachment ? 1 : 0 509 } 510 conversationListService.updateById(threadIds, valueBucket); 511 this.deleteDraftData(); 512 this.isDraft = false; 513 } 514 515 cancleCheckedAll() { 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.initNewPageContracts(); 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 = 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 let actionData: LooseObject = { 735 slotId: MmsPreferences.getInstance().getSendMessageSlotId(), 736 destinationHost: this.strContactsNumber, 737 content: content, 738 isEditMms: isMms 739 }; 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 = {}; 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_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.cancleCheckedAll(); 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 router.back(); 990 globalThis.needToUpdate = true; 991 this.deleteMessageById(this.threadId); 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) { 1001 let actionData = { 1002 groupIds: groupIds, 1003 }; 1004 // Invoke the database deletion method. 1005 conversationService.deleteMessageByGroupIds(actionData); 1006 } 1007 1008 // Updates the lock status of the session list. 1009 updateSessionLock(isLock) { 1010 let threadIds = [this.threadId]; 1011 let hasLock = isLock ? 1 : 0; 1012 let valueBucket = { 1013 "has_lock": hasLock, 1014 } 1015 if (!isLock) { 1016 // If you want to unlock the status, you must unlock all the statuses before unlocking the statuses. 1017 let unlockCount = 0; 1018 for (let element of this.mmsList) { 1019 if (!element.isLock) { 1020 unlockCount++; 1021 } 1022 } 1023 if (unlockCount != this.mmsList.length) { 1024 HiLog.w(TAG, "updateSessionLock, it is not all select unlock"); 1025 return; 1026 } 1027 } 1028 // If it is locked, update the status to locked. 1029 conversationListService.updateById(threadIds, valueBucket); 1030 } 1031 1032 updateLastItemContent() { 1033 let actionData = { 1034 mmsList: this.mmsList, 1035 threadId: this.threadId, 1036 }; 1037 conversationListService.updateLastItemContent(actionData); 1038 } 1039 1040 deleteMessageById(threadId) { 1041 let threadIds = [threadId]; 1042 // Deleting Database Data 1043 let actionData = { 1044 threadIds: threadIds, 1045 }; 1046 conversationListService.deleteMessageById(actionData); 1047 } 1048 1049 clickGroupDelete() { 1050 if (this.selectDeleteMsgCount == 0) { 1051 return; 1052 } 1053 if (this.selectDeleteMsgCount == 1) { 1054 this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_tip1"); 1055 } else if (this.selectDeleteMsgCount == this.mmsList.length) { 1056 this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_tip3"); 1057 } else { 1058 this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_tip2", this.selectDeleteMsgCount); 1059 } 1060 this.hasLockMsg = (this.mmsList.some((element, index) => element.isCbChecked && element.isLock)); 1061 } 1062 1063 // Check whether a contact exists. 1064 judgeContactExists() { 1065 let telephones = [this.strContactsNumber]; 1066 let actionData = { 1067 telephones: telephones 1068 }; 1069 conversationService.judgeContactExists(actionData, result => { 1070 this.hasExitContract = result; 1071 }); 1072 if (this.strContactsName == common.string.EMPTY_STR) { 1073 this.hasExitContract = false; 1074 } else { 1075 this.hasExitContract = true; 1076 } 1077 } 1078 1079 /** 1080 * Obtain information details. 1081 * 1082 * @param telephone 1083 * @param threadId 1084 * @param callback 1085 */ 1086 queryMessageDetail(telephone, threadId, callback) { 1087 let actionData: LooseObject = {}; 1088 if (telephone != common.string.EMPTY_STR) { 1089 actionData.telephone = telephone; 1090 } 1091 if (threadId != common.string.EMPTY_STR) { 1092 actionData.threadId = threadId; 1093 } 1094 actionData.contactsNum = this.contactsNum; 1095 conversationService.queryMessageDetail(actionData, result => { 1096 if (result.code == common.int.SUCCESS) { 1097 this.initIsShowMsgLongMenu(result); 1098 this.dealMessageDetailTime(result); 1099 this.dealMessageDetailContent(result); 1100 if (this.mmsList.length == 0 && this.isDraft) { 1101 HiLog.i(TAG, "queryMessageDetail, isNewMsg = true"); 1102 this.isNewMsg = true; 1103 } 1104 } else { 1105 HiLog.w(TAG, "queryMessageDetail, failed"); 1106 } 1107 if (this.isDraft) { 1108 this.setDraft(); 1109 } 1110 this.deleteDraftData(); 1111 }); 1112 if (callback) { 1113 callback(); 1114 } 1115 } 1116 1117 initIsShowMsgLongMenu(result) { 1118 for (let item of result.response) { 1119 item.isShowMsgLongMenu = false; 1120 } 1121 } 1122 1123 dealItemContent(showType, content, mmsSource) { 1124 let strContent = content; 1125 if (showType == common.MESSAGE_SHOW_TYPE.THEME_NO_IMAGE || showType == common.MESSAGE_SHOW_TYPE.THEME_IMAGE) { 1126 if (content !== common.string.EMPTY_STR) { 1127 strContent = $r("app.string.msg_theme") + ": " + content; 1128 } 1129 } else if (showType == common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE) { 1130 strContent = (content == common.string.EMPTY_STR) ? $r("app.string.msg_slide") : content; 1131 } else if (showType == common.MESSAGE_SHOW_TYPE.PPT_IMAGE) { 1132 if (mmsSource[0].msgType == common.MSG_ITEM_TYPE.THEME && content !== common.string.EMPTY_STR) { 1133 strContent = $r("app.string.msg_theme") + ": " + content; 1134 } else { 1135 strContent = (content == common.string.EMPTY_STR) ? $r("app.string.msg_slide") : content; 1136 } 1137 } 1138 return strContent; 1139 } 1140 1141 dealMessageDetailContent(result) { 1142 for (let item of result.response) { 1143 item.content = this.dealItemContent(item.msgShowType, item.content, item.mms); 1144 } 1145 } 1146 1147 dealMessageDetailTime(result) { 1148 if (result.response && result.response.length > 0) { 1149 let resultList = []; 1150 for (let item of result.response) { 1151 item.timeMillisecond = parseInt(item.timeMillisecond); 1152 dateUtil.fullDate(item); 1153 dateUtil.convertTimeStampToDateWeek(item, false); 1154 this.setDateShow(item, resultList); 1155 dateUtil.convertDateFormatForItem(item, false); 1156 if (item.sendStatus == common.int.SEND_DRAFT) { 1157 this.dealDraftData(item); 1158 } else { 1159 resultList.push(item); 1160 } 1161 } 1162 this.mmsList = resultList; 1163 } 1164 } 1165 1166 deleteDraftData() { 1167 if (this.isDraft && this.draftGroupId > 0) { 1168 let groupIds = [this.draftGroupId]; 1169 this.deleteMessageByGroupIds(groupIds); 1170 this.draftGroupId = 0; 1171 } 1172 } 1173 1174 getMmsDataSource(mmsSource, first) { 1175 this.pptTotalCount = (first.msgType == common.MSG_ITEM_TYPE.THEME) ? -1 : 0; 1176 let mms = []; 1177 let textareas = []; 1178 mmsSource.forEach((source, index) => { 1179 this.pptTotalCount++; 1180 let mmsObj = null; 1181 if (source.msgType == common.MSG_ITEM_TYPE.AUDIO || 1182 source.msgType == common.MSG_ITEM_TYPE.IMAGE || 1183 source.msgType == common.MSG_ITEM_TYPE.VIDEO) { 1184 mmsObj = { 1185 type: source.msgType, 1186 uriPath: source.msgUriPath, 1187 time: source.time, 1188 index: this.pptTotalCount, 1189 fileSize: first.fileSize 1190 }; 1191 mms.push(mmsObj); 1192 } 1193 let placeholder = $r("app.string.enter_text"); 1194 if (source.msgType == common.MSG_ITEM_TYPE.THEME) { 1195 placeholder = $r("app.string.msg_theme"); 1196 } else if (mmsSource[0].msgType == common.MSG_ITEM_TYPE.THEME && mmsSource.length == 2) { 1197 if (mmsObj) { 1198 placeholder = $r("app.string.msg_note_mms2"); 1199 } else { 1200 placeholder = $r("app.string.msg_note_mms"); 1201 } 1202 this.pptTotalCount = 0; 1203 } 1204 let obj = { 1205 textValue: source.content, 1206 placeholder: placeholder, 1207 pptIndex: this.pptTotalCount, 1208 mms: mmsObj 1209 }; 1210 textareas.push(obj); 1211 }); 1212 this.mmsEditList = mms; 1213 this.textareaDatasource = textareas; 1214 } 1215 1216 setMmsDataSource(mmsSource) { 1217 this.mmsEditList = []; 1218 this.textareaDatasource = []; 1219 let first = mmsSource[0]; 1220 this.messageType = first.messageType; 1221 if (this.messageType == common.MESSAGE_TYPE.NORMAL) { 1222 let arr = []; 1223 mmsSource.forEach(item => { 1224 let obj = { 1225 type: item.msgType, 1226 uriPath: item.msgUriPath, 1227 time: item.time, 1228 fileSize: item.fileSize 1229 } 1230 arr.push(obj); 1231 }); 1232 this.mmsEditList = arr; 1233 } else { 1234 this.getMmsDataSource(mmsSource, first); 1235 } 1236 } 1237 1238 dealDraftData(item) { 1239 this.isDraft = true; 1240 this.draftContent = item.content; 1241 this.draftGroupId = item.groupId; 1242 if (item.isMsm) { 1243 this.isEditMms = true; 1244 this.setMmsDataSource(item.mms); 1245 } else { 1246 this.messageType = common.MESSAGE_TYPE.NORMAL; 1247 } 1248 } 1249 // Set Draft Content 1250 setDraft() { 1251 // If the content is a draft, the draft content needs to be displayed. 1252 if (this.isDraft) { 1253 this.textValue = this.draftContent; 1254 this.canSendMessage = MmsPreferences.getInstance().haveSimCardReady(); 1255 } 1256 } 1257 1258 updateDetail(threadId, sendResult) { 1259 let sendResults = []; 1260 sendResults.push(sendResult); 1261 let actionData = { 1262 sendResults: sendResults, 1263 threadId: threadId 1264 } 1265 conversationService.updateSessionAndDetail(actionData); 1266 let sendStatus = sendResult.sendStatus 1267 let deliveryReportSwitch = MmsPreferences.getInstance().getValueOfDeliveryReportSwitch(); 1268 HiLog.i(TAG, "updateDetail, sendStatus=" + sendStatus + ", deliveryReportSwitch=" + deliveryReportSwitch) 1269 if ((deliveryReportSwitch == common.DELIVERY_REPORTS.SMS_AND_MMS || 1270 deliveryReportSwitch == common.DELIVERY_REPORTS.SMS) && 1271 sendStatus == common.int.SEND_MESSAGE_SUCCESS) { 1272 let msg = this.strContactsNumber + " 已收到消息!" 1273 this.showToast(msg) 1274 } 1275 } 1276 1277 showToast(msg) { 1278 Prompt.showToast({ 1279 message: msg, 1280 duration: 2000, 1281 }); 1282 } 1283 1284 // Setting the Sending Status 1285 setCanSendMsgStatus() { 1286 if (this.receiveContactValue == common.string.EMPTY_STR && this.selectContacts.length == 0) { 1287 this.canSendMessage = false; 1288 } 1289 } 1290 1291 // Obtains the size of the current MMS file. 1292 getCurEdtFileSize() { 1293 this.curEdtFileSize = 0; 1294 if (!this.isEditMms || this.mmsEditList.length == 0) { 1295 return; 1296 } 1297 for (let element of this.mmsEditList) { 1298 this.curEdtFileSize += element.fileSize; 1299 } 1300 } 1301 1302 dealMmsSendResult(sendNumber, item, sendResult) { 1303 HiLog.i(TAG, "dealMmsSendResult, start") 1304 // MMS Sending 1305 sendResult.sendStatus = common.int.SEND_MESSAGE_SUCCESS; 1306 item.sendStatus = common.int.SEND_MESSAGE_SUCCESS; 1307 this.updateDetail(this.threadId, sendResult); 1308 // The MMS message will be sent for receiving and using. 1309 if (sendNumber.length == 1 && sendResult.sendStatus == common.int.SEND_MESSAGE_SUCCESS) { 1310 setTimeout(() => { 1311 // this.publishData(sendResult.telephone, item.mmsSource); 1312 }, 1000); 1313 } 1314 let params = { 1315 mmsSource: item.mmsSource 1316 }; 1317 sendMsgService.sendMmsMessage(params, (sendStatus) => { 1318 }); 1319 } 1320 1321 dealSmsSendResult(params, item, sendResult) { 1322 sendMsgService.sendMessage(params, (sendStatus) => { 1323 HiLog.i(TAG, "dealSmsSendResult, sendMessage sendStatus: " + sendStatus); 1324 item.sendStatus = sendStatus; 1325 if (sendStatus === common.int.SEND_MESSAGE_FAILED) { 1326 item.failuresNumber = item.failuresNumber + 1; 1327 } 1328 item.completeNumber = item.completeNumber + 1; 1329 sendResult.sendStatus = sendStatus; 1330 // Update sending status 1331 this.updateDetail(this.threadId, sendResult); 1332 this.refresh = !this.refresh 1333 }); 1334 } 1335 1336 getSendMessageId(initDatas, telephone) { 1337 for (let initData of initDatas) { 1338 if (initData.telephone == telephone) { 1339 return initData.id; 1340 } 1341 } 1342 } 1343 1344 convertingSms() { 1345 // Convert to SMS 1346 this.isEditMms = false; 1347 this.showToast($r("app.string.converting_sms")); 1348 } 1349 1350 dealSendResult(actionData, item, initDatas) { 1351 HiLog.i(TAG, "dealSendResult, start") 1352 // Add sending information to the list. 1353 let sendNumbers: Array<string> = actionData.hosts; 1354 let content: string = actionData.content; 1355 for (let i = 0; i < sendNumbers.length; i++) { 1356 let params: LooseObject = { 1357 slotId: actionData.slotId, 1358 destinationHost: sendNumbers[i], 1359 content: content, 1360 }; 1361 let id = this.getSendMessageId(initDatas, sendNumbers[i]); 1362 let sendResult: LooseObject = { 1363 id: id, 1364 telephone: sendNumbers[i], 1365 content: content, 1366 } 1367 if (!item.isMsm) { 1368 this.dealSmsSendResult(params, item, sendResult); 1369 } else { 1370 this.dealMmsSendResult(sendNumbers, item, sendResult); 1371 } 1372 } 1373 } 1374 1375 insertInitData(actionData, item, callback): void { 1376 let sendNumbers: Array<string> = actionData.hosts; 1377 let insertSendResults: Array<LooseObject> = []; 1378 for (let i = 0; i < sendNumbers.length; i++) { 1379 let sendResult: LooseObject = { 1380 slotId: actionData.slotId, 1381 telephone: sendNumbers[i], 1382 content: actionData.content, 1383 sendStatus: common.int.SEND_MESSAGE_SENDING 1384 } 1385 if (item.isMsm) { 1386 sendResult.content = commonService.getMmsContent(item.mmsSource); 1387 } 1388 insertSendResults.push(sendResult); 1389 } 1390 let hasReport: number = settingService.judgeIsDeliveryReport(item.isMsm) ? 1 : 0; 1391 let hasAttachment: boolean = commonService.judgeIsAttachment(item.mmsSource); 1392 let actionData_: LooseObject = { 1393 sendResults: insertSendResults, 1394 isReceive: false, 1395 ownNumber: common.string.EMPTY_STR, 1396 isSender: 0, 1397 hasDraft: this.isDraft, 1398 hasReport: hasReport, 1399 isMms: item.isMsm, 1400 mmsSource: item.mmsSource, 1401 hasAttachment: hasAttachment 1402 } 1403 conversationService.insertSessionAndDetail(actionData_, callback); 1404 } 1405 1406 changeReceiveContactValue(value) { 1407 this.receiveContactValue = value 1408 } 1409 1410 updatePreview(idx) { 1411 // Delete Preview 1412 HiLog.i(TAG, "updatePreview, idx: " + idx); 1413 // If not audio (picture or video) is deleted from the preview, you need to change the value of 1414 // checkbox in the thumbnail of the gallery. 1415 if (this.mmsEditList[idx].type != common.MSG_ITEM_TYPE.AUDIO) { 1416 let that = this; 1417 this.pictureListFromGallery.forEach(function (item) { 1418 if (item.path == that.mmsEditList[idx].uriPath) { 1419 item.checkedValue = false; 1420 that.curEdtFileSize -= that.mmsEditList[idx].fileSize; 1421 that.msgSendTip = Math.ceil(that.curEdtFileSize) + COMMON_FILE_SIZE_STRING; 1422 } 1423 }); 1424 } 1425 this.isOnlyAudio = !this.mmsEditList.some((item, index) => item.type != common.MSG_ITEM_TYPE.AUDIO); 1426 if (this.mmsEditList.length == 0) { 1427 this.convertingSms(); 1428 } 1429 } 1430 1431 initSendItem() { 1432 // Obtains the day of the week. 1433 HiLog.i(TAG, "initSendItem, start") 1434 let item: LooseObject = {}; 1435 item.date = common.string.EMPTY_STR; 1436 item.time = $r("app.string.justNow"); 1437 item.timeMillisecond = new Date().getTime(); 1438 dateUtil.convertTimeStampToDateWeek(item, false); 1439 dateUtil.fullDate(item); 1440 item.content = this.textValue; 1441 item.msgType = this.mmsEditList.length != 0 ? this.mmsEditList[0].type : common.MSG_ITEM_TYPE.TEXT; 1442 item.isFullScreenImg = false; 1443 item.msgUriPath = this.mmsEditList.length != 0 ? this.mmsEditList[0].uriPath : common.string.EMPTY_STR; 1444 let time = (this.mmsEditList.length != 0 && (this.mmsEditList[0].type == 3 || this.mmsEditList[0].type == 5)) ? 1445 this.mmsEditList[0].time : common.string.SUCCESS; 1446 item.audioTime = time; 1447 item.isCbChecked = false; 1448 item.isLock = false; 1449 item.isStared = false; 1450 item.isReceive = false; 1451 item.sendStatus = 1; 1452 item.cancelTimeCount = common.int.CANCEL_TIME_COUNT; 1453 item.subId = this.slotId; 1454 item.mmsEditListTemp = this.mmsEditList; 1455 if (this.contactsNum > 1) { 1456 item.completeNumber = 0; 1457 item.failuresNumber = 0; 1458 } 1459 item.hasReport = settingService.judgeIsDeliveryReport(item.isMsm); 1460 item.msgShowType = this.getMsgShowType(item); 1461 item.mmsSource = this.getMmsSource(); 1462 item.isMsm = this.isEditMms; 1463 this.setDateShow(item, this.mmsList); 1464 this.mmsList.push(item); 1465 this.refresh = !this.refresh 1466 } 1467 // Check whether the time on the top of each SMS message is displayed. 1468 setDateShow(item, list) { 1469 item.dateShow = true; 1470 let tempDateId = item.date.id; 1471 let tempWeekId = item.week.id; 1472 if (list.length > 0) { 1473 item.dateShow = 1474 (tempDateId != (list[list.length-1]).date.id) 1475 && (tempWeekId != (list[list.length-1]).week.id) 1476 } 1477 } 1478 1479 getMmsSource() { 1480 HiLog.i(TAG, "getMmsSource, start") 1481 let sources = []; 1482 this.dealTextareaDataSource(); 1483 if (this.messageType === common.MESSAGE_TYPE.NORMAL) { 1484 sources = this.dealMmsEditList(); 1485 } else { 1486 sources = this.getMmsSourceFromDataSource(); 1487 } 1488 return sources; 1489 } 1490 1491 dealTextareaDataSource() { 1492 HiLog.i(TAG, "dealTextareaDataSource, start") 1493 if (this.messageType == common.MESSAGE_TYPE.THEME) { 1494 let first = this.textareaDatasource[0]; 1495 if (first.textValue == common.string.EMPTY_STR) { 1496 this.messageType = common.MESSAGE_TYPE.NORMAL; 1497 this.textValue = this.textareaDatasource[1].textValue; 1498 this.textareaDatasource = []; 1499 } 1500 } 1501 } 1502 1503 dealMmsEditList() { 1504 HiLog.i(TAG, "dealMmsEditList, start") 1505 let sources = []; 1506 if (this.mmsEditList.length != 0) { 1507 this.mmsEditList.forEach((item, index) => { 1508 let mms = { 1509 msgType: item.type, 1510 msgUriPath: item.uriPath, 1511 content: common.string.EMPTY_STR, 1512 time: item.time, 1513 fileSize: item.fileSize 1514 } 1515 if (index === 0) { 1516 mms.content = this.textValue; 1517 } 1518 sources.push(mms); 1519 }); 1520 } 1521 return sources; 1522 } 1523 1524 getMmsSourceFromDataSource() { 1525 HiLog.i(TAG, "getMmsSourceFromDataSource, start") 1526 let sources = []; 1527 this.textareaDatasource.forEach((item, index) => { 1528 let mms = { 1529 msgType: common.MSG_ITEM_TYPE.TEXT, 1530 msgUriPath: '', 1531 content: item.textValue, 1532 time: '', 1533 fileSize: 0 1534 }; 1535 if (index === 0 && (this.messageType === common.MESSAGE_TYPE.THEME || 1536 this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT)) { 1537 mms.msgType = common.MSG_ITEM_TYPE.THEME; 1538 sources.push(mms); 1539 } else if (this.messageType === common.MESSAGE_TYPE.THEME) { 1540 sources.push(mms); 1541 sources = this.getMmsSourceByTheme(sources, item, mms); 1542 } else { 1543 if (item.mms) { 1544 mms.msgType = item.mms.type; 1545 mms.msgUriPath = item.mms.uriPath; 1546 mms.time = item.mms.time; 1547 mms.fileSize = item.mms.fileSize; 1548 } 1549 sources.push(mms); 1550 } 1551 }); 1552 return sources; 1553 } 1554 1555 getMmsSourceByTheme(sources, item, mms) { 1556 HiLog.i(TAG, "getMmsSourceByTheme, start") 1557 if (this.mmsEditList.length === 1) { 1558 let first = this.mmsEditList[0]; 1559 sources.unshift({ 1560 msgType: first.type, 1561 msgUriPath: first.uriPath, 1562 content: item.textValue, 1563 time: first.time, 1564 fileSize: first.fileSize 1565 }); 1566 } else { 1567 this.getMmsSourceByItem(sources, mms); 1568 } 1569 let arr = JSON.parse(JSON.stringify(sources)); 1570 return arr; 1571 } 1572 1573 getMmsSourceByItem(sources, mms) { 1574 HiLog.i(TAG, "getMmsSourceByItem, start") 1575 this.mmsEditList.forEach((list, i) => { 1576 if (i === 0) { 1577 mms.msgType = list.type; 1578 mms.msgUriPath = list.uriPath; 1579 mms.time = list.time; 1580 mms.fileSize = list.fileSize; 1581 } else { 1582 let mmsObj = { 1583 msgType: list.type, 1584 msgUriPath: list.uriPath, 1585 content: common.string.EMPTY_STR, 1586 time: list.time, 1587 fileSize: list.fileSize 1588 }; 1589 sources.push(mmsObj); 1590 } 1591 }); 1592 } 1593 1594 getMsgShowType(item) { 1595 HiLog.i(TAG, "getMsgShowType, start") 1596 let type = common.MESSAGE_SHOW_TYPE.NORMAL; 1597 let slideString = "msg_slide"; 1598 if (this.messageType === common.MESSAGE_TYPE.NORMAL && this.mmsEditList.length <= 1) { 1599 type = common.MESSAGE_SHOW_TYPE.NORMAL; 1600 item.content = this.textValue; 1601 } else if (this.messageType === common.MESSAGE_TYPE.THEME && this.mmsEditList.length === 1) { 1602 type = common.MESSAGE_SHOW_TYPE.THEME_IMAGE; 1603 item.content = this.getThemeContent(); 1604 } else { 1605 type = this.getMsgShowTypePpt(item, slideString); 1606 } 1607 if (type == common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE || type == common.MESSAGE_SHOW_TYPE.PPT_IMAGE) { 1608 if (item.content == common.string.EMPTY_STR) { 1609 item.content = slideString; 1610 } 1611 } 1612 return type; 1613 } 1614 1615 getMsgShowTypePpt(item, slideString) { 1616 HiLog.i(TAG, "getMsgShowTypePpt, start") 1617 let type = common.MESSAGE_SHOW_TYPE.NORMAL; 1618 let hasSource = this.textareaDatasource.length > 0 ? true : false; 1619 let firstStr = hasSource ? this.textareaDatasource[0].textValue : common.string.EMPTY_STR; 1620 if (this.mmsEditList.length === 0) { 1621 type = common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE; 1622 if (this.messageType === common.MESSAGE_TYPE.THEME || 1623 this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT) { 1624 item.content = this.getThemeContent(); 1625 } else { 1626 item.content = (firstStr == common.string.EMPTY_STR) ? slideString : firstStr; 1627 } 1628 } else { 1629 type = this.getPPTType(); 1630 this.getMsgShowTypeContent(item, firstStr, slideString); 1631 } 1632 return type; 1633 } 1634 1635 getPPTType() { 1636 HiLog.i(TAG, "getPPTType, start") 1637 let type = common.MESSAGE_SHOW_TYPE.NORMAL; 1638 if (this.messageType === common.MESSAGE_TYPE.NORMAL && this.mmsEditList.length > 0) { 1639 type = common.MESSAGE_SHOW_TYPE.PPT_IMAGE; 1640 } else { 1641 let firstMms = null; 1642 if (this.messageType === common.MESSAGE_TYPE.THEME && this.mmsEditList.length > 1) { 1643 firstMms = this.mmsEditList[0]; 1644 } else if (this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT) { 1645 firstMms = this.textareaDatasource[1].mms; 1646 } else { 1647 firstMms = this.textareaDatasource[0].mms; 1648 } 1649 if (this.mmsEditList.length >= 1 && firstMms && 1650 (firstMms.type === common.MSG_ITEM_TYPE.IMAGE || firstMms.type === common.MSG_ITEM_TYPE.VIDEO)) { 1651 type = common.MESSAGE_SHOW_TYPE.PPT_IMAGE; 1652 } else { 1653 type = common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE; 1654 } 1655 } 1656 return type; 1657 } 1658 1659 getMsgShowTypeContent(item, firstStr, slideString) { 1660 HiLog.i(TAG, "getMsgShowTypeContent, start") 1661 if (this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT || 1662 this.messageType === common.MESSAGE_TYPE.THEME) { 1663 item.content = this.getThemeContent(); 1664 } else { 1665 let content = common.string.EMPTY_STR; 1666 if (this.messageType === common.MESSAGE_TYPE.NORMAL) { 1667 content = (this.textValue == common.string.EMPTY_STR) ? slideString : this.textValue; 1668 } else { 1669 content = (firstStr == common.string.EMPTY_STR) ? slideString : firstStr; 1670 } 1671 item.content = content; 1672 } 1673 } 1674 1675 getThemeContent() { 1676 HiLog.i(TAG, "getThemeContent, start") 1677 this.isEditMms = true; 1678 let content = ''; 1679 let first = this.textareaDatasource[0].textValue; 1680 let text = this.textareaDatasource[1].textValue; 1681 if (first !== common.string.EMPTY_STR) { 1682 content = $r("app.string.msg_theme") + ": " + first; 1683 } 1684 if (text !== common.string.EMPTY_STR) { 1685 if (content === common.string.EMPTY_STR) { 1686 content = text; 1687 } else { 1688 content = content + "\n" + text; 1689 } 1690 } 1691 return content; 1692 } 1693 1694 sendMassMessage(actionData, item) { 1695 this.insertInitData(actionData, item, result => { 1696 // Processing the sent result 1697 if (this.threadId != result.rowId) { 1698 // When modifying the recipient information, click Send and delete the session before the modification. 1699 conversationListService.deleteMessageBySessionId([this.threadId]); 1700 } 1701 this.threadId = result.rowId; 1702 this.portraitColor = AvatarColor.background.Color[Math.abs(parseInt(this.threadId, 10)) % 6]; 1703 item.groupId = result.groupId; 1704 item.id = result.initDatas[0].id; 1705 this.refresh = !this.refresh 1706 // Sending and processing the sending result 1707 this.dealSendResult(actionData, item, result.initDatas); 1708 }); 1709 } 1710 1711 clearMsm() { 1712 if (this.isEditMms) { 1713 this.isEditMms = false; 1714 } 1715 // Deleting the preview image of an MMS message 1716 if (this.mmsEditList.length != 0) { 1717 for (let index in this.mmsEditList) { 1718 this.updatePreview(index); 1719 } 1720 this.mmsEditList = []; 1721 } 1722 } 1723 1724 resetMmsSource() { 1725 this.textareaDatasource = []; 1726 this.mmsEditList = []; 1727 this.pptTotalCount = 0; 1728 this.messageType = common.MESSAGE_TYPE.NORMAL; 1729 this.selectedTextareaIdx = -1; 1730 } 1731 1732 send() { 1733 HiLog.i(TAG, "send, start"); 1734 // The Send button is dimmed and messages cannot be sent. 1735 if (!this.canSendMessage) { 1736 HiLog.w(TAG, "send, canSendMessage=false"); 1737 return; 1738 } 1739 // Switching from the new state to the session state 1740 if (this.isNewMsg) { 1741 HiLog.i(TAG, "send, isNewMsg=true"); 1742 this.newSend(() => { 1743 this.sendDataRefresh(); 1744 }); 1745 } else { 1746 this.sendDataRefresh(); 1747 } 1748 } 1749 1750 sendDataRefresh() { 1751 this.isSendStatus = true; 1752 // Send Text 1753 if (this.textValue != common.string.EMPTY_STR || this.mmsEditList.length != 0 || 1754 this.textareaDatasource.length != 0) { 1755 this.initSendItem(); 1756 } 1757 this.slotId = MmsPreferences.getInstance().getSendMessageSlotId(); 1758 let actionData: LooseObject = { 1759 slotId: this.slotId, 1760 destinationHost: this.strContactsNumber, 1761 content: this.textValue, 1762 isEditMms: this.isEditMms 1763 }; 1764 // Real SMS Sending 1765 this.sendInterval(actionData, this.mmsList); 1766 this.textValue = common.string.EMPTY_STR; 1767 this.canSendMessage = false; 1768 this.isShowFullScreen = false; 1769 this.clearMsm(); 1770 this.resetMmsSource(); 1771 this.setTabOperationStatus(false); 1772 this.distanceBottomFlag = false; 1773 this.receiveContactValue = common.string.EMPTY_STR; 1774 this.selectContacts = []; 1775 this.isNewMsg = false; 1776 } 1777 1778 isPhoneNumber(str) { 1779 // Determine whether the value is a number. 1780 let reg = /^\d{1,}$/; 1781 let pattern = new RegExp(reg); 1782 return pattern.test(str); 1783 } 1784 1785 newSend(callback) { 1786 // Check whether the entered content has a value. 1787 if (this.receiveContactValue != common.string.EMPTY_STR) { 1788 if (!this.isPhoneNumber(this.receiveContactValue)) { 1789 // Invalid Recipient 1790 this.showToast($r("app.string.invalid_receive", this.receiveContactValue)) 1791 HiLog.w(TAG, "newSend, PhoneNumber is invalidate"); 1792 return; 1793 } 1794 } 1795 if (this.selectContacts.length > 0 && this.receiveContactValue != common.string.EMPTY_STR) { 1796 let selectContact = { 1797 telephone: this.receiveContactValue, 1798 telephoneFormat: this.receiveContactValue, 1799 contactName: common.string.EMPTY_STR 1800 } 1801 let selectContacts = this.selectContacts; 1802 selectContacts.push(selectContact); 1803 this.initNewSelectContacts(selectContacts); 1804 } else if (this.selectContacts.length > 0) { 1805 this.initNewSelectContacts(this.selectContacts); 1806 } else if (this.receiveContactValue != common.string.EMPTY_STR) { 1807 this.contactsNum = 1; 1808 this.strContactsNumber = this.receiveContactValue; 1809 this.strContactsNumberFormat = this.receiveContactValue; 1810 } else { 1811 HiLog.w(TAG, "newSend, the contact condition is not met.") 1812 return; 1813 } 1814 this.isNewMsg = false; 1815 // To cancel sending, set this parameter to true. 1816 if (this.recallMessagesFlag) { 1817 this.isNewRecallMessagesFlag = true; 1818 this.commonCtrl.paramContact.isNewRecallMessagesFlag = true; 1819 } 1820 // When the new page is displayed in full screen mode, the following table data needs to be obtained. 1821 if (true) { 1822 this.queryOldMessageList(this.strContactsNumber, callback); 1823 } 1824 } 1825 1826 queryOldMessageList(telephone, callback) { 1827 HiLog.i(TAG, "queryOldMessageList, start"); 1828 if (telephone == common.string.EMPTY_STR) { 1829 return; 1830 } 1831 let number = telephoneUtil.dealTelephoneSort(telephone); 1832 conversationListService.querySessionByTelephone(number, res => { 1833 HiLog.i(TAG, "queryOldMessageList, querySessionByTelephone res.response.id: " + res.response.id) 1834 if (res.code == common.int.SUCCESS && res.response.id > 0) { 1835 if (this.threadId != res.response.id) { 1836 // When modifying the recipient information, click Send and delete the session before the 1837 // modification. 1838 conversationListService.deleteMessageBySessionId([this.threadId]); 1839 } 1840 this.threadId = res.response.id; 1841 this.portraitColor = AvatarColor.background.Color[Math.abs(parseInt(this.threadId, 10)) % 6]; 1842 this.queryMessageDetail(telephone, res.response.id, callback); 1843 this.scroller.scrollToIndex(this.mmsList.length - 1) 1844 } else { 1845 callback(); 1846 } 1847 }); 1848 } 1849 1850 initNewSelectContacts(selectContacts) { 1851 HiLog.i(TAG, "initNewSelectContacts, start"); 1852 let contactsNumber = common.string.EMPTY_STR; 1853 let contactsName = common.string.EMPTY_STR; 1854 let contactsNumberFormat = common.string.EMPTY_STR; 1855 let contacts = telephoneUtil.dealSelectContactsSort(selectContacts); 1856 let length = contacts.length; 1857 for (let index in contacts) { 1858 let item = contacts[index]; 1859 contactsNumber = contactsNumber + item.telephone + common.string.COMMA; 1860 contactsNumberFormat = contactsNumberFormat + item.telephoneFormat + common.string.COMMA; 1861 if (item.contactName != common.string.EMPTY_STR) { 1862 contactsName += (item.contactName + common.string.COMMA); 1863 } 1864 } 1865 this.strContactsNumber = contactsNumber.substring(0, contactsNumber.length - 1); 1866 this.strContactsName = contactsName.substring(0, contactsName.length - 1); 1867 this.photoFirstNameDeal(this.strContactsName); 1868 this.strContactsNumberFormat = contactsNumberFormat.substring(0, contactsNumberFormat.length - 1); 1869 this.contactsNum = length; 1870 } 1871 1872 handleWithSend(actionData, item) { 1873 // Sending request processing 1874 let hosts: Array<string> = []; 1875 if (actionData.destinationHost.indexOf(",") == -1) { 1876 // single-shot 1877 hosts.push(actionData.destinationHost); 1878 } else { 1879 // Group Sending 1880 for (let host of actionData.destinationHost.split(",")) { 1881 hosts.push(telephoneUtil.formatTelephone(host)); 1882 } 1883 } 1884 actionData.hosts = hosts; 1885 this.sendMassMessage(actionData, item); 1886 } 1887 1888 sendInterval(actionData, mmsList) { 1889 // Send Timer 1890 let item = mmsList[mmsList.length - 1]; 1891 if (this.recallMessagesFlag) { 1892 item.intervalSendStatus = true; 1893 // Second countdown timer after the Send button is clicked 1894 item.sendIntervalId = setInterval(function () { 1895 item.cancelTimeCount--; 1896 }, 1000); 1897 // Transmit timer, which is sent after 6s. 1898 item.sendTimeoutId = setTimeout(() => { 1899 item.cancelTimeCount = 0; 1900 // Clear Timer 1901 clearTimeout(item.sendTimeoutId); 1902 clearInterval(item.sendIntervalId); 1903 this.handleWithSend(actionData, item); 1904 }, 6000); 1905 } else { 1906 this.handleWithSend(actionData, item); 1907 } 1908 } 1909 1910 changeValue(e) { 1911 this.textValue = e; 1912 if (e == null || e == common.string.EMPTY_STR) { 1913 if (this.mmsEditList.length != 0) { 1914 this.canSendMessage = true; 1915 } else { 1916 this.canSendMessage = false; 1917 } 1918 return; 1919 } 1920 // Whether to display full screen 1921 if (this.isEditMms) { 1922 this.isShowFullScreen = false; 1923 } else { 1924 this.isShowFullScreen = true; 1925 } 1926 if (this.isNewMsg) { 1927 if (this.receiveContactValue == '' && this.selectContacts.length == 0) { 1928 this.canSendMessage = false; 1929 return; 1930 } 1931 } 1932 if (this.textValue.length == 0) { 1933 this.canSendMessage = false; 1934 return; 1935 } else { 1936 this.canSendMessage = MmsPreferences.getInstance().haveSimCardReady() && !this.isFlightMode; 1937 } 1938 if (this.isNewMsg) { 1939 this.setCanSendMsgStatus(); 1940 } 1941 } 1942 1943 setTabTitleText() { 1944 // TabTitleText selected globally 1945 if (this.tabIndex != 1) { 1946 // Non-picture page 1947 this.tabTitleText = this.tabTextList[this.tabIndex]; 1948 return; 1949 } 1950 // On the image selection page, the number of selected images is displayed. 1951 let size = 0; 1952 for (let element of this.pictureListFromGallery) { 1953 if (element.checkedValue) { 1954 size++; 1955 } 1956 } 1957 this.tabTitleText = size == 0 ? $r("app.string.msg_unselected_tip") : $r("app.string.msg_selected_tip", { 1958 number: size 1959 }); 1960 } 1961 1962 // Check whether the sending icon can be highlighted. 1963 judgeSendBtnCanClicked() { 1964 if (MmsPreferences.getInstance().haveSimCardReady() && (this.mmsEditList.length != 0 || 1965 this.textValue != common.string.EMPTY_STR || this.textareaDatasource.length !== 0)) { 1966 if (this.isNewMsg) { 1967 if ((this.receiveContactValue !== '' && this.isPhoneNumber(this.receiveContactValue)) 1968 || this.selectContacts.length !== 0) { 1969 this.canSendMessage = true; 1970 } 1971 } else { 1972 this.canSendMessage = true; 1973 } 1974 } 1975 } 1976 1977 // Subscribing to Public Events 1978 subscribeDetail() { 1979 HiLog.i(TAG, "subscribeDetail, start"); 1980 let events = [common.string.RECEIVE_TRANSMIT_EVENT] 1981 let commonEventSubscribeInfo = { 1982 events: events 1983 }; 1984 // Creating Subscription Information 1985 commonEvent.createSubscriber(commonEventSubscribeInfo, this.createSubscriberCallBack.bind(this)); 1986 } 1987 1988 createSubscriberCallBack(err, data) { 1989 this.commonEventData = data; 1990 // Received subscription 1991 commonEvent.subscribe(this.commonEventData, this.subscriberCallBack.bind(this)); 1992 } 1993 1994 subscriberCallBack(err, data) { 1995 HiLog.i(TAG, "subscriberCallBack, start"); 1996 globalThis.needToUpdate = true; 1997 // Receiving SMS Updates 1998 setTimeout(() => { 1999 this.queryMessageDetail(this.strContactsNumber, this.threadId, () => { 2000 }); 2001 this.scroller.scrollToIndex(this.mmsList.length - 1); 2002 let valueBucket: LooseObject = { 2003 "unread_count": 0, 2004 }; 2005 let actionData: LooseObject = { 2006 threadIds: [this.threadId], 2007 hasRead: 0, 2008 valueBucket: valueBucket 2009 }; 2010 NotificationService.getInstance().cancelMessageNotify(actionData, res => { 2011 actionData.hasRead = 1; 2012 conversationListService.markAllAsRead(actionData); 2013 }); 2014 this.notifySlotIdChange(this.mmsList[this.mmsList.length - 1]); 2015 }, 500); 2016 } 2017 2018 // Unsubscribe 2019 unSubscribeDetail() { 2020 if (this.commonEventData != null) { 2021 commonEvent.unsubscribe(this.commonEventData, () => { 2022 HiLog.i(TAG, "unSubscribeDetail, unsubscribe"); 2023 }); 2024 } 2025 } 2026 2027 notifySlotIdChange(item: LooseObject): void { 2028 if (item == null || item.subId == null) { 2029 HiLog.w(TAG, "notifySlotIdChange, get item.subId error!"); 2030 return; 2031 } 2032 let slotId: number = item.subId; 2033 if (MmsPreferences.getInstance().haveMultiSimCardReady() 2034 && MmsPreferences.getInstance().getSelectedSlotId() != slotId) { 2035 MmsPreferences.getInstance().setValueToMap(common.string.KEY_OF_SELECTED_SLOTID, slotId); 2036 emitter.emit(simCardService.SLOTID_CHANGE_EVENT, { 2037 data: { 2038 "slotId": slotId 2039 } 2040 }); 2041 } 2042 } 2043 2044 // In the selection mode, tap More. In the displayed menu, select 2045 moreSelected(e) { 2046 HiLog.i(TAG, "moreSelected, e: " + JSON.stringify(e)) 2047 switch (e) { 2048 case "0": 2049 // duplicating 2050 this.copyText(); 2051 break; 2052 case 1: 2053 // Share 2054 this.share(); 2055 break; 2056 case 2: 2057 // Select Text 2058 this.gotoTextSelect(this.mmsIndex); 2059 break; 2060 case 3: 2061 // lock 2062 this.lock(); 2063 break; 2064 case 4: 2065 // Show Details 2066 this.showDetails(); 2067 break; 2068 case 5: 2069 // Unlock 2070 this.unlock(); 2071 break; 2072 case 6: 2073 // View Reports 2074 this.showReport(this.mmsIndex); 2075 break; 2076 case 7: 2077 // Save Attachments 2078 this.saveImage(); 2079 break; 2080 case 8: 2081 // Querying vCard Details 2082 this.showVcarDetail(this.mmsIndex); 2083 break; 2084 default: 2085 break; 2086 } 2087 // Exit the multi-selection mode. 2088 this.exitMultiselect(); 2089 } 2090 2091 copyText() { 2092 commonPasteboard.setPasteboard(this.mmsList[this.mmsIndex].content); 2093 } 2094 2095 share() { 2096 for (let i = 0; i < this.mmsList.length; i++) { 2097 if (this.mmsList[i].isCbChecked == true) { 2098 var actionData: LooseObject = {}; 2099 actionData.content = this.mmsList[i].content; 2100 conversationService.gotoShare(actionData, function (data) { 2101 HiLog.i(TAG, "share, gotoShare callback"); 2102 }); 2103 } 2104 } 2105 } 2106 2107 gotoTextSelect(idx) { 2108 router.push({ 2109 uri: "pages/text_select/text_select", 2110 params: this.mmsList[idx] 2111 }) 2112 } 2113 2114 lock() { 2115 this.updateLock(true); 2116 } 2117 2118 unlock() { 2119 this.updateLock(false); 2120 } 2121 2122 updateLock(isLock) { 2123 // Select Content Lock 2124 let groupIds = []; 2125 for (let element of this.mmsList) { 2126 if (element.isCbChecked) { 2127 element.isLock = isLock; 2128 groupIds.push(element.groupId); 2129 } 2130 } 2131 let hasLock = isLock ? 1 : 0; 2132 let actionData: LooseObject = {}; 2133 actionData = { 2134 groupIds: groupIds, 2135 hasLock: hasLock 2136 }; 2137 let that = this; 2138 conversationService.updateLock(actionData, function (result) { 2139 if (result.code == common.int.SUCCESS) { 2140 // Multi-Select Status Off 2141 that.isSelectStatus = false; 2142 that.cancleCheckedAll(); 2143 HiLog.i(TAG, "updateLock, Success"); 2144 } else { 2145 HiLog.w(TAG, "updateLock, failed"); 2146 } 2147 }); 2148 // Update Lock Status 2149 this.updateSessionLock(isLock); 2150 } 2151 2152 showDetails() { 2153 for (let index = 0; index < this.mmsList.length; index++) { 2154 if (this.mmsList[index].isCbChecked == true) { 2155 var time = this.mmsList[index].timeMillisecond; 2156 var timeStash = this.getTime(time); 2157 this.mmsTime = timeStash + this.mmsList[index].time; 2158 if (this.mmsList[index].msgType == 0) { 2159 this.isMmsType = $r("app.string.sms"); 2160 } else { 2161 this.isMmsType = $r("app.string.mms"); 2162 } 2163 2164 if (this.mmsList[index].isReceive) { 2165 this.isSendRecipient = true; 2166 } else { 2167 this.isSendRecipient = false; 2168 } 2169 } 2170 } 2171 // this.$element("mms_details_dialog").show(); 2172 } 2173 2174 showReport(mmsIndex) { 2175 // View Reports 2176 let item = this.mmsList[mmsIndex]; 2177 router.push({ 2178 uri: "pages/queryreport/queryReport", 2179 params: { 2180 isMsm: item.isMsm, 2181 telephone: this.strContactsNumber, 2182 sendStatus: item.sendStatus, 2183 timeMillisecond: item.timeMillisecond 2184 }, 2185 }); 2186 } 2187 2188 saveImage() { 2189 var actionData: LooseObject = {}; 2190 actionData.threadId = this.mmsList[this.mmsIndex].threadId; 2191 actionData.pduId = this.mmsList[this.mmsIndex].pduId; 2192 conversationService.saveImage(actionData, result => { 2193 this.showToast(result); 2194 }); 2195 } 2196 2197 showVcarDetail(mmsIndex) { 2198 2199 } 2200 2201 exitMultiselect() { 2202 // Exit the multi-selection state. 2203 this.isSelectStatus = false; 2204 this.cancleCheckedAll(); 2205 } 2206 2207 longPressMore(e) { 2208 switch (e) { 2209 case 0: 2210 // delete 2211 this.deleteDetail(); 2212 break; 2213 case 1: 2214 // New Contact 2215 this.createNewContract(this.strContactsNumber); 2216 break; 2217 case 2: 2218 // Save to Existing Contacts 2219 this.existingContact(this.strContactsNumber); 2220 break; 2221 case 3: 2222 // Edit Before Call 2223 this.callEditor(this.strContactsNumber); 2224 break; 2225 case 4: 2226 // Add to Blocklist 2227 this.callEditor(this.strContactsNumber); 2228 break; 2229 case 5: 2230 // View Contacts 2231 this.titleBarAvatar(); 2232 break; 2233 default: 2234 break; 2235 } 2236 } 2237 2238 // Delete 2239 deleteDetail() { 2240 if (this.mmsList.length == 1) { 2241 this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_tip3"); 2242 } else { 2243 this.hasDetailDelete = false; 2244 this.isSelectStatus = true; 2245 } 2246 } 2247 2248 // New Contact 2249 createNewContract(number) { 2250 var actionData: LooseObject = {}; 2251 actionData.phoneNumber = number; 2252 actionData.pageFlag = common.contractPage.PAGE_FLAG_SAVE_CONTACT; 2253 this.jumpToContract(actionData); 2254 } 2255 2256 // Edit Before Call 2257 callEditor(number) { 2258 var actionData: LooseObject = {}; 2259 actionData.phoneNumber = number; 2260 actionData.pageFlag = common.contractPage.PAGE_FLAG_EDIT_BEFORE_CALLING; 2261 this.jumpToContract(actionData); 2262 } 2263 2264 // Save to Existing Contacts 2265 existingContact(number) { 2266 var actionData: LooseObject = {}; 2267 actionData.phoneNumber = number; 2268 actionData.pageFlag = common.contractPage.PAGE_FLAG_SAVE_EXIST_CONTACT; 2269 this.jumpToContract(actionData); 2270 } 2271 2272 // Switching to the Contacts app 2273 jumpToContract(actionData) { 2274 let str = commonService.commonContractParam(actionData); 2275 globalThis.mmsContext.startAbility(str).then((data) => { 2276 HiLog.i(TAG, "jumpToContract, startAbility Success"); 2277 }).catch((error) => { 2278 HiLog.e(TAG, "jumpToContract, failed. Cause: " + JSON.stringify(error.message)); 2279 }) 2280 } 2281 2282 // Tap a contact's avatar to go to the contact details page. 2283 titleBarAvatar() { 2284 var actionData = { 2285 phoneNumber: this.strContactsNumber, 2286 pageFlag: common.contractPage.PAGE_FLAG_CONTACT_DETAILS 2287 }; 2288 this.jumpToContract(actionData); 2289 } 2290 2291 clickCall() { 2292 this.call(this.strContactsNumber); 2293 } 2294 2295 call(telephone) { 2296 // Calling 2297 callService.call(telephone, result => { 2298 if (result.code == common.int.SUCCESS) { 2299 HiLog.i(TAG, "call success"); 2300 } else { 2301 HiLog.w(TAG, "call failed"); 2302 } 2303 }); 2304 } 2305 2306 getTime(nS) { 2307 var date = new Date(parseInt(nS)); 2308 var year = date.getFullYear(); 2309 var mon = date.getMonth() + 1; 2310 var day = date.getDate(); 2311 return year; // + $r("app.string.year") + mon + $r("app.string.month") + day + $r("app.string.day"); 2312 } 2313 2314 // Contact data returned on the new page 2315 setReceiveContactValue(receiverData) { 2316 let selectContacts = receiverData.selectContacts; 2317 let receiveContactValue = selectContacts.length > 0 ? common.string.EMPTY_STR : receiverData.contactValue; 2318 let hasBlur = receiverData.hasBlur; 2319 let telephone = common.string.EMPTY_STR; 2320 this.textValue = common.string.EMPTY_STR; 2321 this.setCanSendMessage(selectContacts, receiveContactValue) 2322 if (hasBlur && receiveContactValue != common.string.EMPTY_STR) { 2323 let index = -1; 2324 for (let i = 0; i < selectContacts.length; i++) { 2325 let contact = selectContacts[i]; 2326 if (contact.telephone == receiveContactValue) { 2327 index = i; 2328 break; 2329 } 2330 } 2331 if (index >= 0) { 2332 selectContacts.splice(index, 1); 2333 } 2334 } 2335 if (receiveContactValue != common.string.EMPTY_STR) { 2336 this.receiveContactValue = receiveContactValue; 2337 } else { 2338 this.receiveContactValue = common.string.EMPTY_STR; 2339 } 2340 if(selectContacts.length > 0) { 2341 for (let item of selectContacts) { 2342 if (!this.isPhoneNumber(item.telephone)) { 2343 item.telephone = this.replaceCode(item.telephone); 2344 item.telephoneFormat = this.replaceCode(item.telephoneFormat); 2345 if (item.contactName != common.string.EMPTY_STR) { 2346 item.contactName = common.string.EMPTY_STR; 2347 } 2348 } 2349 if (this.selectContacts.length > 1) { 2350 break 2351 } 2352 this.selectContacts = selectContacts; 2353 } 2354 } else { 2355 this.selectContacts = []; 2356 } 2357 if (this.selectContacts.length > 0) { 2358 for (let element of this.selectContacts) { 2359 telephone += element.telephone + common.string.COMMA; 2360 } 2361 } 2362 if (this.receiveContactValue != common.string.EMPTY_STR) { 2363 telephone += this.receiveContactValue + common.string.COMMA; 2364 } 2365 if (telephone != common.string.EMPTY_STR) { 2366 telephone = telephone.substring(0, telephone.length - 1); 2367 } 2368 if (!hasBlur && telephone != "") { 2369 this.queryOldMessageList(telephone, null); 2370 } 2371 } 2372 2373 setCanSendMessage(selectContacts, receiveContactValue) { 2374 if (this.textValue != common.string.EMPTY_STR || this.isEditMms) { 2375 if (this.canSendMessage) { 2376 if (selectContacts.length == 0 && receiveContactValue == common.string.EMPTY_STR) { 2377 this.canSendMessage = false; 2378 } 2379 } else if ((selectContacts.length != 0 || receiveContactValue != common.string.EMPTY_STR) 2380 && MmsPreferences.getInstance().haveSimCardReady()) { 2381 this.canSendMessage = true; 2382 } 2383 } 2384 } 2385}