1/** 2 * Copyright (c) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16import contactService from "../service/ContractService"; 17import conversationListService from "../service/ConversationListService"; 18import common from "../data/commonData"; 19import featureAbility from "@ohos.ability.featureAbility"; 20import HiLog from "./HiLog"; 21import router from "@system.router"; 22 23const TAG = "WantUtil"; 24 25export default { 26 27 getWant() { 28 HiLog.i(TAG, "getWant start"); 29 if(globalThis.abilityWant == null) { 30 return; 31 } 32 let abilityWant = globalThis.abilityWant; 33 globalThis.abilityWant = null; 34 35 if (abilityWant.hasOwnProperty("parameters")) { 36 let parameters = abilityWant.parameters; 37 let pageFlag = ''; 38 if (parameters.hasOwnProperty("pageFlag")) { 39 pageFlag = parameters.pageFlag; 40 HiLog.i(TAG, "pageFlag = " + pageFlag); 41 } 42 let contractParams = {} 43 if (parameters.hasOwnProperty("contactObjects")) { 44 contractParams = contactService.dealContractParams(parameters.contactObjects); 45 } 46 this.jump(pageFlag, contractParams); 47 } 48 }, 49 50 jump(pageFlag, contractParams) { 51 let result = { 52 uri: '', 53 params: {} 54 }; 55 HiLog.i(TAG, "want.pageFlag: " + pageFlag); 56 switch (pageFlag) { 57 case "conversation": 58 result.uri = "pages/conversation/conversation"; 59 if (contractParams) { 60 result.params = contractParams; 61 this.jumpIsNewPage(result, contractParams); 62 } else { 63 router.push(result); 64 } 65 break; 66 default: 67 break; 68 } 69 }, 70 71 async jumpIsNewPage(result, contractParams) { 72 // Check whether a session has been created for the current phone number in the SMS message. 73 conversationListService.querySessionByTelephone(contractParams.strContactsNumber, res => { 74 if (res.code == common.int.SUCCESS && res.response.id > 0) { 75 result.params.threadId = res.response.id; 76 this.markAllAsRead(result.params.threadId); 77 if (res.response.hasDraft && res.response.messageCount == 0) { 78 result.params.isNewMsg = true; 79 } else { 80 result.params.isNewMsg = false; 81 } 82 } else { 83 result.params.isNewMsg = true; 84 } 85 router.push(result); 86 }); 87 }, 88 89 markAllAsRead(threadId) { 90 let actionData = { 91 threadIds: [threadId], 92 hasRead: 1, 93 valueBucket: { 94 "unread_count": 0 95 } 96 }; 97 conversationListService.markAllAsRead(actionData); 98 } 99}