• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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_con_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: this.slotId,
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        this.slotId = MmsPreferences.getInstance().getSendMessageSlotId();
735        let actionData: LooseObject = {
736            slotId: this.slotId,
737            destinationHost: this.strContactsNumber,
738            content: content,
739            isEditMms: isMms
740        };
741        this.dealNewRecallMessagesFlag(this.mmsList);
742        HiLog.i(TAG, 'sendSms send start');
743        // Cancel Sending and Normal Sending Methods
744        this.sendInterval(actionData, this.mmsList);
745        HiLog.i(TAG, 'sendSms send end');
746        if (this.isEditMms) {
747            this.isEditMms = false;
748        }
749    }
750
751    initSendSms(content, msgUriPath, isMms, mmsSource) {
752        // Obtain the day of the week.
753        let item: LooseObject = {};
754        item.date = common.string.EMPTY_STR;
755        item.time = $r('app.string.just');
756        item.timeMillisecond = new Date().getTime();
757        dateUtil.convertTimeStampToDateWeek(item, false);
758        dateUtil.fullDate(item);
759        item.content = content;
760        if (isMms) {
761            item.msgType = common.MSG_ITEM_TYPE.IMAGE;
762            item.msgUriPath = msgUriPath;
763        }
764        item.isFullScreenImg = false;
765        let time = (this.mmsEditList.length != 0 && (this.mmsEditList[0].type == 3 || this.mmsEditList[0].type == 5)) ?
766        this.mmsEditList[0].time : common.string.SUCCESS;
767        item.audioTime = time;
768        item.isCbChecked = false;
769        item.isLock = false;
770        item.isStared = false;
771        item.isReceive = false;
772        item.sendStatus = 1;
773        item.subId = this.slotId;
774        item.isMsm = isMms;
775        this.contactsNum = this.strContactsNumber.split(',').length;
776        item.contactsNum = this.contactsNum;
777        item.cancelTimeCount = common.int.CANCEL_TIME_COUNT;
778        item.mmsEditListTemp = this.fillmmsEditListTemp(msgUriPath, isMms);
779        if (this.contactsNum > 1) {
780            item.completeNumber = 0;
781            item.failuresNumber = 0;
782        }
783        item.hasReport = settingService.judgeIsDeliveryReport(item.isMsm);
784        item.mmsSource = mmsSource;
785        if (this.isEditMms || isMms) {
786            item.msgShowType = commonService.getDisplay(mmsSource);
787            commonService.setItemMmsContent(item, mmsSource);
788            item.content = this.dealItemContent(item.msgShowType, item.content, mmsSource);
789        } else {
790            item.msgShowType = common.MESSAGE_SHOW_TYPE.NORMAL;
791        }
792        this.mmsList.push(item);
793    }
794
795    fillmmsEditListTemp(msgUriPath, isMsm) {
796        let mmsEditListTemp = [];
797        if (this.recallMessagesFlag && isMsm) {
798            let item = {};
799            item.type = common.MSG_ITEM_TYPE.IMAGE;
800            item.uriPath = msgUriPath;
801            mmsEditListTemp.push(item);
802        }
803        return mmsEditListTemp;
804    }
805
806    dealNewRecallMessagesFlag(mmsList) {
807        let count = common.int.MESSAGE_CODE_ZERO;
808        for (let index in mmsList) {
809            let item = mmsList[index];
810            if (!item.isDraft) {
811                count++;
812            }
813        }
814        if (count == common.int.MESSAGE_CODE_ONE) {
815            this.isNewRecallMessagesFlag = true;
816            this.commonCtrl.paramContact.isNewRecallMessagesFlag = true;
817        }
818        if (count == common.int.MESSAGE_CODE_ZERO && this.isNewRecallMessagesFlag) {
819            this.isNewMsg = true;
820            this.isNewRecallMessagesFlag = false;
821        }
822    }
823
824    // Single Forwarding
825    transmitMsgSingle() {
826        // Forwarding a single message
827        let item: LooseObject = this.mmsList[this.mmsIndex];
828        let transmitObj: LooseObject = {};
829        let contactsName: string | Resource = common.string.EMPTY_STR;
830        if (this.strContactsName && this.strContactsName != common.string.EMPTY_STR) {
831            contactsName = $r('app.string.transmitContentReceive', this.strContactsName);
832        } else {
833            contactsName = $r('app.string.transmitContentReceive', this.strContactsNumberFormat);
834        }
835        transmitObj.contactsName = contactsName;
836        transmitObj.isMsm = item.isMsm;
837        transmitObj.msgShowType = item.msgShowType;
838        transmitObj.mms = item.mms;
839        transmitObj.content = item.content;
840        transmitObj.msgUriPath = item.msgUriPath ? item.msgUriPath : common.string.EMPTY_STR;
841        transmitObj.contentInfo = common.string.EMPTY_STR;
842        transmitObj.msgType = item.msgType;
843        let transmitContentList = [];
844        transmitContentList.push(transmitObj);
845        let transmitContent = item.isReceive ? contactsName : $r('app.string.transmitContent');
846        this.jumpTransmitMsg(transmitContent, transmitContentList, item.isMsm);
847    }
848
849    jumpTransmitMsg(transmitContent, transmitContentList, isMms) {
850        router.push({
851            uri: 'pages/transmitmsg/transmitMsg',
852            params: {
853                threadId: this.threadId,
854                doubleCard: false,
855                transmitContent: transmitContent,
856                transmitContentList: transmitContentList,
857                isMulti: true,
858                isMms: isMms,
859                isMyStartPage: false
860            }
861        });
862    }
863
864    // Delete a dialog box.
865    deleteDialogShow() {
866        this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_con_tip1");
867        let item = this.mmsList[this.mmsIndex];
868        item.isShowMsgLongMenu = false
869        HiLog.i(TAG, "deleteDialogShow, isShowMsgLongMenu=" + item.isShowMsgLongMenu);
870        this.hasLockMsg = item.isLock;
871        if (!item.isMsm) {
872            this.hasContent = true;
873            return;
874        }
875    }
876
877    // more
878    more() {
879        this.setTabOperationStatus(false);
880        this.distanceBottomFlag = false;
881        let item = this.mmsList[this.mmsIndex];
882
883        item.isCbChecked = !item.isCbChecked;
884        item.isShowMsgLongMenu = false;
885        HiLog.i(TAG, "more, isShowMsgLongMenu=" + item.isShowMsgLongMenu);
886        this.setSelectStatus(true);
887        this.hasDetailDelete = false;
888        this.setMessageCheckAll(common.int.CHECKBOX_SELECT_UNKNOWN);
889        this.hasReport = item.hasReport;
890        this.setGroupMoreMenu(item);
891    }
892
893    setTabOperationStatus(flag) {
894        this.isShowMoreOperation = flag;
895        // Value type. The HTML page is refreshed only when the value type is numeric.
896        if (flag) {
897            this.sendBarMarginBottom = common.int.TAB_HEIGHT;
898        } else {
899            this.sendBarMarginBottom = 0;
900        }
901    }
902
903    setSelectStatus(isSelect) {
904        this.isSelectStatus = isSelect;
905    }
906
907    // Event of pressing and holding an SMS message
908    mmsListLongPress(index) {
909        for (let i = 0; i < this.mmsList.length; i++) {
910            if (index == i) {
911                this.mmsList[index].isShowMsgLongMenu = true;
912            } else {
913                this.mmsList[i].isShowMsgLongMenu = false;
914            }
915        }
916        this.refresh = !this.refresh
917        this.mmsIndex = index;
918        if (this.isSelectStatus) {
919            this.mmsList[index].isCbChecked = !this.mmsList[index].isCbChecked;
920            this.setMessageCheckAll(common.int.CHECKBOX_SELECT_UNKNOWN);
921            return;
922        }
923        this.hasContent = false;
924        this.hasImage = false;
925        let item = this.mmsList[index];
926        let menuId = common.string.EMPTY_STR;
927        if (item.isMsm) {
928            this.setGroupMoreMenu(item);
929            //      menuId = "menu_long_press_mms";
930        } else {
931            //      menuId = "menu_long_press";
932        }
933        //    setTimeout(() => {
934        //      this.$element(menuId).show({
935        //        x: this.rawX,
936        //        y: this.rawY
937        //      });
938        //    },100);
939    }
940
941    touchStart(e) {
942        this.rawX = e.globalX;
943        this.rawY = e.globalY;
944
945    }
946
947    deleteDialogCancel() {
948        // Cancel Ejection
949        this.isSelectLockMsg = false;
950        HiLog.i(TAG, "deleteDialogCancel, isSelectLockMsg=false")
951    }
952
953    deleteDialogConfirm() {
954        let groupIds = [];
955        let mmsListCopy = [];
956        HiLog.i(TAG, "deleteDialogConfirm, isSelectStatus=" + this.isSelectStatus);
957        if (this.isSelectStatus) {
958            // Delete the selected item through the filter.
959            for (let element of this.mmsList) {
960                if (!element.isCbChecked || (element.isLock && !this.isSelectLockMsg)) {
961                    this.setDateShow(element, mmsListCopy);
962                    mmsListCopy.push(element);
963                } else {
964                    groupIds.push(element.groupId);
965                }
966            }
967            // Set to non-multi-choice status
968            this.setSelectStatus(false);
969            this.mmsList = mmsListCopy;
970        } else if ((this.mmsList[this.mmsIndex] != undefined && !this.mmsList[this.mmsIndex].isLock) || this.isSelectLockMsg) {
971            let item = this.mmsList[this.mmsIndex];
972            for (let i = 0; i < this.mmsList.length; i++) {
973                if (this.mmsIndex == i) {
974                    continue;
975                } else {
976                    this.setDateShow(this.mmsList[i], mmsListCopy);
977                    mmsListCopy.push(this.mmsList[i]);
978                }
979            }
980            this.mmsList = mmsListCopy;
981            HiLog.i(TAG, "deleteDialogConfirm, mmsList.length=" + this.mmsList.length);
982            groupIds.push(item.groupId);
983        }
984        this.isSelectLockMsg = false;
985        this.cancleCheckedAll();
986        if (groupIds.length > 0) {
987            this.deleteMessageByGroupIds(groupIds);
988            // Check whether the length of the deleted list is 0.
989            if (this.mmsList.length === 0 && this.textValue === common.string.EMPTY_STR) {
990                globalThis.needToUpdate = true;
991                this.deleteMessageById(this.threadId);
992                router.back();
993            } else {
994                this.updateSessionLock(false);
995                this.updateLastItemContent();
996            }
997        }
998        // After the deletion is complete, check whether all data is deleted.
999    }
1000
1001    deleteMessageByGroupIds(groupIds) {
1002        let actionData = {
1003            groupIds: groupIds,
1004        };
1005        // Invoke the database deletion method.
1006        conversationService.deleteMessageByGroupIds(actionData);
1007    }
1008
1009    // Updates the lock status of the session list.
1010    updateSessionLock(isLock) {
1011        let threadIds = [this.threadId];
1012        let hasLock = isLock ? 1 : 0;
1013        let valueBucket = {
1014            "has_lock": hasLock,
1015        }
1016        if (!isLock) {
1017            // If you want to unlock the status, you must unlock all the statuses before unlocking the statuses.
1018            let unlockCount = 0;
1019            for (let element of this.mmsList) {
1020                if (!element.isLock) {
1021                    unlockCount++;
1022                }
1023            }
1024            if (unlockCount != this.mmsList.length) {
1025                HiLog.w(TAG, "updateSessionLock, it is not all select unlock");
1026                return;
1027            }
1028        }
1029        // If it is locked, update the status to locked.
1030        conversationListService.updateById(threadIds, valueBucket);
1031    }
1032
1033    updateLastItemContent() {
1034        let actionData = {
1035            mmsList: this.mmsList,
1036            threadId: this.threadId,
1037        };
1038        conversationListService.updateLastItemContent(actionData);
1039    }
1040
1041    deleteMessageById(threadId) {
1042        let threadIds = [threadId];
1043        // Deleting Database Data
1044        let actionData = {
1045            threadIds: threadIds,
1046        };
1047        conversationListService.deleteMessageById(actionData);
1048    }
1049
1050    clickGroupDelete() {
1051        if (this.selectDeleteMsgCount == 0) {
1052            return;
1053        }
1054        if (this.selectDeleteMsgCount == 1) {
1055            this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_con_tip1");
1056        } else if (this.selectDeleteMsgCount == this.mmsList.length) {
1057            this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_con_tip3");
1058        } else {
1059            this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_con_tip2", this.selectDeleteMsgCount);
1060        }
1061        this.hasLockMsg = (this.mmsList.some((element, index) => element.isCbChecked && element.isLock));
1062    }
1063
1064    // Check whether a contact exists.
1065    judgeContactExists() {
1066        let telephones = [this.strContactsNumber];
1067        let actionData = {
1068            telephones: telephones
1069        };
1070        conversationService.judgeContactExists(actionData, result => {
1071            this.hasExitContract = result;
1072        });
1073        if (this.strContactsName == common.string.EMPTY_STR) {
1074            this.hasExitContract = false;
1075        } else {
1076            this.hasExitContract = true;
1077        }
1078    }
1079
1080    /**
1081     * Obtain information details.
1082     *
1083     * @param telephone
1084     * @param threadId
1085     * @param callback
1086     */
1087    queryMessageDetail(telephone, threadId, callback) {
1088        let actionData: LooseObject = {};
1089        if (telephone != common.string.EMPTY_STR) {
1090            actionData.telephone = telephone;
1091        }
1092        if (threadId != common.string.EMPTY_STR) {
1093            actionData.threadId = threadId;
1094        }
1095        actionData.contactsNum = this.contactsNum;
1096        conversationService.queryMessageDetail(actionData, result => {
1097            if (result.code == common.int.SUCCESS) {
1098                this.initIsShowMsgLongMenu(result);
1099                this.dealMessageDetailTime(result);
1100                this.dealMessageDetailContent(result);
1101                if (this.mmsList.length == 0 && this.isDraft) {
1102                    HiLog.i(TAG, "queryMessageDetail, isNewMsg = true");
1103                    this.isNewMsg = true;
1104                }
1105            } else {
1106                HiLog.w(TAG, "queryMessageDetail, failed");
1107            }
1108            if (this.isDraft) {
1109                this.setDraft();
1110            }
1111            this.deleteDraftData();
1112            callback();
1113        });
1114    }
1115
1116    initIsShowMsgLongMenu(result) {
1117        for (let item of result.response) {
1118            item.isShowMsgLongMenu = false;
1119        }
1120    }
1121
1122    dealItemContent(showType, content, mmsSource) {
1123        let strContent = content;
1124        if (showType == common.MESSAGE_SHOW_TYPE.THEME_NO_IMAGE || showType == common.MESSAGE_SHOW_TYPE.THEME_IMAGE) {
1125            if (content !== common.string.EMPTY_STR) {
1126                strContent = $r("app.string.msg_theme") + ": " + content;
1127            }
1128        } else if (showType == common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE) {
1129            strContent = (content == common.string.EMPTY_STR) ? $r("app.string.msg_slide") : content;
1130        } else if (showType == common.MESSAGE_SHOW_TYPE.PPT_IMAGE) {
1131            if (mmsSource[0].msgType == common.MSG_ITEM_TYPE.THEME && content !== common.string.EMPTY_STR) {
1132                strContent = $r("app.string.msg_theme") + ": " + content;
1133            } else {
1134                strContent = (content == common.string.EMPTY_STR) ? $r("app.string.msg_slide") : content;
1135            }
1136        }
1137        return strContent;
1138    }
1139
1140    dealMessageDetailContent(result) {
1141        for (let item of result.response) {
1142            item.content = this.dealItemContent(item.msgShowType, item.content, item.mms);
1143        }
1144    }
1145
1146    dealMessageDetailTime(result) {
1147        if (result.response && result.response.length > 0) {
1148            let resultList = [];
1149            for (let item of result.response) {
1150                item.timeMillisecond = parseInt(item.timeMillisecond);
1151                dateUtil.fullDate(item);
1152                dateUtil.convertTimeStampToDateWeek(item, false);
1153                this.setDateShow(item, resultList);
1154                dateUtil.convertDateFormatForItem(item, false);
1155                if (item.sendStatus == common.int.SEND_DRAFT) {
1156                    this.dealDraftData(item);
1157                } else {
1158                    resultList.push(item);
1159                }
1160            }
1161            this.mmsList = resultList;
1162        }
1163    }
1164
1165    deleteDraftData() {
1166        if (this.isDraft && this.draftGroupId > 0) {
1167            let groupIds = [this.draftGroupId];
1168            this.deleteMessageByGroupIds(groupIds);
1169            this.draftGroupId = 0;
1170        }
1171    }
1172
1173    getMmsDataSource(mmsSource, first) {
1174        this.pptTotalCount = (first.msgType == common.MSG_ITEM_TYPE.THEME) ? -1 : 0;
1175        let mms = [];
1176        let textareas = [];
1177        mmsSource.forEach((source, index) => {
1178            this.pptTotalCount++;
1179            let mmsObj = null;
1180            if (source.msgType == common.MSG_ITEM_TYPE.AUDIO ||
1181            source.msgType == common.MSG_ITEM_TYPE.IMAGE ||
1182            source.msgType == common.MSG_ITEM_TYPE.VIDEO) {
1183                mmsObj = {
1184                    type: source.msgType,
1185                    uriPath: source.msgUriPath,
1186                    time: source.time,
1187                    index: this.pptTotalCount,
1188                    fileSize: first.fileSize
1189                };
1190                mms.push(mmsObj);
1191            }
1192            let placeholder = $r("app.string.enter_text");
1193            if (source.msgType == common.MSG_ITEM_TYPE.THEME) {
1194                placeholder = $r("app.string.msg_theme");
1195            } else if (mmsSource[0].msgType == common.MSG_ITEM_TYPE.THEME && mmsSource.length == 2) {
1196                if (mmsObj) {
1197                    placeholder = $r("app.string.msg_note_mms2");
1198                } else {
1199                    placeholder = $r("app.string.msg_note_mms");
1200                }
1201                this.pptTotalCount = 0;
1202            }
1203            let obj = {
1204                textValue: source.content,
1205                placeholder: placeholder,
1206                pptIndex: this.pptTotalCount,
1207                mms: mmsObj
1208            };
1209            textareas.push(obj);
1210        });
1211        this.mmsEditList = mms;
1212        this.textareaDatasource = textareas;
1213    }
1214
1215    setMmsDataSource(mmsSource) {
1216        this.mmsEditList = [];
1217        this.textareaDatasource = [];
1218        let first = mmsSource[0];
1219        this.messageType = first.messageType;
1220        if (this.messageType == common.MESSAGE_TYPE.NORMAL) {
1221            let arr = [];
1222            mmsSource.forEach(item => {
1223                let obj = {
1224                    type: item.msgType,
1225                    uriPath: item.msgUriPath,
1226                    time: item.time,
1227                    fileSize: item.fileSize
1228                }
1229                arr.push(obj);
1230            });
1231            this.mmsEditList = arr;
1232        } else {
1233            this.getMmsDataSource(mmsSource, first);
1234        }
1235    }
1236
1237    dealDraftData(item) {
1238        this.isDraft = true;
1239        this.draftContent = item.content;
1240        this.draftGroupId = item.groupId;
1241        if (item.isMsm) {
1242            this.isEditMms = true;
1243            this.setMmsDataSource(item.mms);
1244        } else {
1245            this.messageType = common.MESSAGE_TYPE.NORMAL;
1246        }
1247    }
1248    // Set Draft Content
1249    setDraft() {
1250        // If the content is a draft, the draft content needs to be displayed.
1251        if (this.isDraft) {
1252            this.textValue = this.draftContent;
1253            this.canSendMessage = MmsPreferences.getInstance().haveSimCardReady();
1254        }
1255    }
1256
1257    updateDetail(threadId, sendResult) {
1258        let sendResults = [];
1259        sendResults.push(sendResult);
1260        let actionData = {
1261            sendResults: sendResults,
1262            threadId: threadId
1263        }
1264        conversationService.updateSessionAndDetail(actionData);
1265        let sendStatus = sendResult.sendStatus
1266        let deliveryReportSwitch = MmsPreferences.getInstance().getValueOfDeliveryReportSwitch();
1267        HiLog.i(TAG, "updateDetail, sendStatus=" + sendStatus + ", deliveryReportSwitch=" + deliveryReportSwitch)
1268        if ((deliveryReportSwitch == common.DELIVERY_REPORTS.SMS_AND_MMS ||
1269        deliveryReportSwitch == common.DELIVERY_REPORTS.SMS) &&
1270        sendStatus == common.int.SEND_MESSAGE_SUCCESS) {
1271            let msg = this.strContactsNumber + " 已收到消息!"
1272            this.showToast(msg)
1273        }
1274    }
1275
1276    showToast(msg) {
1277        Prompt.showToast({
1278            message: msg,
1279            duration: 2000,
1280        });
1281    }
1282
1283    // Setting the Sending Status
1284    setCanSendMsgStatus() {
1285        if (this.receiveContactValue == common.string.EMPTY_STR && this.selectContacts.length == 0) {
1286            this.canSendMessage = false;
1287        }
1288    }
1289
1290    // Obtains the size of the current MMS file.
1291    getCurEdtFileSize() {
1292        this.curEdtFileSize = 0;
1293        if (!this.isEditMms || this.mmsEditList.length == 0) {
1294            return;
1295        }
1296        for (let element of this.mmsEditList) {
1297            this.curEdtFileSize += element.fileSize;
1298        }
1299    }
1300
1301    dealMmsSendResult(sendNumber, item, sendResult) {
1302        HiLog.i(TAG, "dealMmsSendResult, start")
1303        // MMS Sending
1304        sendResult.sendStatus = common.int.SEND_MESSAGE_SUCCESS;
1305        item.sendStatus = common.int.SEND_MESSAGE_SUCCESS;
1306        this.updateDetail(this.threadId, sendResult);
1307        // The MMS message will be sent for receiving and using.
1308        if (sendNumber.length == 1 && sendResult.sendStatus == common.int.SEND_MESSAGE_SUCCESS) {
1309            setTimeout(() => {
1310                //        this.publishData(sendResult.telephone, item.mmsSource);
1311            }, 1000);
1312        }
1313        let params = {
1314            mmsSource: item.mmsSource
1315        };
1316        sendMsgService.sendMmsMessage(params, (sendStatus) => {
1317        });
1318    }
1319
1320    dealSmsSendResult(params, item, sendResult) {
1321        sendMsgService.sendMessage(params, (sendStatus) => {
1322            HiLog.i(TAG, "dealSmsSendResult, sendMessage sendStatus: " + sendStatus);
1323            item.sendStatus = sendStatus;
1324            if (sendStatus === common.int.SEND_MESSAGE_FAILED) {
1325                item.failuresNumber = item.failuresNumber + 1;
1326            }
1327            item.completeNumber = item.completeNumber + 1;
1328            sendResult.sendStatus = sendStatus;
1329            // Update sending status
1330            this.updateDetail(this.threadId, sendResult);
1331            this.refresh = !this.refresh
1332        });
1333    }
1334
1335    getSendMessageId(initDatas, telephone) {
1336        for (let initData of initDatas) {
1337            if (initData.telephone == telephone) {
1338                return initData.id;
1339            }
1340        }
1341    }
1342
1343    convertingSms() {
1344        // Convert to SMS
1345        this.isEditMms = false;
1346        this.showToast($r("app.string.converting_sms"));
1347    }
1348
1349    dealSendResult(actionData, item, initDatas) {
1350        HiLog.i(TAG, "dealSendResult, start")
1351        // Add sending information to the list.
1352        let sendNumbers: Array<string> = actionData.hosts;
1353        let content: string = actionData.content;
1354        for (let i = 0; i < sendNumbers.length; i++) {
1355            let params: LooseObject = {
1356                slotId: actionData.slotId,
1357                destinationHost: sendNumbers[i],
1358                content: content,
1359            };
1360            let id = this.getSendMessageId(initDatas, sendNumbers[i]);
1361            let sendResult: LooseObject = {
1362                id: id,
1363                telephone: sendNumbers[i],
1364                content: content,
1365            }
1366            if (!item.isMsm) {
1367                this.dealSmsSendResult(params, item, sendResult);
1368            } else {
1369                this.dealMmsSendResult(sendNumbers, item, sendResult);
1370            }
1371        }
1372    }
1373
1374    insertInitData(actionData, item, callback): void {
1375        let sendNumbers: Array<string> = actionData.hosts;
1376        let insertSendResults: Array<LooseObject> = [];
1377        for (let i = 0; i < sendNumbers.length; i++) {
1378            let sendResult: LooseObject = {
1379                slotId: actionData.slotId,
1380                telephone: sendNumbers[i],
1381                content: actionData.content,
1382                sendStatus: common.int.SEND_MESSAGE_SENDING
1383            }
1384            if (item.isMsm) {
1385                sendResult.content = commonService.getMmsContent(item.mmsSource);
1386            }
1387            insertSendResults.push(sendResult);
1388        }
1389        let hasReport: number = settingService.judgeIsDeliveryReport(item.isMsm) ? 1 : 0;
1390        let hasAttachment: boolean = commonService.judgeIsAttachment(item.mmsSource);
1391        let actionData_: LooseObject = {
1392            sendResults: insertSendResults,
1393            isReceive: false,
1394            ownNumber: common.string.EMPTY_STR,
1395            isSender: 0,
1396            hasDraft: this.isDraft,
1397            hasReport: hasReport,
1398            isMms: item.isMsm,
1399            mmsSource: item.mmsSource,
1400            hasAttachment: hasAttachment
1401        }
1402        conversationService.insertSessionAndDetail(actionData_, callback);
1403    }
1404
1405    changeReceiveContactValue(value) {
1406        this.receiveContactValue = value
1407    }
1408
1409    updatePreview(idx) {
1410        // Delete Preview
1411        HiLog.i(TAG, "updatePreview, idx: " + idx);
1412        // If not audio (picture or video) is deleted from the preview, you need to change the value of
1413        // checkbox in the thumbnail of the gallery.
1414        if (this.mmsEditList[idx].type != common.MSG_ITEM_TYPE.AUDIO) {
1415            let that = this;
1416            this.pictureListFromGallery.forEach(function (item) {
1417                if (item.path == that.mmsEditList[idx].uriPath) {
1418                    item.checkedValue = false;
1419                    that.curEdtFileSize -= that.mmsEditList[idx].fileSize;
1420                    that.msgSendTip = Math.ceil(that.curEdtFileSize) + COMMON_FILE_SIZE_STRING;
1421                }
1422            });
1423        }
1424        this.isOnlyAudio = !this.mmsEditList.some((item, index) => item.type != common.MSG_ITEM_TYPE.AUDIO);
1425        if (this.mmsEditList.length == 0) {
1426            this.convertingSms();
1427        }
1428    }
1429
1430    initSendItem() {
1431        // Obtains the day of the week.
1432        HiLog.i(TAG, "initSendItem, start")
1433        let item: LooseObject = {};
1434        item.date = common.string.EMPTY_STR;
1435        item.time = $r("app.string.justNow");
1436        item.timeMillisecond = new Date().getTime();
1437        dateUtil.convertTimeStampToDateWeek(item, false);
1438        dateUtil.fullDate(item);
1439        item.content = this.textValue;
1440        item.msgType = this.mmsEditList.length != 0 ? this.mmsEditList[0].type : common.MSG_ITEM_TYPE.TEXT;
1441        item.isFullScreenImg = false;
1442        item.msgUriPath = this.mmsEditList.length != 0 ? this.mmsEditList[0].uriPath : common.string.EMPTY_STR;
1443        let time = (this.mmsEditList.length != 0 && (this.mmsEditList[0].type == 3 || this.mmsEditList[0].type == 5)) ?
1444            this.mmsEditList[0].time : common.string.SUCCESS;
1445        item.audioTime = time;
1446        item.isCbChecked = false;
1447        item.isLock = false;
1448        item.isStared = false;
1449        item.isReceive = false;
1450        item.sendStatus = 1;
1451        item.cancelTimeCount = common.int.CANCEL_TIME_COUNT;
1452        item.subId = this.slotId;
1453        item.mmsEditListTemp = this.mmsEditList;
1454        if (this.contactsNum > 1) {
1455            item.completeNumber = 0;
1456            item.failuresNumber = 0;
1457        }
1458        item.hasReport = settingService.judgeIsDeliveryReport(item.isMsm);
1459        item.msgShowType = this.getMsgShowType(item);
1460        item.mmsSource = this.getMmsSource();
1461        item.isMsm = this.isEditMms;
1462        this.setDateShow(item, this.mmsList);
1463        this.mmsList.push(item);
1464        this.refresh = !this.refresh
1465    }
1466    // Check whether the time on the top of each SMS message is displayed.
1467    setDateShow(item, list) {
1468        item.dateShow = true;
1469        let tempDateId = item.date.id;
1470        let tempWeekId = item.week.id;
1471        if (list.length > 0) {
1472            item.dateShow =
1473            (tempDateId != (list[list.length-1]).date.id)
1474            && (tempWeekId != (list[list.length-1]).week.id)
1475        }
1476    }
1477
1478    getMmsSource() {
1479        HiLog.i(TAG, "getMmsSource, start")
1480        let sources = [];
1481        this.dealTextareaDataSource();
1482        if (this.messageType === common.MESSAGE_TYPE.NORMAL) {
1483            sources = this.dealMmsEditList();
1484        } else {
1485            sources = this.getMmsSourceFromDataSource();
1486        }
1487        return sources;
1488    }
1489
1490    dealTextareaDataSource() {
1491        HiLog.i(TAG, "dealTextareaDataSource, start")
1492        if (this.messageType == common.MESSAGE_TYPE.THEME) {
1493            let first = this.textareaDatasource[0];
1494            if (first.textValue == common.string.EMPTY_STR) {
1495                this.messageType = common.MESSAGE_TYPE.NORMAL;
1496                this.textValue = this.textareaDatasource[1].textValue;
1497                this.textareaDatasource = [];
1498            }
1499        }
1500    }
1501
1502    dealMmsEditList() {
1503        HiLog.i(TAG, "dealMmsEditList, start")
1504        let sources = [];
1505        if (this.mmsEditList.length != 0) {
1506            this.mmsEditList.forEach((item, index) => {
1507                let mms = {
1508                    msgType: item.type,
1509                    msgUriPath: item.uriPath,
1510                    content: common.string.EMPTY_STR,
1511                    time: item.time,
1512                    fileSize: item.fileSize
1513                }
1514                if (index === 0) {
1515                    mms.content = this.textValue;
1516                }
1517                sources.push(mms);
1518            });
1519        }
1520        return sources;
1521    }
1522
1523    getMmsSourceFromDataSource() {
1524        HiLog.i(TAG, "getMmsSourceFromDataSource, start")
1525        let sources = [];
1526        this.textareaDatasource.forEach((item, index) => {
1527            let mms = {
1528                msgType: common.MSG_ITEM_TYPE.TEXT,
1529                msgUriPath: '',
1530                content: item.textValue,
1531                time: '',
1532                fileSize: 0
1533            };
1534            if (index === 0 && (this.messageType === common.MESSAGE_TYPE.THEME ||
1535            this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT)) {
1536                mms.msgType = common.MSG_ITEM_TYPE.THEME;
1537                sources.push(mms);
1538            } else if (this.messageType === common.MESSAGE_TYPE.THEME) {
1539                sources.push(mms);
1540                sources = this.getMmsSourceByTheme(sources, item, mms);
1541            } else {
1542                if (item.mms) {
1543                    mms.msgType = item.mms.type;
1544                    mms.msgUriPath = item.mms.uriPath;
1545                    mms.time = item.mms.time;
1546                    mms.fileSize = item.mms.fileSize;
1547                }
1548                sources.push(mms);
1549            }
1550        });
1551        return sources;
1552    }
1553
1554    getMmsSourceByTheme(sources, item, mms) {
1555        HiLog.i(TAG, "getMmsSourceByTheme, start")
1556        if (this.mmsEditList.length === 1) {
1557            let first = this.mmsEditList[0];
1558            sources.unshift({
1559                msgType: first.type,
1560                msgUriPath: first.uriPath,
1561                content: item.textValue,
1562                time: first.time,
1563                fileSize: first.fileSize
1564            });
1565        } else {
1566            this.getMmsSourceByItem(sources, mms);
1567        }
1568        let arr = JSON.parse(JSON.stringify(sources));
1569        return arr;
1570    }
1571
1572    getMmsSourceByItem(sources, mms) {
1573        HiLog.i(TAG, "getMmsSourceByItem, start")
1574        this.mmsEditList.forEach((list, i) => {
1575            if (i === 0) {
1576                mms.msgType = list.type;
1577                mms.msgUriPath = list.uriPath;
1578                mms.time = list.time;
1579                mms.fileSize = list.fileSize;
1580            } else {
1581                let mmsObj = {
1582                    msgType: list.type,
1583                    msgUriPath: list.uriPath,
1584                    content: common.string.EMPTY_STR,
1585                    time: list.time,
1586                    fileSize: list.fileSize
1587                };
1588                sources.push(mmsObj);
1589            }
1590        });
1591    }
1592
1593    getMsgShowType(item) {
1594        HiLog.i(TAG, "getMsgShowType, start")
1595        let type = common.MESSAGE_SHOW_TYPE.NORMAL;
1596        let slideString = "msg_slide";
1597        if (this.messageType === common.MESSAGE_TYPE.NORMAL && this.mmsEditList.length <= 1) {
1598            type = common.MESSAGE_SHOW_TYPE.NORMAL;
1599            item.content = this.textValue;
1600        } else if (this.messageType === common.MESSAGE_TYPE.THEME && this.mmsEditList.length === 1) {
1601            type = common.MESSAGE_SHOW_TYPE.THEME_IMAGE;
1602            item.content = this.getThemeContent();
1603        } else {
1604            type = this.getMsgShowTypePpt(item, slideString);
1605        }
1606        if (type == common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE || type == common.MESSAGE_SHOW_TYPE.PPT_IMAGE) {
1607            if (item.content == common.string.EMPTY_STR) {
1608                item.content = slideString;
1609            }
1610        }
1611        return type;
1612    }
1613
1614    getMsgShowTypePpt(item, slideString) {
1615        HiLog.i(TAG, "getMsgShowTypePpt, start")
1616        let type = common.MESSAGE_SHOW_TYPE.NORMAL;
1617        let hasSource = this.textareaDatasource.length > 0 ? true : false;
1618        let firstStr = hasSource ? this.textareaDatasource[0].textValue : common.string.EMPTY_STR;
1619        if (this.mmsEditList.length === 0) {
1620            type = common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE;
1621            if (this.messageType === common.MESSAGE_TYPE.THEME ||
1622            this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT) {
1623                item.content = this.getThemeContent();
1624            } else {
1625                item.content = (firstStr == common.string.EMPTY_STR) ? slideString : firstStr;
1626            }
1627        } else {
1628            type = this.getPPTType();
1629            this.getMsgShowTypeContent(item, firstStr, slideString);
1630        }
1631        return type;
1632    }
1633
1634    getPPTType() {
1635        HiLog.i(TAG, "getPPTType, start")
1636        let type = common.MESSAGE_SHOW_TYPE.NORMAL;
1637        if (this.messageType === common.MESSAGE_TYPE.NORMAL && this.mmsEditList.length > 0) {
1638            type = common.MESSAGE_SHOW_TYPE.PPT_IMAGE;
1639        } else {
1640            let firstMms = null;
1641            if (this.messageType === common.MESSAGE_TYPE.THEME && this.mmsEditList.length > 1) {
1642                firstMms = this.mmsEditList[0];
1643            } else if (this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT) {
1644                firstMms = this.textareaDatasource[1].mms;
1645            } else {
1646                firstMms = this.textareaDatasource[0].mms;
1647            }
1648            if (this.mmsEditList.length >= 1 && firstMms &&
1649            (firstMms.type === common.MSG_ITEM_TYPE.IMAGE || firstMms.type === common.MSG_ITEM_TYPE.VIDEO)) {
1650                type = common.MESSAGE_SHOW_TYPE.PPT_IMAGE;
1651            } else {
1652                type = common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE;
1653            }
1654        }
1655        return type;
1656    }
1657
1658    getMsgShowTypeContent(item, firstStr, slideString) {
1659        HiLog.i(TAG, "getMsgShowTypeContent, start")
1660        if (this.messageType === common.MESSAGE_TYPE.THEME_AND_PPT ||
1661        this.messageType === common.MESSAGE_TYPE.THEME) {
1662            item.content = this.getThemeContent();
1663        } else {
1664            let content = common.string.EMPTY_STR;
1665            if (this.messageType === common.MESSAGE_TYPE.NORMAL) {
1666                content = (this.textValue == common.string.EMPTY_STR) ? slideString : this.textValue;
1667            } else {
1668                content = (firstStr == common.string.EMPTY_STR) ? slideString : firstStr;
1669            }
1670            item.content = content;
1671        }
1672    }
1673
1674    getThemeContent() {
1675        HiLog.i(TAG, "getThemeContent, start")
1676        this.isEditMms = true;
1677        let content = '';
1678        let first = this.textareaDatasource[0].textValue;
1679        let text = this.textareaDatasource[1].textValue;
1680        if (first !== common.string.EMPTY_STR) {
1681            content = $r("app.string.msg_theme") + ": " + first;
1682        }
1683        if (text !== common.string.EMPTY_STR) {
1684            if (content === common.string.EMPTY_STR) {
1685                content = text;
1686            } else {
1687                content = content + "\n" + text;
1688            }
1689        }
1690        return content;
1691    }
1692
1693    sendMassMessage(actionData, item) {
1694        this.insertInitData(actionData, item, result => {
1695            // Processing the sent result
1696            if (this.threadId != result.rowId) {
1697                // When modifying the recipient information, click Send and delete the session before the modification.
1698                conversationListService.deleteMessageBySessionId([this.threadId]);
1699            }
1700            this.threadId = result.rowId;
1701            this.portraitColor = AvatarColor.background.Color[Math.abs(parseInt(this.threadId, 10)) % 6];
1702            item.groupId = result.groupId;
1703            item.id = result.initDatas[0].id;
1704            this.refresh = !this.refresh
1705            // Sending and processing the sending result
1706            this.dealSendResult(actionData, item, result.initDatas);
1707        });
1708    }
1709
1710    clearMsm() {
1711        if (this.isEditMms) {
1712            this.isEditMms = false;
1713        }
1714        // Deleting the preview image of an MMS message
1715        if (this.mmsEditList.length != 0) {
1716            for (let index in this.mmsEditList) {
1717                this.updatePreview(index);
1718            }
1719            this.mmsEditList = [];
1720        }
1721    }
1722
1723    resetMmsSource() {
1724        this.textareaDatasource = [];
1725        this.mmsEditList = [];
1726        this.pptTotalCount = 0;
1727        this.messageType = common.MESSAGE_TYPE.NORMAL;
1728        this.selectedTextareaIdx = -1;
1729    }
1730
1731    send() {
1732        HiLog.i(TAG, "send, start");
1733        // The Send button is dimmed and messages cannot be sent.
1734        if (!this.canSendMessage) {
1735            HiLog.w(TAG, "send, canSendMessage=false");
1736            return;
1737        }
1738        // Switching from the new state to the session state
1739        if (this.isNewMsg) {
1740            HiLog.i(TAG, "send, isNewMsg=true");
1741            this.newSend(() => {
1742                this.sendDataRefresh();
1743            });
1744        } else {
1745            this.sendDataRefresh();
1746        }
1747    }
1748
1749    sendDataRefresh() {
1750        this.isSendStatus = true;
1751        this.slotId = MmsPreferences.getInstance().getSendMessageSlotId();
1752        if (this.textValue != common.string.EMPTY_STR || this.mmsEditList.length != 0 ||
1753        this.textareaDatasource.length != 0) {
1754            this.initSendItem();
1755        }
1756        let actionData: LooseObject = {
1757            slotId: this.slotId,
1758            destinationHost: this.strContactsNumber,
1759            content: this.textValue,
1760            isEditMms: this.isEditMms
1761        };
1762        // Real SMS Sending
1763        this.sendInterval(actionData, this.mmsList);
1764        this.textValue = common.string.EMPTY_STR;
1765        this.canSendMessage = false;
1766        this.isShowFullScreen = false;
1767        this.clearMsm();
1768        this.resetMmsSource();
1769        this.setTabOperationStatus(false);
1770        this.distanceBottomFlag = false;
1771        this.receiveContactValue = common.string.EMPTY_STR;
1772        this.selectContacts = [];
1773        this.isNewMsg = false;
1774    }
1775
1776    isPhoneNumber(str) {
1777        // Determine whether the value is a number.
1778        let reg = /^\d{1,}$/;
1779        let pattern = new RegExp(reg);
1780        return pattern.test(str);
1781    }
1782
1783    newSend(callback) {
1784        // Check whether the entered content has a value.
1785        if (this.receiveContactValue != common.string.EMPTY_STR) {
1786            if (!this.isPhoneNumber(this.receiveContactValue)) {
1787                // Invalid Recipient
1788                this.showToast($r("app.string.invalid_receive", this.receiveContactValue))
1789                HiLog.w(TAG, "newSend, PhoneNumber is invalidate");
1790                return;
1791            }
1792        }
1793        if (this.selectContacts.length > 0 && this.receiveContactValue != common.string.EMPTY_STR) {
1794            let selectContact = {
1795                telephone: this.receiveContactValue,
1796                telephoneFormat: this.receiveContactValue,
1797                contactName: common.string.EMPTY_STR
1798            }
1799            let selectContacts = this.selectContacts;
1800            selectContacts.push(selectContact);
1801            this.initNewSelectContacts(selectContacts);
1802        } else if (this.selectContacts.length > 0) {
1803            this.initNewSelectContacts(this.selectContacts);
1804        } else if (this.receiveContactValue != common.string.EMPTY_STR) {
1805            this.contactsNum = 1;
1806            this.strContactsNumber = this.receiveContactValue;
1807            this.strContactsNumberFormat = this.receiveContactValue;
1808        } else {
1809            HiLog.w(TAG, "newSend, the contact condition is not met.")
1810            return;
1811        }
1812        this.isNewMsg = false;
1813        // To cancel sending, set this parameter to true.
1814        if (this.recallMessagesFlag) {
1815            this.isNewRecallMessagesFlag = true;
1816            this.commonCtrl.paramContact.isNewRecallMessagesFlag = true;
1817        }
1818        // When the new page is displayed in full screen mode, the following table data needs to be obtained.
1819        if (true) {
1820            this.queryOldMessageList(this.strContactsNumber, callback);
1821        }
1822    }
1823
1824    queryOldMessageList(telephone, callback) {
1825        HiLog.i(TAG, "queryOldMessageList, start");
1826        if (telephone == common.string.EMPTY_STR) {
1827            return;
1828        }
1829        let number = telephoneUtil.dealTelephoneSort(telephone);
1830        conversationListService.querySessionByTelephone(number, res => {
1831            HiLog.i(TAG, "queryOldMessageList, querySessionByTelephone res.response.id: " + res.response.id)
1832            if (res.code == common.int.SUCCESS && res.response.id > 0) {
1833                if (this.threadId != res.response.id) {
1834                    // When modifying the recipient information, click Send and delete the session before the
1835                    // modification.
1836                    conversationListService.deleteMessageBySessionId([this.threadId]);
1837                }
1838                this.threadId = res.response.id;
1839                this.portraitColor = AvatarColor.background.Color[Math.abs(parseInt(this.threadId, 10)) % 6];
1840                this.queryMessageDetail(telephone, res.response.id, callback);
1841                this.scroller.scrollToIndex(this.mmsList.length - 1)
1842            } else {
1843                callback();
1844            }
1845        });
1846    }
1847
1848    initNewSelectContacts(selectContacts) {
1849        HiLog.i(TAG, "initNewSelectContacts, start");
1850        let contactsNumber = common.string.EMPTY_STR;
1851        let contactsName = common.string.EMPTY_STR;
1852        let contactsNumberFormat = common.string.EMPTY_STR;
1853        let contacts = telephoneUtil.dealSelectContactsSort(selectContacts);
1854        let length = contacts.length;
1855        for (let index in contacts) {
1856            let item = contacts[index];
1857            contactsNumber = contactsNumber + item.telephone + common.string.COMMA;
1858            contactsNumberFormat = contactsNumberFormat + item.telephoneFormat + common.string.COMMA;
1859            if (item.contactName != common.string.EMPTY_STR) {
1860                contactsName += (item.contactName + common.string.COMMA);
1861            }
1862        }
1863        this.strContactsNumber = contactsNumber.substring(0, contactsNumber.length - 1);
1864        this.strContactsName = contactsName.substring(0, contactsName.length - 1);
1865        this.photoFirstNameDeal(this.strContactsName);
1866        this.strContactsNumberFormat = contactsNumberFormat.substring(0, contactsNumberFormat.length - 1);
1867        this.contactsNum = length;
1868    }
1869
1870    handleWithSend(actionData, item) {
1871        // Sending request processing
1872        let hosts: Array<string> = [];
1873        if (actionData.destinationHost.indexOf(",") == -1) {
1874            // single-shot
1875            hosts.push(actionData.destinationHost);
1876        } else {
1877            // Group Sending
1878            for (let host of actionData.destinationHost.split(",")) {
1879                hosts.push(telephoneUtil.formatTelephone(host));
1880            }
1881        }
1882        actionData.hosts = hosts;
1883        this.sendMassMessage(actionData, item);
1884    }
1885
1886    sendInterval(actionData, mmsList) {
1887        // Send Timer
1888        let item = mmsList[mmsList.length - 1];
1889        if (this.recallMessagesFlag) {
1890            item.intervalSendStatus = true;
1891            // Second countdown timer after the Send button is clicked
1892            item.sendIntervalId = setInterval(function () {
1893                item.cancelTimeCount--;
1894            }, 1000);
1895            // Transmit timer, which is sent after 6s.
1896            item.sendTimeoutId = setTimeout(() => {
1897                item.cancelTimeCount = 0;
1898                // Clear Timer
1899                clearTimeout(item.sendTimeoutId);
1900                clearInterval(item.sendIntervalId);
1901                this.handleWithSend(actionData, item);
1902            }, 6000);
1903        } else {
1904            this.handleWithSend(actionData, item);
1905        }
1906    }
1907
1908    changeValue(e) {
1909        this.textValue = e;
1910        if (e == null || e == common.string.EMPTY_STR) {
1911            if (this.mmsEditList.length != 0) {
1912                this.canSendMessage = true;
1913            } else {
1914                this.canSendMessage = false;
1915            }
1916            return;
1917        }
1918        // Whether to display full screen
1919        if (this.isEditMms) {
1920            this.isShowFullScreen = false;
1921        } else {
1922            this.isShowFullScreen = true;
1923        }
1924        if (this.isNewMsg) {
1925            if (this.receiveContactValue == '' && this.selectContacts.length == 0) {
1926                this.canSendMessage = false;
1927                return;
1928            }
1929        }
1930        if (this.textValue.length == 0) {
1931            this.canSendMessage = false;
1932            return;
1933        } else {
1934            this.canSendMessage = MmsPreferences.getInstance().haveSimCardReady() && !this.isFlightMode;
1935        }
1936        if (this.isNewMsg) {
1937            this.setCanSendMsgStatus();
1938        }
1939    }
1940
1941    setTabTitleText() {
1942        // TabTitleText selected globally
1943        if (this.tabIndex != 1) {
1944            // Non-picture page
1945            this.tabTitleText = this.tabTextList[this.tabIndex];
1946            return;
1947        }
1948        // On the image selection page, the number of selected images is displayed.
1949        let size = 0;
1950        for (let element of this.pictureListFromGallery) {
1951            if (element.checkedValue) {
1952                size++;
1953            }
1954        }
1955        this.tabTitleText = size == 0 ? $r("app.string.msg_unselected_tip") : $r("app.string.msg_selected_tip", {
1956            number: size
1957        });
1958    }
1959
1960    // Check whether the sending icon can be highlighted.
1961    judgeSendBtnCanClicked() {
1962        if (MmsPreferences.getInstance().haveSimCardReady() && (this.mmsEditList.length != 0 ||
1963        this.textValue != common.string.EMPTY_STR || this.textareaDatasource.length !== 0)) {
1964            if (this.isNewMsg) {
1965                if ((this.receiveContactValue !== '' && this.isPhoneNumber(this.receiveContactValue))
1966                || this.selectContacts.length !== 0) {
1967                    this.canSendMessage = true;
1968                }
1969            } else {
1970                this.canSendMessage = true;
1971            }
1972        }
1973    }
1974
1975    // Subscribing to Public Events
1976    subscribeDetail() {
1977        HiLog.i(TAG, "subscribeDetail, start");
1978        let events = [common.string.RECEIVE_TRANSMIT_EVENT]
1979        let commonEventSubscribeInfo = {
1980            events: events
1981        };
1982        // Creating Subscription Information
1983        commonEvent.createSubscriber(commonEventSubscribeInfo, this.createSubscriberCallBack.bind(this));
1984    }
1985
1986    createSubscriberCallBack(err, data) {
1987        this.commonEventData = data;
1988        // Received subscription
1989        commonEvent.subscribe(this.commonEventData, this.subscriberCallBack.bind(this));
1990    }
1991
1992    subscriberCallBack(err, data) {
1993        HiLog.i(TAG, "subscriberCallBack, start");
1994        globalThis.needToUpdate = true;
1995        // Receiving SMS Updates
1996        setTimeout(() => {
1997            this.queryMessageDetail(this.strContactsNumber, this.threadId, () => {
1998            });
1999            this.scroller.scrollToIndex(this.mmsList.length - 1);
2000            let valueBucket: LooseObject = {
2001                "unread_count": 0,
2002            };
2003            let actionData: LooseObject = {
2004                threadIds: [this.threadId],
2005                hasRead: 0,
2006                valueBucket: valueBucket
2007            };
2008            NotificationService.getInstance().cancelMessageNotify(actionData, res => {
2009                actionData.hasRead = 1;
2010                conversationListService.markAllAsRead(actionData);
2011            });
2012            let lastItem: LooseObject = this.mmsList[this.mmsList.length - 1];
2013            if (lastItem != null && lastItem.subId != null) {
2014                this.notifySlotIdChange(lastItem.subId);
2015            }
2016        }, 500);
2017    }
2018
2019    // Unsubscribe
2020    unSubscribeDetail() {
2021        if (this.commonEventData != null) {
2022            commonEvent.unsubscribe(this.commonEventData, () => {
2023                HiLog.i(TAG, "unSubscribeDetail, unsubscribe");
2024            });
2025        }
2026    }
2027
2028    notifySlotIdChange(slotId: number): void {
2029        if (MmsPreferences.getInstance().getSelectedSlotId() != slotId) {
2030            MmsPreferences.getInstance().setValueToMap(common.string.KEY_OF_SELECTED_SLOTID, slotId);
2031            HiLog.i(TAG, "notifySlotIdChange, emit slotId: " + slotId);
2032            emitter.emit(simCardService.SLOTID_CHANGE_EVENT, {
2033                data: {
2034                    "slotId": slotId
2035                }
2036            });
2037        }
2038    }
2039
2040    // In the selection mode, tap More. In the displayed menu, select
2041    moreSelected(e) {
2042        HiLog.i(TAG, "moreSelected, e: " + JSON.stringify(e))
2043        switch (e) {
2044            case "0":
2045            // duplicating
2046                this.copyText();
2047                break;
2048            case 1:
2049            // Share
2050                this.share();
2051                break;
2052            case 2:
2053            // Select Text
2054                this.gotoTextSelect(this.mmsIndex);
2055                break;
2056            case 3:
2057            // lock
2058                this.lock();
2059                break;
2060            case 4:
2061            // Show Details
2062                this.showDetails();
2063                break;
2064            case 5:
2065            // Unlock
2066                this.unlock();
2067                break;
2068            case 6:
2069            // View Reports
2070                this.showReport(this.mmsIndex);
2071                break;
2072            case 7:
2073            // Save Attachments
2074                this.saveImage();
2075                break;
2076            case 8:
2077            // Querying vCard Details
2078                this.showVcarDetail(this.mmsIndex);
2079                break;
2080            default:
2081                break;
2082        }
2083        // Exit the multi-selection mode.
2084        this.exitMultiselect();
2085    }
2086
2087    copyText() {
2088        commonPasteboard.setPasteboard(this.mmsList[this.mmsIndex].content);
2089    }
2090
2091    share() {
2092        for (let i = 0; i < this.mmsList.length; i++) {
2093            if (this.mmsList[i].isCbChecked == true) {
2094                var actionData: LooseObject = {};
2095                actionData.content = this.mmsList[i].content;
2096                conversationService.gotoShare(actionData, function (data) {
2097                    HiLog.i(TAG, "share, gotoShare callback");
2098                });
2099            }
2100        }
2101    }
2102
2103    gotoTextSelect(idx) {
2104        router.push({
2105            uri: "pages/text_select/text_select",
2106            params: this.mmsList[idx]
2107        })
2108    }
2109
2110    lock() {
2111        this.updateLock(true);
2112    }
2113
2114    unlock() {
2115        this.updateLock(false);
2116    }
2117
2118    updateLock(isLock) {
2119        // Select Content Lock
2120        let groupIds = [];
2121        for (let element of this.mmsList) {
2122            if (element.isCbChecked) {
2123                element.isLock = isLock;
2124                groupIds.push(element.groupId);
2125            }
2126        }
2127        let hasLock = isLock ? 1 : 0;
2128        let actionData: LooseObject = {};
2129        actionData = {
2130            groupIds: groupIds,
2131            hasLock: hasLock
2132        };
2133        let that = this;
2134        conversationService.updateLock(actionData, function (result) {
2135            if (result.code == common.int.SUCCESS) {
2136                // Multi-Select Status Off
2137                that.isSelectStatus = false;
2138                that.cancleCheckedAll();
2139                HiLog.i(TAG, "updateLock, Success");
2140            } else {
2141                HiLog.w(TAG, "updateLock, failed");
2142            }
2143        });
2144        // Update Lock Status
2145        this.updateSessionLock(isLock);
2146    }
2147
2148    showDetails() {
2149        for (let index = 0; index < this.mmsList.length; index++) {
2150            if (this.mmsList[index].isCbChecked == true) {
2151                var time = this.mmsList[index].timeMillisecond;
2152                var timeStash = this.getTime(time);
2153                this.mmsTime = timeStash + this.mmsList[index].time;
2154                if (this.mmsList[index].msgType == 0) {
2155                    this.isMmsType = $r("app.string.sms");
2156                } else {
2157                    this.isMmsType = $r("app.string.mms");
2158                }
2159
2160                if (this.mmsList[index].isReceive) {
2161                    this.isSendRecipient = true;
2162                } else {
2163                    this.isSendRecipient = false;
2164                }
2165            }
2166        }
2167        //    this.$element("mms_details_dialog").show();
2168    }
2169
2170    showReport(mmsIndex) {
2171        // View Reports
2172        let item = this.mmsList[mmsIndex];
2173        router.push({
2174            uri: "pages/queryreport/queryReport",
2175            params: {
2176                isMsm: item.isMsm,
2177                telephone: this.strContactsNumber,
2178                sendStatus: item.sendStatus,
2179                timeMillisecond: item.timeMillisecond
2180            },
2181        });
2182    }
2183
2184    saveImage() {
2185        var actionData: LooseObject = {};
2186        actionData.threadId = this.mmsList[this.mmsIndex]?.threadId;
2187        actionData.pduId = this.mmsList[this.mmsIndex]?.pduId;
2188        conversationService.saveImage(actionData, result => {
2189            this.showToast(result);
2190        });
2191    }
2192
2193    showVcarDetail(mmsIndex) {
2194
2195    }
2196
2197    exitMultiselect() {
2198        // Exit the multi-selection state.
2199        this.isSelectStatus = false;
2200        this.cancleCheckedAll();
2201    }
2202
2203    longPressMore(e) {
2204        switch (e) {
2205            case 0:
2206            // delete
2207                this.deleteDetail();
2208                break;
2209            case 1:
2210            // New Contact
2211                this.createNewContract(this.strContactsNumber);
2212                break;
2213            case 2:
2214            // Save to Existing Contacts
2215                this.existingContact(this.strContactsNumber);
2216                break;
2217            case 3:
2218            // Edit Before Call
2219                this.callEditor(this.strContactsNumber);
2220                break;
2221            case 4:
2222            // Add to Blocklist
2223                this.callEditor(this.strContactsNumber);
2224                break;
2225            case 5:
2226            // View Contacts
2227                this.titleBarAvatar();
2228                break;
2229            default:
2230                break;
2231        }
2232    }
2233
2234    // Delete
2235    deleteDetail() {
2236        if (this.mmsList.length == 1) {
2237            this.strMsgDeleteDialogTip = $r("app.string.msg_delete_dialog_con_tip3");
2238        } else {
2239            this.hasDetailDelete = false;
2240            this.isSelectStatus = true;
2241        }
2242    }
2243
2244    // New Contact
2245    createNewContract(number) {
2246        var actionData: LooseObject = {};
2247        actionData.phoneNumber = number;
2248        actionData.pageFlag = common.contractPage.PAGE_FLAG_SAVE_CONTACT;
2249        this.jumpToContract(actionData);
2250    }
2251
2252    // Edit Before Call
2253    callEditor(number) {
2254        var actionData: LooseObject = {};
2255        actionData.phoneNumber = number;
2256        actionData.pageFlag = common.contractPage.PAGE_FLAG_EDIT_BEFORE_CALLING;
2257        this.jumpToContract(actionData);
2258    }
2259
2260    // Save to Existing Contacts
2261    existingContact(number) {
2262        var actionData: LooseObject = {};
2263        actionData.phoneNumber = number;
2264        actionData.pageFlag = common.contractPage.PAGE_FLAG_SAVE_EXIST_CONTACT;
2265        this.jumpToContract(actionData);
2266    }
2267
2268    // Switching to the Contacts app
2269    jumpToContract(actionData) {
2270        let str = commonService.commonContractParam(actionData);
2271        globalThis.mmsContext.startAbility(str).then((data) => {
2272            HiLog.i(TAG, "jumpToContract, startAbility Success");
2273        }).catch((error) => {
2274            HiLog.e(TAG, "jumpToContract, failed. Cause: " + JSON.stringify(error.message));
2275        })
2276    }
2277
2278    // Tap a contact's avatar to go to the contact details page.
2279    titleBarAvatar() {
2280        var actionData = {
2281            phoneNumber: this.strContactsNumber,
2282            pageFlag: common.contractPage.PAGE_FLAG_CONTACT_DETAILS
2283        };
2284        this.jumpToContract(actionData);
2285    }
2286
2287    clickCall() {
2288        this.call(this.strContactsNumber);
2289    }
2290
2291    call(telephone) {
2292        // Calling
2293        callService.call(telephone, result => {
2294            if (result.code == common.int.SUCCESS) {
2295                HiLog.i(TAG, "call success");
2296            } else {
2297                HiLog.w(TAG, "call failed");
2298            }
2299        });
2300    }
2301
2302    getTime(nS) {
2303        var date = new Date(parseInt(nS));
2304        var year = date.getFullYear();
2305        var mon = date.getMonth() + 1;
2306        var day = date.getDate();
2307        return year; // + $r("app.string.year") + mon + $r("app.string.month") + day + $r("app.string.day");
2308    }
2309
2310    // Contact data returned on the new page
2311    setReceiveContactValue(receiverData) {
2312        let selectContacts = receiverData.selectContacts;
2313        let receiveContactValue = selectContacts.length > 0 ? common.string.EMPTY_STR : receiverData.contactValue;
2314        let hasBlur = receiverData.hasBlur;
2315        let telephone = common.string.EMPTY_STR;
2316        this.textValue = common.string.EMPTY_STR;
2317        this.setCanSendMessage(selectContacts, receiveContactValue)
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, null);
2366        }
2367    }
2368
2369    setCanSendMessage(selectContacts, receiveContactValue) {
2370        if (this.textValue != common.string.EMPTY_STR || this.isEditMms) {
2371            if (this.canSendMessage) {
2372                if (selectContacts.length == 0 && receiveContactValue == common.string.EMPTY_STR) {
2373                    this.canSendMessage = false;
2374                }
2375            } else if ((selectContacts.length != 0 || receiveContactValue != common.string.EMPTY_STR)
2376            && MmsPreferences.getInstance().haveSimCardReady()) {
2377                this.canSendMessage = true;
2378            }
2379        }
2380    }
2381}