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 common from '../data/commonData';
17
18export default {
19    commonContactParam(actionData) {
20        let str = {
21            'bundleName': common.string.CONTACT_BUNDLE_NAME,
22            'abilityName': common.string.CONTACT_ABILITY_NAME,
23            'parameters': actionData,
24            'entities': [
25                common.string.COMMON_ENTITIES
26            ]
27        };
28        return str;
29    },
30
31    getDisplay(mmsParts) {
32        let display = common.MESSAGE_SHOW_TYPE.NORMAL;
33        let first = mmsParts[0];
34        if (mmsParts.length == 1) {
35            display = common.MESSAGE_SHOW_TYPE.NORMAL;
36        } else if (mmsParts.length >= 2) {
37            let second = mmsParts[1];
38            if (first.msgType == common.MSG_ITEM_TYPE.THEME) {
39                if (second.msgType == common.MSG_ITEM_TYPE.IMAGE || second.msgType == common.MSG_ITEM_TYPE.VIDEO) {
40                    display = common.MESSAGE_SHOW_TYPE.PPT_IMAGE;
41                } else if (mmsParts.length > 2) {
42                    display = common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE;
43                } else {
44                    display = common.MESSAGE_SHOW_TYPE.THEME_NO_IMAGE;
45                }
46            } else if (second.msgType == common.MSG_ITEM_TYPE.THEME && mmsParts.length == 3) {
47                display = common.MESSAGE_SHOW_TYPE.THEME_IMAGE;
48            } else {
49                if (first.msgType == common.MSG_ITEM_TYPE.IMAGE || first.msgType == common.MSG_ITEM_TYPE.VIDEO) {
50                    display = common.MESSAGE_SHOW_TYPE.PPT_IMAGE;
51                } else {
52                    display = common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE;
53                }
54            }
55        }
56        return display;
57    },
58
59    setItemMmsContent(item, mmsParts) {
60        item.msgUriPath = common.string.EMPTY_STR;
61        item.content = common.string.EMPTY_STR;
62        let first = mmsParts[0];
63        item.msgUriPath = first.msgUriPath;
64        item.audioTime = first.time;
65        if (mmsParts.length == 1) {
66            item.msgType = first.msgType;
67            item.content = first.content;
68        } else if (mmsParts.length >= 2) {
69            let content = first.content;
70            let second = mmsParts[1];
71            let secondContent = second.content;
72            if (first.msgType == common.MSG_ITEM_TYPE.THEME) {
73                if (second.msgType == common.MSG_ITEM_TYPE.IMAGE || second.msgType == common.MSG_ITEM_TYPE.VIDEO) {
74                    item.msgUriPath = second.msgUriPath;
75                }
76                if (content == common.string.EMPTY_STR) {
77                    item.content = secondContent;
78                } else {
79                    item.content = content + '\n' + secondContent;
80                }
81            } else if (second.msgType == common.MSG_ITEM_TYPE.THEME && mmsParts.length === 3) {
82                item.msgUriPath = first.msgUriPath;
83                item.msgType = first.msgType;
84                let third = mmsParts[2];
85                let thirdContent = third.content;
86                if (secondContent == common.string.EMPTY_STR) {
87                    item.content = thirdContent;
88                } else {
89                    item.content = secondContent + '\n' + thirdContent;
90                }
91            } else {
92                item.content = content;
93            }
94        }
95    },
96
97    getMmsSource(mmsParts) {
98        let source = [];
99        mmsParts.forEach(part => {
100            let obj = {
101                msgType: parseInt(part.type),
102                msgUriPath: part.locationPath,
103                time: part.recordingTime,
104                content: part.content,
105                fileSize: part.fileSize,
106                messageType: part.messageType ? parseInt(part.messageType) : 0
107            }
108            source.push(obj);
109        });
110        return source;
111    },
112
113    getMmsContent(mmsSource) {
114        let content = common.string.EMPTY_STR;
115        for (let mms of mmsSource) {
116            // Indicates that the topic exists.
117            if (mms.msgType == common.MSG_ITEM_TYPE.THEME) {
118                content = mms.content;
119                break;
120            }
121        }
122        return content;
123    },
124
125    checkIsMms(dataSource) {
126        // Indicates whether the SMS message is a common message.
127        let isMsg = false;
128        for (let index = 0; index < dataSource.length; index++) {
129            let item = dataSource[index];
130            if (!item.isMsm) {
131                isMsg = true;
132                break;
133            }
134        }
135        return isMsg;
136    },
137
138    judgeIsSelectText(mmsSource) {
139        let flage = false;
140        for (let item of mmsSource) {
141            let msgType = item.msgType;
142            if (common.MSG_ITEM_TYPE.THEME == msgType) {
143                flage = true;
144            }
145            if (common.MSG_ITEM_TYPE.TEXT == msgType && item.content != common.string.EMPTY_STR) {
146                flage = true;
147            }
148            if ((common.MSG_ITEM_TYPE.IMAGE == msgType || common.MSG_ITEM_TYPE.AUDIO == msgType ||
149                common.MSG_ITEM_TYPE.VIDEO == msgType) && item.content != common.string.EMPTY_STR) {
150                flage = true;
151            }
152        }
153        return flage;
154    },
155
156    judgeIsImage(mmsSource) {
157        let flage = false;
158        for (let item of mmsSource) {
159            let msgType = item.msgType;
160            if (common.MSG_ITEM_TYPE.IMAGE == msgType) {
161                flage = true;
162            }
163        }
164        return flage;
165    },
166
167    getTransmitContentHeight(list) {
168        let height = 0;
169        list.forEach((item) => {
170            if (item.msgShowType == common.MESSAGE_SHOW_TYPE.NORMAL) {
171                height = height + common.TRANSMIT_ITEM_HEIGHT.TEXT_HEIGHT;
172            } else if (item.msgShowType == common.MESSAGE_SHOW_TYPE.THEME_IMAGE) {
173                height = height + common.TRANSMIT_ITEM_HEIGHT.THEME_IMAGE_HEIGHT;
174            } else if (item.msgShowType == common.MESSAGE_SHOW_TYPE.PPT_IMAGE) {
175                height = height + common.TRANSMIT_ITEM_HEIGHT.PPT_IMAGE_HEIGHT;
176            } else if (item.msgShowType == common.MESSAGE_SHOW_TYPE.THEME_NO_IMAGE ||
177            item.msgShowType == common.MESSAGE_SHOW_TYPE.PPT_NO_IMAGE) {
178                height = height + common.TRANSMIT_ITEM_HEIGHT.THEME_HEIGHT;
179            }
180            height = height + common.TRANSMIT_ITEM_HEIGHT.DISTANCE;
181        });
182        if (height > common.TRANSMIT_ITEM_HEIGHT.TOTAL_HEIGHT) {
183            height = common.TRANSMIT_ITEM_HEIGHT.TOTAL_HEIGHT;
184        }
185        return height;
186    },
187
188    judgeIsAttachment(mmsSource): boolean {
189        let flage = false;
190        if (mmsSource == null || mmsSource.length == 0) {
191            return flage;
192        }
193        for (let item of mmsSource) {
194            let msgType = item.msgType;
195            if (common.MSG_ITEM_TYPE.IMAGE == msgType || common.MSG_ITEM_TYPE.VIDEO == msgType ||
196                common.MSG_ITEM_TYPE.AUDIO == msgType) {
197                flage = true;
198            }
199        }
200        return flage;
201    }
202}