• 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 image from '@ohos.multimedia.image'
17
18@Entry
19@Component
20struct MsgBase {
21  build() {
22    Row() {
23      Column() {
24        Text('Hello World')
25          .fontSize(50)
26          .fontWeight(FontWeight.Bold)
27      }.width('100%')
28    }.height('100%')
29  }
30}
31/**
32 * 聊天list中item对象
33 * @param user 用户名
34 * @param lastMsg 最后一天信息
35 * @param time 时间
36 */
37
38export class ChatModel {
39  user: EMContact
40  lastMsg: string;
41  constructor(user: EMContact, lastMsg: string) {
42    this.user = user
43    this.lastMsg = lastMsg
44  }
45
46  toString(): string {
47    return this.user.toString() + "  " + this.lastMsg + "  "
48  }
49}
50
51// 聊天信息
52export class MessageBase {
53  img: image.PixelMap
54  msgId: string
55  fo: EMContact
56  to: EMContact
57  msgBody: MessageBody
58  msgType: number
59  msgTime: number
60  constructor(id: string, fo: EMContact, to: EMContact, msg: MessageBody, ty: number, time: number) {
61    this.msgId = id
62    this.fo = fo
63    this.to = to
64    this.msgBody = msg
65    this.msgType = ty
66    this.msgTime = time
67  }
68
69  toString(): string {
70    return this.msgId + "  " + this.fo + "  " + this.to + "  " + this.msgBody + "  " + this.msgType + "  " + this.msgTime
71  }
72}
73
74export class MessageBody {
75  toString(): string{
76    return ""
77  }
78}
79
80// 文本消息
81export class TextMessage extends MessageBody {
82  toString(): string {
83    return this.msg
84  }
85
86  constructor(msg: string) {
87    super()
88    this.msg = msg
89  }
90
91  msg: string
92}
93
94// 图片消息
95export class ImageMessage extends MessageBody {
96  toString(): string {
97    return this.height + "  " + this.width + "  " + this.img
98  }
99
100  constructor(hei: number, wid: number, img: string) {
101    super()
102    this.height = hei
103    this.width = wid
104    this.img = img
105  }
106
107  height: number
108  width: number
109  img: string
110}
111
112// wantParams:图片+文本消息
113export class ImgTextMessage extends MessageBody {
114  toString(): string {
115    return this.msg + ' ' +
116    this.height + "  " + this.width + "  " + this.img
117  }
118
119  constructor(hei: number, wid: number, img: string | Resource, msg: string) {
120    super()
121    this.height = hei
122    this.width = wid
123    this.img = img
124    this.msg = msg
125  }
126
127  height: number
128  width: number
129  img: string | Resource
130  msg: string
131}
132
133// wantParams:图片文件
134export class FileMessage extends MessageBody {
135  height: number | string
136  width: number | string
137  img: image.PixelMap
138  constructor(hei: number | string, wid: number | string, img: image.PixelMap) {
139    super()
140    this.height = hei
141    this.width = wid
142    this.img = img
143  }
144}
145
146// user消息
147export class EMContact {
148  userId: string
149  userName: string
150  userImage: string
151  toString(): string {
152    return this.userId + "  " + this.userName + "  " + this.userImage
153  }
154
155  constructor(id: string, name: string, image?: string) {
156    this.userId = id
157    this.userName = name
158    this.userImage = $r("app.media.personality3")
159    if (image != null) {
160      this.userImage = image
161    }
162  }
163}
164
165export class FriendMoment {
166  id: string
167  user: EMContact
168  text: string
169  time: string
170  imageList: Array<string>
171  constructor(id: string, user: EMContact, text: string, time: string, List?: Array<string>) {
172    this.id = id
173    this.user = user
174    this.time = time
175    this.text = text
176    if (List != null) {
177      this.imageList = List
178    }
179  }
180
181  toString(): string {
182    return this.id + "  " + this.user.toString() + "  " + this.text + "  " + this.time + "  " // +this.imageList.toString()
183  }
184}