1048147e0Sopenharmony_ci/** 2048147e0Sopenharmony_ci * Copyright (c) 2022 Huawei Device Co., Ltd. 3048147e0Sopenharmony_ci * Licensed under the Apache License, Version 2.0 (the "License"); 4048147e0Sopenharmony_ci * you may not use this file except in compliance with the License. 5048147e0Sopenharmony_ci * You may obtain a copy of the License at 6048147e0Sopenharmony_ci * 7048147e0Sopenharmony_ci * http://www.apache.org/licenses/LICENSE-2.0 8048147e0Sopenharmony_ci * 9048147e0Sopenharmony_ci * Unless required by applicable law or agreed to in writing, software 10048147e0Sopenharmony_ci * distributed under the License is distributed on an "AS IS" BASIS, 11048147e0Sopenharmony_ci * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12048147e0Sopenharmony_ci * See the License for the specific language governing permissions and 13048147e0Sopenharmony_ci * limitations under the License. 14048147e0Sopenharmony_ci */ 15048147e0Sopenharmony_ciimport commonEvent from '@ohos.commonEventManager'; 16048147e0Sopenharmony_ciimport router from '@system.router'; 17048147e0Sopenharmony_ci 18048147e0Sopenharmony_ciimport common from '../../data/commonData'; 19048147e0Sopenharmony_ciimport commonService from '../../service/CommonService'; 20048147e0Sopenharmony_ciimport dateUtil from '../../utils/DateUtil'; 21048147e0Sopenharmony_ciimport LooseObject from '../../data/LooseObject' 22048147e0Sopenharmony_ciimport ConversationListService from '../../service/ConversationListService'; 23048147e0Sopenharmony_ciimport ConversationService from '../../service/ConversationService'; 24048147e0Sopenharmony_ciimport HiLog from '../../utils/HiLog'; 25048147e0Sopenharmony_ciimport NotificationService from '../../service/NotificationService'; 26048147e0Sopenharmony_ciimport settingService from '../../service/SettingService'; 27048147e0Sopenharmony_ciimport ConversationListDataSource from '../../model/ConversationListDataSource' 28048147e0Sopenharmony_ci 29048147e0Sopenharmony_ciconst TAG = 'InfoMsgController' 30048147e0Sopenharmony_ci 31048147e0Sopenharmony_cilet sInfoMsgCtrl; 32048147e0Sopenharmony_ci 33048147e0Sopenharmony_ciexport default class InfoMsgController { 34048147e0Sopenharmony_ci delDialogShow: boolean = false; 35048147e0Sopenharmony_ci commonEventData: any = null; 36048147e0Sopenharmony_ci svgDelete: string = 'icon/ic_public_delete.svg' 37048147e0Sopenharmony_ci total: number = 0; 38048147e0Sopenharmony_ci strCheckBoxSelectTip: Resource; 39048147e0Sopenharmony_ci strMsgDeleteDialogTip: Resource; 40048147e0Sopenharmony_ci // Number of selected sessions 41048147e0Sopenharmony_ci conversationSelectedNumber: number = 0; 42048147e0Sopenharmony_ci // Indicates whether the multi-select state is selected. 43048147e0Sopenharmony_ci isMultipleSelectState: boolean = false; 44048147e0Sopenharmony_ci isSearchFocusable: boolean = false; 45048147e0Sopenharmony_ci // No The session list is selected. 46048147e0Sopenharmony_ci isConversationCheckAll: boolean = false; 47048147e0Sopenharmony_ci // Value entered in the search box on the information list page 48048147e0Sopenharmony_ci inputValueOfSearch: string = ''; 49048147e0Sopenharmony_ci // Indicates whether to lock. The default value is false. No. 50048147e0Sopenharmony_ci hasLockMsg: boolean = false; 51048147e0Sopenharmony_ci isSelectLockMsg: boolean = false; 52048147e0Sopenharmony_ci // List of search results 53048147e0Sopenharmony_ci searchResultList: LooseObject = { 54048147e0Sopenharmony_ci 'sessionList': [], 55048147e0Sopenharmony_ci 'contentList': [] 56048147e0Sopenharmony_ci }; 57048147e0Sopenharmony_ci // Search Results Queue 58048147e0Sopenharmony_ci searchResultListQueue: Array<any> = []; 59048147e0Sopenharmony_ci // Search Text Queue 60048147e0Sopenharmony_ci searchTextQueue: Array<any> = []; 61048147e0Sopenharmony_ci // Queue timer start flag bit 62048147e0Sopenharmony_ci setTimeOutQueueFlag: boolean = false; 63048147e0Sopenharmony_ci // Indicates whether to perform redirection to avoid repeated redirection. 64048147e0Sopenharmony_ci isJumping: boolean = false; 65048147e0Sopenharmony_ci // Indicates whether to display the search return button. By default, the button is not displayed. 66048147e0Sopenharmony_ci isShowSearchBack: boolean = false; 67048147e0Sopenharmony_ci // The transparent color of the mask is displayed during search. 68048147e0Sopenharmony_ci isSearchCoverage: boolean = false; 69048147e0Sopenharmony_ci // Display Query All Information 70048147e0Sopenharmony_ci isSearchStatus: boolean = true; 71048147e0Sopenharmony_ci // Whether to display session search 72048147e0Sopenharmony_ci isSearchConversation: boolean = false; 73048147e0Sopenharmony_ci // Show Spacer Lines 74048147e0Sopenharmony_ci isSearchInterval: boolean = false; 75048147e0Sopenharmony_ci // Display Single Information Search 76048147e0Sopenharmony_ci isSearchSms: boolean = false; 77048147e0Sopenharmony_ci // Display SMS messages when the search result is empty. 78048147e0Sopenharmony_ci isSearchNull: boolean = false; 79048147e0Sopenharmony_ci // Queue start flag bit 80048147e0Sopenharmony_ci queueFlag: boolean = false; 81048147e0Sopenharmony_ci // Show Search Status 82048147e0Sopenharmony_ci showSearchStatus: string = ''; 83048147e0Sopenharmony_ci conversationName: string = ''; 84048147e0Sopenharmony_ci // Number of unread notifications. 85048147e0Sopenharmony_ci unreadTotalOfInfo: number = 0; 86048147e0Sopenharmony_ci messageList: Array<any> = []; 87048147e0Sopenharmony_ci // Indicates whether to display the contact profile picture. 88048147e0Sopenharmony_ci isShowContactHeadIcon: boolean = true; 89048147e0Sopenharmony_ci // Number of search results 90048147e0Sopenharmony_ci countOfSearchResult: number = 0; 91048147e0Sopenharmony_ci // Display Navigation Bar 92048147e0Sopenharmony_ci isNavigationBar: boolean = false; 93048147e0Sopenharmony_ci // Search status. Click the search box to enter the search status. 94048147e0Sopenharmony_ci searchStatus: boolean = false; 95048147e0Sopenharmony_ci // Indicates whether to display the toolbar. The toolbar is not displayed in the search state. 96048147e0Sopenharmony_ci showToolBar: boolean = true; 97048147e0Sopenharmony_ci // Update the UI. 98048147e0Sopenharmony_ci flushTranslate: boolean = true; 99048147e0Sopenharmony_ci // Length of the operation button 100048147e0Sopenharmony_ci operateBtnW: number = 145; 101048147e0Sopenharmony_ci // Data index of the current touch 102048147e0Sopenharmony_ci itemTouchedIdx: number = -1; 103048147e0Sopenharmony_ci // List pagination, quantity 104048147e0Sopenharmony_ci limit: number = 1000; 105048147e0Sopenharmony_ci // List pagination, number of pages 106048147e0Sopenharmony_ci page: number = 0; 107048147e0Sopenharmony_ci // Total number of messages 108048147e0Sopenharmony_ci totalMessage: number = 0; 109048147e0Sopenharmony_ci // notification conversation list adapters 110048147e0Sopenharmony_ci conversationListDataSource: ConversationListDataSource = new ConversationListDataSource(); 111048147e0Sopenharmony_ci 112048147e0Sopenharmony_ci static getInstance() { 113048147e0Sopenharmony_ci if (sInfoMsgCtrl == null) { 114048147e0Sopenharmony_ci sInfoMsgCtrl = new InfoMsgController(); 115048147e0Sopenharmony_ci AppStorage.SetAndLink('InfoMsgController', sInfoMsgCtrl); 116048147e0Sopenharmony_ci } 117048147e0Sopenharmony_ci return sInfoMsgCtrl; 118048147e0Sopenharmony_ci } 119048147e0Sopenharmony_ci 120048147e0Sopenharmony_ci onInit() { 121048147e0Sopenharmony_ci HiLog.i(TAG, 'onInit'); 122048147e0Sopenharmony_ci this.strCheckBoxSelectTip = $r('app.string.msg_select_all'); 123048147e0Sopenharmony_ci this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_tip2', this.conversationSelectedNumber); 124048147e0Sopenharmony_ci } 125048147e0Sopenharmony_ci 126048147e0Sopenharmony_ci onShow() { 127048147e0Sopenharmony_ci HiLog.i(TAG, 'onShow'); 128048147e0Sopenharmony_ci this.isJumping = false; 129048147e0Sopenharmony_ci this.getSettingFlagForConvListPage(); 130048147e0Sopenharmony_ci this.page = 0; 131048147e0Sopenharmony_ci this.requestItem(); 132048147e0Sopenharmony_ci this.subscribeInfo(); 133048147e0Sopenharmony_ci NotificationService.getInstance().updateBadgeNumber(); 134048147e0Sopenharmony_ci } 135048147e0Sopenharmony_ci 136048147e0Sopenharmony_ci onHide() { 137048147e0Sopenharmony_ci HiLog.i(TAG, 'onHide'); 138048147e0Sopenharmony_ci this.unsubscribeInfo(); 139048147e0Sopenharmony_ci } 140048147e0Sopenharmony_ci // Querying List Data 141048147e0Sopenharmony_ci queryAllMessages() { 142048147e0Sopenharmony_ci let actionData: LooseObject = {}; 143048147e0Sopenharmony_ci actionData.smsType = common.sms_type.NOTICE; 144048147e0Sopenharmony_ci actionData.page = this.page; 145048147e0Sopenharmony_ci actionData.limit = this.limit; 146048147e0Sopenharmony_ci actionData.orderByTimeDesc = true; 147048147e0Sopenharmony_ci ConversationListService.getInstance().querySessionList(actionData, result => { 148048147e0Sopenharmony_ci if (result.code == common.int.SUCCESS) { 149048147e0Sopenharmony_ci HiLog.i(TAG, 'queryAllMessages, Success'); 150048147e0Sopenharmony_ci let res = this.buildSessionList(result); 151048147e0Sopenharmony_ci this.messageList = res; 152048147e0Sopenharmony_ci this.conversationListDataSource.refresh(this.messageList); 153048147e0Sopenharmony_ci this.totalMessage = result.total; 154048147e0Sopenharmony_ci this.total = this.messageList.length; 155048147e0Sopenharmony_ci if (this.totalMessage === this.total) { 156048147e0Sopenharmony_ci this.countUnread(); 157048147e0Sopenharmony_ci } 158048147e0Sopenharmony_ci } else { 159048147e0Sopenharmony_ci HiLog.w(TAG, 'queryAllMessages, failed'); 160048147e0Sopenharmony_ci } 161048147e0Sopenharmony_ci }, null); 162048147e0Sopenharmony_ci } 163048147e0Sopenharmony_ci 164048147e0Sopenharmony_ci dealMmsListContent(element) { 165048147e0Sopenharmony_ci if (element.hasMms && element.hasAttachment) { 166048147e0Sopenharmony_ci if (element.content == common.string.EMPTY_STR) { 167048147e0Sopenharmony_ci element.content = $r('app.string.attachment_no_subject'); 168048147e0Sopenharmony_ci } else { 169048147e0Sopenharmony_ci element.content = $r('app.string.attachment', element.content); 170048147e0Sopenharmony_ci } 171048147e0Sopenharmony_ci } 172048147e0Sopenharmony_ci if (element.hasMms && !element.hasAttachment && element.content == common.string.EMPTY_STR) { 173048147e0Sopenharmony_ci element.content = $r('app.string.no_subject'); 174048147e0Sopenharmony_ci } 175048147e0Sopenharmony_ci } 176048147e0Sopenharmony_ci 177048147e0Sopenharmony_ci buildSessionList(result) { 178048147e0Sopenharmony_ci let res = []; 179048147e0Sopenharmony_ci result.response.forEach(item => { 180048147e0Sopenharmony_ci // Inherit selected items 181048147e0Sopenharmony_ci this.messageList.some(oldItem => { 182048147e0Sopenharmony_ci if (item.threadId === oldItem.threadId) { 183048147e0Sopenharmony_ci item.isCbChecked = oldItem.isCbChecked; 184048147e0Sopenharmony_ci return true; 185048147e0Sopenharmony_ci } 186048147e0Sopenharmony_ci }); 187048147e0Sopenharmony_ci let obj: LooseObject = {}; 188048147e0Sopenharmony_ci obj = item; 189048147e0Sopenharmony_ci obj.itemLeft = 0; 190048147e0Sopenharmony_ci obj.isDelShow = false; 191048147e0Sopenharmony_ci dateUtil.convertDateFormatForItem(item, false); 192048147e0Sopenharmony_ci this.dealMmsListContent(obj); 193048147e0Sopenharmony_ci res.push(obj); 194048147e0Sopenharmony_ci }); 195048147e0Sopenharmony_ci return res; 196048147e0Sopenharmony_ci } 197048147e0Sopenharmony_ci 198048147e0Sopenharmony_ci requestItem() { 199048147e0Sopenharmony_ci let count = this.page * this.limit; 200048147e0Sopenharmony_ci if (this.page === 0) { 201048147e0Sopenharmony_ci this.page++; 202048147e0Sopenharmony_ci this.queryAllMessages(); 203048147e0Sopenharmony_ci } else if (count < this.totalMessage && this.messageList.length > (this.page - 1) * this.limit) { 204048147e0Sopenharmony_ci // The restriction on messageList is to prevent multiple requests from being refreshed during initialization 205048147e0Sopenharmony_ci this.page++; 206048147e0Sopenharmony_ci this.queryAllMessages(); 207048147e0Sopenharmony_ci } 208048147e0Sopenharmony_ci } 209048147e0Sopenharmony_ci // Return to the information list page. 210048147e0Sopenharmony_ci back() { 211048147e0Sopenharmony_ci router.back(); 212048147e0Sopenharmony_ci } 213048147e0Sopenharmony_ci // Tap More at the bottom of the screen 214048147e0Sopenharmony_ci clickMore() { 215048147e0Sopenharmony_ci // this.$element('moreDialog').show(); 216048147e0Sopenharmony_ci } 217048147e0Sopenharmony_ci // Delete a single piece of information from a notification. 218048147e0Sopenharmony_ci clickToDelete() { 219048147e0Sopenharmony_ci 220048147e0Sopenharmony_ci } 221048147e0Sopenharmony_ci 222048147e0Sopenharmony_ci clickSearchBack() { 223048147e0Sopenharmony_ci // Click the search return button. 224048147e0Sopenharmony_ci this.backSearch(); 225048147e0Sopenharmony_ci } 226048147e0Sopenharmony_ci 227048147e0Sopenharmony_ci backSearch() { 228048147e0Sopenharmony_ci this.isShowSearchBack = false; 229048147e0Sopenharmony_ci this.isSearchCoverage = false; 230048147e0Sopenharmony_ci this.isSearchFocusable = false; 231048147e0Sopenharmony_ci this.inputValueOfSearch = common.string.EMPTY_STR; 232048147e0Sopenharmony_ci this.isSearchStatus = true; 233048147e0Sopenharmony_ci this.isSearchNull = false; 234048147e0Sopenharmony_ci this.searchStatus = false; 235048147e0Sopenharmony_ci this.showToolBar = true; 236048147e0Sopenharmony_ci } 237048147e0Sopenharmony_ci 238048147e0Sopenharmony_ci conversationLongPress(index) { 239048147e0Sopenharmony_ci // Check whether the left slide button exists. If yes, the button cannot be clicked. 240048147e0Sopenharmony_ci if (this.itemTouchedIdx >= 0 && this.messageList[this.itemTouchedIdx].isDelShow) { 241048147e0Sopenharmony_ci return; 242048147e0Sopenharmony_ci } 243048147e0Sopenharmony_ci // Touch and hold a list to display the selection and deletion functions. 244048147e0Sopenharmony_ci this.showToolBar = false; 245048147e0Sopenharmony_ci HiLog.i(TAG, 'conversationLongPress, index: ' + index); 246048147e0Sopenharmony_ci if (this.isMultipleSelectState) { 247048147e0Sopenharmony_ci this.messageList[index].isCbChecked = !this.messageList[index].isCbChecked; 248048147e0Sopenharmony_ci } else { 249048147e0Sopenharmony_ci this.messageList[index].isCbChecked = true; 250048147e0Sopenharmony_ci this.isMultipleSelectState = true; 251048147e0Sopenharmony_ci } 252048147e0Sopenharmony_ci this.setConversationCheckAll(common.int.CHECKBOX_SELECT_UNKNOWN); 253048147e0Sopenharmony_ci } 254048147e0Sopenharmony_ci // Check whether all items are selected. 255048147e0Sopenharmony_ci setConversationCheckAll(type) { 256048147e0Sopenharmony_ci if (!this.isMultipleSelectState) { 257048147e0Sopenharmony_ci return; 258048147e0Sopenharmony_ci } 259048147e0Sopenharmony_ci if (type == common.int.CHECKBOX_SELECT_NONE) { 260048147e0Sopenharmony_ci this.conversationSelectedNumber = common.int.MESSAGE_CODE_ZERO; 261048147e0Sopenharmony_ci this.isConversationCheckAll = false; 262048147e0Sopenharmony_ci } else if (type == common.int.CHECKBOX_SELECT_ALL) { 263048147e0Sopenharmony_ci this.conversationSelectedNumber = this.messageList.length; 264048147e0Sopenharmony_ci this.isConversationCheckAll = true; 265048147e0Sopenharmony_ci } else { 266048147e0Sopenharmony_ci // The default value is CHECKBOX_SELECT_UNKNOWN. Check whether there is any unselected item. 267048147e0Sopenharmony_ci this.isConversationCheckAll = true; 268048147e0Sopenharmony_ci this.conversationSelectedNumber = common.int.MESSAGE_CODE_ZERO; 269048147e0Sopenharmony_ci this.messageList.forEach((item, index, array) => { 270048147e0Sopenharmony_ci if (item.isCbChecked) { 271048147e0Sopenharmony_ci this.conversationSelectedNumber++; 272048147e0Sopenharmony_ci } else if (this.isConversationCheckAll) { 273048147e0Sopenharmony_ci this.isConversationCheckAll = false; 274048147e0Sopenharmony_ci } 275048147e0Sopenharmony_ci }); 276048147e0Sopenharmony_ci } 277048147e0Sopenharmony_ci this.conversationListDataSource.refresh(this.messageList); 278048147e0Sopenharmony_ci if (!this.isConversationCheckAll) { 279048147e0Sopenharmony_ci // Non-Select All Status 280048147e0Sopenharmony_ci this.strCheckBoxSelectTip = $r('app.string.msg_select_all'); 281048147e0Sopenharmony_ci } else { 282048147e0Sopenharmony_ci // Select All Status 283048147e0Sopenharmony_ci this.strCheckBoxSelectTip = $r('app.string.msg_deselect_all'); 284048147e0Sopenharmony_ci } 285048147e0Sopenharmony_ci } 286048147e0Sopenharmony_ci // The SM details page is displayed. 287048147e0Sopenharmony_ci clickInfoToConversation(index) { 288048147e0Sopenharmony_ci if (this.resetTouch()) { 289048147e0Sopenharmony_ci return; 290048147e0Sopenharmony_ci } 291048147e0Sopenharmony_ci // If multiple options are selected, the system responds to CheckBox. 292048147e0Sopenharmony_ci if (this.isMultipleSelectState) { 293048147e0Sopenharmony_ci this.messageList[index].isCbChecked = !this.messageList[index].isCbChecked; 294048147e0Sopenharmony_ci this.setConversationCheckAll(common.int.CHECKBOX_SELECT_UNKNOWN); 295048147e0Sopenharmony_ci return; 296048147e0Sopenharmony_ci } 297048147e0Sopenharmony_ci if (this.isJumping) { 298048147e0Sopenharmony_ci return; 299048147e0Sopenharmony_ci } 300048147e0Sopenharmony_ci this.isJumping = true; 301048147e0Sopenharmony_ci // If the contact has unread information, a message needs to be sent to the backend PA to mark all information 302048147e0Sopenharmony_ci // of the contact as read. 303048147e0Sopenharmony_ci if (this.messageList[index]?.countOfUnread > common.int.MESSAGE_CODE_ZERO) { 304048147e0Sopenharmony_ci this.markAllAsReadByIndex(index); 305048147e0Sopenharmony_ci } 306048147e0Sopenharmony_ci this.jumpToConversationPage(this.messageList[index]); 307048147e0Sopenharmony_ci } 308048147e0Sopenharmony_ci // The session details page is displayed. 309048147e0Sopenharmony_ci jumpToConversationPage(item) { 310048147e0Sopenharmony_ci router.push({ 311048147e0Sopenharmony_ci uri: 'pages/conversation/conversation', 312048147e0Sopenharmony_ci params: { 313048147e0Sopenharmony_ci strContactsNumber: item?.telephone, 314048147e0Sopenharmony_ci strContactsNumberFormat: item?.telephoneFormat, 315048147e0Sopenharmony_ci strContactsName: item?.name, 316048147e0Sopenharmony_ci contactsNum: item?.contactsNum, 317048147e0Sopenharmony_ci threadId: item?.threadId, 318048147e0Sopenharmony_ci isDraft: item?.isDraft, 319048147e0Sopenharmony_ci draftContent: item?.content, 320048147e0Sopenharmony_ci searchContent: this.inputValueOfSearch 321048147e0Sopenharmony_ci } 322048147e0Sopenharmony_ci }); 323048147e0Sopenharmony_ci } 324048147e0Sopenharmony_ci // Searching for a session avatar 325048147e0Sopenharmony_ci searchConversationHeadClick(index) { 326048147e0Sopenharmony_ci this.headClickedListener(this.searchResultList.sessionList[index]); 327048147e0Sopenharmony_ci } 328048147e0Sopenharmony_ci 329048147e0Sopenharmony_ci headClickedListener(item) { 330048147e0Sopenharmony_ci // Tap the avatar to go to the contact details page or recipient list page. 331048147e0Sopenharmony_ci if (this.isJumping) { 332048147e0Sopenharmony_ci return; 333048147e0Sopenharmony_ci } 334048147e0Sopenharmony_ci if (item.isFavorite != null && item.isFavorite) { 335048147e0Sopenharmony_ci return; 336048147e0Sopenharmony_ci } 337048147e0Sopenharmony_ci var telephone = item.telephone; 338048147e0Sopenharmony_ci var contactsNum = item.contactsNum; 339048147e0Sopenharmony_ci this.isJumping = true; 340048147e0Sopenharmony_ci if (contactsNum == common.int.MESSAGE_CODE_ONE) { 341048147e0Sopenharmony_ci var actionData: LooseObject = {}; 342048147e0Sopenharmony_ci actionData.phoneNumber = telephone; 343048147e0Sopenharmony_ci actionData.pageFlag = common.contactPage.PAGE_FLAG_CONTACT_DETAILS; 344048147e0Sopenharmony_ci this.jumpToContact(actionData); 345048147e0Sopenharmony_ci } else { 346048147e0Sopenharmony_ci let threadId = item.threadId; 347048147e0Sopenharmony_ci let contactsNum = item.contactsNum; 348048147e0Sopenharmony_ci this.jumpToGroupDetail(threadId, contactsNum); 349048147e0Sopenharmony_ci } 350048147e0Sopenharmony_ci } 351048147e0Sopenharmony_ci // Go to the multi-faceted portrait list page. 352048147e0Sopenharmony_ci jumpToGroupDetail(threadId, contactsNum) { 353048147e0Sopenharmony_ci let actionData = { 354048147e0Sopenharmony_ci uri: 'pages/group_detail/group_detail', 355048147e0Sopenharmony_ci params: { 356048147e0Sopenharmony_ci threadId: threadId, 357048147e0Sopenharmony_ci contactsNum: contactsNum 358048147e0Sopenharmony_ci } 359048147e0Sopenharmony_ci }; 360048147e0Sopenharmony_ci this.isJumping = false; 361048147e0Sopenharmony_ci router.push(actionData); 362048147e0Sopenharmony_ci } 363048147e0Sopenharmony_ci // Go to session details. 364048147e0Sopenharmony_ci searchConversationClick(index) { 365048147e0Sopenharmony_ci this.searchMmsClicked(this.searchResultList.sessionList[index]); 366048147e0Sopenharmony_ci } 367048147e0Sopenharmony_ci // Go to SMS details. 368048147e0Sopenharmony_ci searchMmsClicked(item) { 369048147e0Sopenharmony_ci if (item.isFavorite) { 370048147e0Sopenharmony_ci router.push({ 371048147e0Sopenharmony_ci uri: 'pages/my_star/my_star', 372048147e0Sopenharmony_ci params: { 373048147e0Sopenharmony_ci searchContent: this.inputValueOfSearch 374048147e0Sopenharmony_ci } 375048147e0Sopenharmony_ci }); 376048147e0Sopenharmony_ci } else { 377048147e0Sopenharmony_ci this.jumpToConversationPage(item); 378048147e0Sopenharmony_ci } 379048147e0Sopenharmony_ci } 380048147e0Sopenharmony_ci // Clicking a profile picture to jump to the contact details page or the list page of multiple recipients 381048147e0Sopenharmony_ci searchSmsHeadClick(index) { 382048147e0Sopenharmony_ci this.headClickedListener(this.searchResultList.contentList[index]); 383048147e0Sopenharmony_ci } 384048147e0Sopenharmony_ci // The session details page is displayed. 385048147e0Sopenharmony_ci searchSmsClick(index) { 386048147e0Sopenharmony_ci this.searchMmsClicked(this.searchResultList.contentList[index]); 387048147e0Sopenharmony_ci } 388048147e0Sopenharmony_ci // Slide your finger to exit the search mode. 389048147e0Sopenharmony_ci searchCoverageClick() { 390048147e0Sopenharmony_ci this.backSearch(); 391048147e0Sopenharmony_ci } 392048147e0Sopenharmony_ci // Counting the number of unread messages 393048147e0Sopenharmony_ci countUnread() { 394048147e0Sopenharmony_ci let that = this; 395048147e0Sopenharmony_ci ConversationListService.getInstance().statisticalData(result => { 396048147e0Sopenharmony_ci if (result.code == common.int.SUCCESS) { 397048147e0Sopenharmony_ci // Unreading of notification messages 398048147e0Sopenharmony_ci that.unreadTotalOfInfo = result.response.unreadTotalOfInfo; 399048147e0Sopenharmony_ci HiLog.i(TAG, 'countUnread = ' + that.unreadTotalOfInfo); 400048147e0Sopenharmony_ci NotificationService.getInstance().setBadgeNumber(Number(result.response.totalListCount)); 401048147e0Sopenharmony_ci } else { 402048147e0Sopenharmony_ci HiLog.w(TAG, 'countUnread, statisticalData failed'); 403048147e0Sopenharmony_ci } 404048147e0Sopenharmony_ci }, null); 405048147e0Sopenharmony_ci } 406048147e0Sopenharmony_ci // Mark all unread notifications as read. 407048147e0Sopenharmony_ci clickToMarkAllAsReadForInfo() { 408048147e0Sopenharmony_ci let threadIds: Array<number> = []; 409048147e0Sopenharmony_ci for (let msg of this.messageList) { 410048147e0Sopenharmony_ci msg.countOfUnread = common.int.MESSAGE_CODE_ZERO; 411048147e0Sopenharmony_ci threadIds.push(msg.threadId); 412048147e0Sopenharmony_ci } 413048147e0Sopenharmony_ci let actionData: LooseObject = {}; 414048147e0Sopenharmony_ci actionData.threadIds = threadIds; 415048147e0Sopenharmony_ci actionData.hasRead = common.is_read.UN_READ; 416048147e0Sopenharmony_ci actionData.smsType = common.sms_type.NOTICE; 417048147e0Sopenharmony_ci NotificationService.getInstance().cancelMessageNotify(actionData); 418048147e0Sopenharmony_ci ConversationListService.getInstance().markAllToRead(actionData); 419048147e0Sopenharmony_ci NotificationService.getInstance().updateBadgeNumber(); 420048147e0Sopenharmony_ci this.unreadTotalOfInfo = 0; 421048147e0Sopenharmony_ci } 422048147e0Sopenharmony_ci 423048147e0Sopenharmony_ci markAllAsReadByIndex(index) { 424048147e0Sopenharmony_ci let item: LooseObject = this.messageList[index]; 425048147e0Sopenharmony_ci let threadId: number = item.threadId; 426048147e0Sopenharmony_ci let actionData: LooseObject = {}; 427048147e0Sopenharmony_ci actionData.threadId = threadId; 428048147e0Sopenharmony_ci actionData.hasRead = common.is_read.UN_READ; 429048147e0Sopenharmony_ci NotificationService.getInstance().cancelMessageNotify(actionData); 430048147e0Sopenharmony_ci NotificationService.getInstance().updateBadgeNumber(); 431048147e0Sopenharmony_ci ConversationListService.getInstance().markAllToRead(actionData); 432048147e0Sopenharmony_ci let tempMsgList: Array<LooseObject> = this.messageList; 433048147e0Sopenharmony_ci for (let msg of tempMsgList) { 434048147e0Sopenharmony_ci if (threadId == msg.threadId) { 435048147e0Sopenharmony_ci // Controls the display of unread icons in the list 436048147e0Sopenharmony_ci msg.countOfUnread = common.int.MESSAGE_CODE_ZERO; 437048147e0Sopenharmony_ci } 438048147e0Sopenharmony_ci } 439048147e0Sopenharmony_ci this.messageList = tempMsgList; 440048147e0Sopenharmony_ci this.conversationListDataSource.refresh(this.messageList); 441048147e0Sopenharmony_ci this.unreadTotalOfInfo = this.unreadTotalOfInfo - 1; 442048147e0Sopenharmony_ci 443048147e0Sopenharmony_ci this.setListItemTransX(0); 444048147e0Sopenharmony_ci item.isDelShow = false; 445048147e0Sopenharmony_ci } 446048147e0Sopenharmony_ci 447048147e0Sopenharmony_ci selectInMoreMenu(menuId: number) { 448048147e0Sopenharmony_ci if (menuId == 1) { 449048147e0Sopenharmony_ci // Delete 450048147e0Sopenharmony_ci this.isMultipleSelectState = true; 451048147e0Sopenharmony_ci this.showToolBar = false; 452048147e0Sopenharmony_ci this.setConversationCheckAll(common.int.CHECKBOX_SELECT_UNKNOWN); 453048147e0Sopenharmony_ci } else { 454048147e0Sopenharmony_ci // The harassment blocking page is displayed, which is in the Phone Manager app. 455048147e0Sopenharmony_ci } 456048147e0Sopenharmony_ci } 457048147e0Sopenharmony_ci // Button Delete 458048147e0Sopenharmony_ci clickConversationDelete() { 459048147e0Sopenharmony_ci if (this.conversationSelectedNumber == common.int.MESSAGE_CODE_ZERO) { 460048147e0Sopenharmony_ci return; 461048147e0Sopenharmony_ci } 462048147e0Sopenharmony_ci if (this.conversationSelectedNumber == common.int.MESSAGE_CODE_ONE) { 463048147e0Sopenharmony_ci this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_tip1'); 464048147e0Sopenharmony_ci } else if (this.conversationSelectedNumber == this.messageList.length) { 465048147e0Sopenharmony_ci this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_tip3'); 466048147e0Sopenharmony_ci } else { 467048147e0Sopenharmony_ci this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_tip2', this.conversationSelectedNumber); 468048147e0Sopenharmony_ci } 469048147e0Sopenharmony_ci this.hasLockMsg = (this.messageList.some((element, index) => element.isCbChecked && element.isLock)); 470048147e0Sopenharmony_ci } 471048147e0Sopenharmony_ci 472048147e0Sopenharmony_ci checkSelectedNumberIsEmpty() { 473048147e0Sopenharmony_ci return this.conversationSelectedNumber == common.int.MESSAGE_CODE_ZERO 474048147e0Sopenharmony_ci } 475048147e0Sopenharmony_ci // Cancel Ejection 476048147e0Sopenharmony_ci deleteDialogCancel() { 477048147e0Sopenharmony_ci if (this.isSelectLockMsg) { 478048147e0Sopenharmony_ci this.isSelectLockMsg = false; 479048147e0Sopenharmony_ci } 480048147e0Sopenharmony_ci } 481048147e0Sopenharmony_ci 482048147e0Sopenharmony_ci setSelectLock() { 483048147e0Sopenharmony_ci this.isSelectLockMsg = !this.isSelectLockMsg; 484048147e0Sopenharmony_ci } 485048147e0Sopenharmony_ci // Delete the checkbox lockout event. 486048147e0Sopenharmony_ci setSelectLockChange(event) { 487048147e0Sopenharmony_ci this.isSelectLockMsg = event.checked; 488048147e0Sopenharmony_ci } 489048147e0Sopenharmony_ci 490048147e0Sopenharmony_ci deleteDialogConfirm() { 491048147e0Sopenharmony_ci this.setDelShow(); 492048147e0Sopenharmony_ci let mmsList: Array<LooseObject> = []; 493048147e0Sopenharmony_ci let threadIds: Array<number> = []; 494048147e0Sopenharmony_ci for (let element of this.messageList) { 495048147e0Sopenharmony_ci if (element.isCbChecked) { 496048147e0Sopenharmony_ci threadIds.push(element.threadId); 497048147e0Sopenharmony_ci } else { 498048147e0Sopenharmony_ci mmsList.push(element); 499048147e0Sopenharmony_ci } 500048147e0Sopenharmony_ci } 501048147e0Sopenharmony_ci this.isMultipleSelectState = false; 502048147e0Sopenharmony_ci this.showToolBar = true; 503048147e0Sopenharmony_ci this.isSelectLockMsg = false; 504048147e0Sopenharmony_ci this.messageList = mmsList; 505048147e0Sopenharmony_ci this.conversationListDataSource.refresh(this.messageList); 506048147e0Sopenharmony_ci this.total = mmsList.length; 507048147e0Sopenharmony_ci if (this.total == 0) { 508048147e0Sopenharmony_ci router.back(); 509048147e0Sopenharmony_ci } 510048147e0Sopenharmony_ci let actionData: LooseObject = {}; 511048147e0Sopenharmony_ci actionData.threadIds = threadIds; 512048147e0Sopenharmony_ci actionData.hasRead = common.is_read.UN_READ; 513048147e0Sopenharmony_ci NotificationService.getInstance().cancelMessageNotify(actionData); 514048147e0Sopenharmony_ci NotificationService.getInstance().updateBadgeNumber(); 515048147e0Sopenharmony_ci actionData.hasRead = null; 516048147e0Sopenharmony_ci ConversationListService.getInstance().deleteMessageById(actionData, null, null); 517048147e0Sopenharmony_ci } 518048147e0Sopenharmony_ci 519048147e0Sopenharmony_ci setDelShow() { 520048147e0Sopenharmony_ci if (this.itemTouchedIdx >= 0) { 521048147e0Sopenharmony_ci let item = this.messageList[this.itemTouchedIdx]; 522048147e0Sopenharmony_ci this.setListItemTransX(0); 523048147e0Sopenharmony_ci item.isDelShow = false; 524048147e0Sopenharmony_ci } 525048147e0Sopenharmony_ci }; 526048147e0Sopenharmony_ci 527048147e0Sopenharmony_ci // Select All/Deselect All 528048147e0Sopenharmony_ci clickConversationCheckAll() { 529048147e0Sopenharmony_ci if (this.isConversationCheckAll) { 530048147e0Sopenharmony_ci // Select All --> Deselect All 531048147e0Sopenharmony_ci for (let item of this.messageList) { 532048147e0Sopenharmony_ci item.isCbChecked = false; 533048147e0Sopenharmony_ci } 534048147e0Sopenharmony_ci this.setConversationCheckAll(common.int.CHECKBOX_SELECT_NONE); 535048147e0Sopenharmony_ci } else { 536048147e0Sopenharmony_ci // Not Select All --> Select All 537048147e0Sopenharmony_ci for (let item of this.messageList) { 538048147e0Sopenharmony_ci item.isCbChecked = true; 539048147e0Sopenharmony_ci } 540048147e0Sopenharmony_ci this.setConversationCheckAll(common.int.CHECKBOX_SELECT_ALL); 541048147e0Sopenharmony_ci } 542048147e0Sopenharmony_ci } 543048147e0Sopenharmony_ci 544048147e0Sopenharmony_ci onBackPress() { 545048147e0Sopenharmony_ci // Key returned by the system. The value true indicates interception. 546048147e0Sopenharmony_ci if (this.isMultipleSelectState) { 547048147e0Sopenharmony_ci for (let element of this.messageList) { 548048147e0Sopenharmony_ci element.isCbChecked = false; 549048147e0Sopenharmony_ci } 550048147e0Sopenharmony_ci this.isMultipleSelectState = false; 551048147e0Sopenharmony_ci this.showToolBar = true; 552048147e0Sopenharmony_ci return true; 553048147e0Sopenharmony_ci } 554048147e0Sopenharmony_ci return false; 555048147e0Sopenharmony_ci } 556048147e0Sopenharmony_ci // Tap the avatar to go to the contact details page or recipient list page. 557048147e0Sopenharmony_ci clickToGroupDetail(index) { 558048147e0Sopenharmony_ci if (this.isJumping) { 559048147e0Sopenharmony_ci return; 560048147e0Sopenharmony_ci } 561048147e0Sopenharmony_ci this.isJumping = true; 562048147e0Sopenharmony_ci // Determine whether to redirect to the contact details page or to the list page of multiple recipients. 563048147e0Sopenharmony_ci var contactsNum = this.messageList[index]?.contactsNum; 564048147e0Sopenharmony_ci var telephone = this.messageList[index]?.telephone; 565048147e0Sopenharmony_ci if (contactsNum == common.int.MESSAGE_CODE_ONE) { 566048147e0Sopenharmony_ci var actionData = { 567048147e0Sopenharmony_ci phoneNumber: telephone, 568048147e0Sopenharmony_ci pageFlag: common.contactPage.PAGE_FLAG_CONTACT_DETAILS 569048147e0Sopenharmony_ci }; 570048147e0Sopenharmony_ci this.jumpToContact(actionData); 571048147e0Sopenharmony_ci } else { 572048147e0Sopenharmony_ci let threadId = this.messageList[index]?.threadId; 573048147e0Sopenharmony_ci let contactsNum = this.messageList[index]?.contactsNum; 574048147e0Sopenharmony_ci this.jumpToGroupDetail(threadId, contactsNum); 575048147e0Sopenharmony_ci } 576048147e0Sopenharmony_ci } 577048147e0Sopenharmony_ci 578048147e0Sopenharmony_ci exitConversationSelect() { 579048147e0Sopenharmony_ci this.onBackPress(); 580048147e0Sopenharmony_ci } 581048147e0Sopenharmony_ci 582048147e0Sopenharmony_ci touchStart(event: GestureEvent, index: number) { 583048147e0Sopenharmony_ci if (this.isMultipleSelectState) { 584048147e0Sopenharmony_ci return; 585048147e0Sopenharmony_ci } 586048147e0Sopenharmony_ci // Check whether the current touch item is the same as that of a touch item. 587048147e0Sopenharmony_ci // If not, reset the previous touch item. 588048147e0Sopenharmony_ci if (this.itemTouchedIdx !== -1 && index !== this.itemTouchedIdx) { 589048147e0Sopenharmony_ci let itemTouched = this.messageList[this.itemTouchedIdx]; 590048147e0Sopenharmony_ci if (itemTouched != undefined && itemTouched != null && itemTouched.isDelShow) { 591048147e0Sopenharmony_ci this.setListItemTransX(0); 592048147e0Sopenharmony_ci itemTouched.isDelShow = false; 593048147e0Sopenharmony_ci } 594048147e0Sopenharmony_ci } 595048147e0Sopenharmony_ci this.itemTouchedIdx = index; 596048147e0Sopenharmony_ci let item = this.messageList[this.itemTouchedIdx]; 597048147e0Sopenharmony_ci if (item == null || item == undefined) { 598048147e0Sopenharmony_ci return; 599048147e0Sopenharmony_ci } 600048147e0Sopenharmony_ci if (item.countOfUnread > 0) { 601048147e0Sopenharmony_ci this.operateBtnW = common.int.OPERATE_UNREAD_WIDTH; 602048147e0Sopenharmony_ci } else { 603048147e0Sopenharmony_ci this.operateBtnW = common.int.OPERATE_DELETE_WIDTH; 604048147e0Sopenharmony_ci } 605048147e0Sopenharmony_ci } 606048147e0Sopenharmony_ci 607048147e0Sopenharmony_ci resetTouch() { 608048147e0Sopenharmony_ci if (this.itemTouchedIdx !== -1) { 609048147e0Sopenharmony_ci let item = this.messageList[this.itemTouchedIdx]; 610048147e0Sopenharmony_ci if (item == undefined) { 611048147e0Sopenharmony_ci return false; 612048147e0Sopenharmony_ci } 613048147e0Sopenharmony_ci if (item.isDelShow) { 614048147e0Sopenharmony_ci item.isDelShow = false; 615048147e0Sopenharmony_ci this.setListItemTransX(0); 616048147e0Sopenharmony_ci return true; 617048147e0Sopenharmony_ci } 618048147e0Sopenharmony_ci } 619048147e0Sopenharmony_ci return false; 620048147e0Sopenharmony_ci } 621048147e0Sopenharmony_ci 622048147e0Sopenharmony_ci touchMove(event: GestureEvent, index: number) { 623048147e0Sopenharmony_ci if (this.isMultipleSelectState) { 624048147e0Sopenharmony_ci return; 625048147e0Sopenharmony_ci } 626048147e0Sopenharmony_ci // offsetX indicates the offset. The value range is [-operateBtnW, 0]. 627048147e0Sopenharmony_ci let offsetX = event.offsetX; 628048147e0Sopenharmony_ci // If the displacement is less than 2, there is no sliding. 629048147e0Sopenharmony_ci if (Math.abs(offsetX) <= 2) { 630048147e0Sopenharmony_ci return; 631048147e0Sopenharmony_ci } 632048147e0Sopenharmony_ci let item = this.messageList[this.itemTouchedIdx]; 633048147e0Sopenharmony_ci let transX = offsetX; 634048147e0Sopenharmony_ci if (item.isDelShow) { 635048147e0Sopenharmony_ci if (event.offsetX - this.operateBtnW <= 0) { 636048147e0Sopenharmony_ci transX = event.offsetX - this.operateBtnW 637048147e0Sopenharmony_ci } else { 638048147e0Sopenharmony_ci // Slide right to close 639048147e0Sopenharmony_ci transX = 0 640048147e0Sopenharmony_ci } 641048147e0Sopenharmony_ci } else { 642048147e0Sopenharmony_ci if (event.offsetX + this.operateBtnW >= 0) { 643048147e0Sopenharmony_ci transX = event.offsetX 644048147e0Sopenharmony_ci } else { 645048147e0Sopenharmony_ci // Slide left to maximum width 646048147e0Sopenharmony_ci transX = 0 - this.operateBtnW; 647048147e0Sopenharmony_ci } 648048147e0Sopenharmony_ci } 649048147e0Sopenharmony_ci this.setListItemTransX(transX); 650048147e0Sopenharmony_ci } 651048147e0Sopenharmony_ci 652048147e0Sopenharmony_ci deleteAction(idx) { 653048147e0Sopenharmony_ci let element = this.messageList[idx]; 654048147e0Sopenharmony_ci this.strMsgDeleteDialogTip = $r('app.string.msg_delete_dialog_tip1'); 655048147e0Sopenharmony_ci element.isCbChecked = true; 656048147e0Sopenharmony_ci this.hasLockMsg = (this.messageList.some((element, index) => element.isCbChecked && element.isLock)); 657048147e0Sopenharmony_ci } 658048147e0Sopenharmony_ci 659048147e0Sopenharmony_ci touchEnd(event: GestureEvent, index: number) { 660048147e0Sopenharmony_ci if (this.isMultipleSelectState) { 661048147e0Sopenharmony_ci return; 662048147e0Sopenharmony_ci } 663048147e0Sopenharmony_ci // offsetX indicates the offset. The value range is [-operateBtnW, 0]. 664048147e0Sopenharmony_ci let offsetX = event.offsetX; 665048147e0Sopenharmony_ci let item = this.messageList[this.itemTouchedIdx]; 666048147e0Sopenharmony_ci if (offsetX + (this.operateBtnW / 2) >= 0) { 667048147e0Sopenharmony_ci this.setListItemTransX(0); 668048147e0Sopenharmony_ci item.isDelShow = false; 669048147e0Sopenharmony_ci } else { 670048147e0Sopenharmony_ci this.setListItemTransX(0 - this.operateBtnW); 671048147e0Sopenharmony_ci item.isDelShow = true; 672048147e0Sopenharmony_ci } 673048147e0Sopenharmony_ci } 674048147e0Sopenharmony_ci // Subscribe to New Messages Received 675048147e0Sopenharmony_ci subscribeInfo() { 676048147e0Sopenharmony_ci HiLog.i(TAG, 'subscribeInfo, start'); 677048147e0Sopenharmony_ci let events = [common.string.RECEIVE_TRANSMIT_EVENT] 678048147e0Sopenharmony_ci let commonEventSubscribeInfo = { 679048147e0Sopenharmony_ci events: events 680048147e0Sopenharmony_ci }; 681048147e0Sopenharmony_ci commonEvent.createSubscriber(commonEventSubscribeInfo, this.createSubscriberCallBack.bind(this)); 682048147e0Sopenharmony_ci } 683048147e0Sopenharmony_ci 684048147e0Sopenharmony_ci setListItemTransX(transX) { 685048147e0Sopenharmony_ci let item = this.messageList[this.itemTouchedIdx]; 686048147e0Sopenharmony_ci if (item) { 687048147e0Sopenharmony_ci if (transX <= 0) { 688048147e0Sopenharmony_ci item.itemLeft = transX; 689048147e0Sopenharmony_ci } else { 690048147e0Sopenharmony_ci item.itemLeft = 0; 691048147e0Sopenharmony_ci } 692048147e0Sopenharmony_ci } 693048147e0Sopenharmony_ci // Used to refresh the interface. 694048147e0Sopenharmony_ci this.flushTranslate = !this.flushTranslate; 695048147e0Sopenharmony_ci } 696048147e0Sopenharmony_ci 697048147e0Sopenharmony_ci createSubscriberCallBack(err, data) { 698048147e0Sopenharmony_ci this.commonEventData = data; 699048147e0Sopenharmony_ci // Received subscription 700048147e0Sopenharmony_ci commonEvent.subscribe(this.commonEventData, this.subscriberCallBack.bind(this)); 701048147e0Sopenharmony_ci } 702048147e0Sopenharmony_ci 703048147e0Sopenharmony_ci subscriberCallBack(err, data) { 704048147e0Sopenharmony_ci this.page = 1; 705048147e0Sopenharmony_ci this.queryAllMessages(); 706048147e0Sopenharmony_ci } 707048147e0Sopenharmony_ci // Unsubscribe 708048147e0Sopenharmony_ci unsubscribeInfo() { 709048147e0Sopenharmony_ci if (this.commonEventData != null) { 710048147e0Sopenharmony_ci commonEvent.unsubscribe(this.commonEventData, () => { 711048147e0Sopenharmony_ci HiLog.i(TAG, 'unsubscribeInfo, success'); 712048147e0Sopenharmony_ci }); 713048147e0Sopenharmony_ci } 714048147e0Sopenharmony_ci } 715048147e0Sopenharmony_ci // Switching to the Contacts app 716048147e0Sopenharmony_ci jumpToContact(actionData) { 717048147e0Sopenharmony_ci var str = commonService.commonContactParam(actionData); 718048147e0Sopenharmony_ci globalThis.mmsContext.startAbility(str).then((data) => { 719048147e0Sopenharmony_ci }).catch((error) => { 720048147e0Sopenharmony_ci HiLog.e(TAG, 'jumpToContact, failed: ' + JSON.stringify(error.message)); 721048147e0Sopenharmony_ci }) 722048147e0Sopenharmony_ci this.isJumping = false; 723048147e0Sopenharmony_ci } 724048147e0Sopenharmony_ci // Obtains the switch value for integrating notification information and displaying contact avatars. 725048147e0Sopenharmony_ci getSettingFlagForConvListPage() { 726048147e0Sopenharmony_ci let result = settingService.getSettingFlagForConvListPage(); 727048147e0Sopenharmony_ci if (result) { 728048147e0Sopenharmony_ci this.isShowContactHeadIcon = result.isShowContactHeadIcon; 729048147e0Sopenharmony_ci } 730048147e0Sopenharmony_ci } 731048147e0Sopenharmony_ci} 732