• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 router from "@system.router";
17
18import ContactService from "../service/ContactsService";
19import ConversationListService from "../service/ConversationListService";
20import common from "../data/commonData";
21import HiLog from "./HiLog";
22import LooseObject from '../data/LooseObject';
23
24const TAG = "WantUtil";
25
26export default {
27
28  getWant() {
29    HiLog.i(TAG, "getWant start");
30    if(globalThis.abilityWant == null) {
31      return;
32    }
33    let abilityWant = globalThis.abilityWant;
34    globalThis.abilityWant = null;
35
36    if (abilityWant.hasOwnProperty("parameters")) {
37        let parameters = abilityWant.parameters;
38        let pageFlag = '';
39        if (parameters.hasOwnProperty("pageFlag")) {
40          pageFlag = parameters.pageFlag;
41          HiLog.i(TAG, "pageFlag = " + pageFlag);
42        }
43        let contactParams = {}
44        if (parameters.hasOwnProperty("contactObjects")) {
45          contactParams = ContactService.getInstance().dealContactParams(parameters.contactObjects);
46        }
47        this.jump(pageFlag, contactParams);
48      }
49  },
50
51  jump(pageFlag, contactParams) {
52    let result = {
53      uri: '',
54      params: {}
55    };
56    HiLog.i(TAG, "want.pageFlag: " + pageFlag);
57    switch (pageFlag) {
58      case "conversation":
59        result.uri = "pages/conversation/conversation";
60        if (contactParams) {
61          result.params = contactParams;
62          this.jumpIsNewPage(result, contactParams);
63        } else {
64          router.push(result);
65        }
66        break;
67      default:
68        break;
69    }
70  },
71
72  async jumpIsNewPage(result, contactParams) {
73    // Check whether a session has been created for the current phone number in the SMS message.
74    ConversationListService.getInstance().querySessionByTelephone(contactParams.strContactsNumber, res => {
75      if (res.code == common.int.SUCCESS && res.response.id > 0) {
76        result.params.threadId = res.response.id;
77        let actionData: LooseObject = {};
78        actionData.threadId = result.params.threadId;
79        ConversationListService.getInstance().markAllToRead(actionData);
80        if (res.response.hasDraft && res.response.messageCount == 0) {
81          result.params.isNewMsg = true;
82        } else {
83          result.params.isNewMsg = false;
84        }
85      } else {
86        result.params.isNewMsg = true;
87      }
88      router.push(result);
89    }, null);
90  },
91}