forked from xhzengAIB/MessageDisplayKit
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathXHMessage.m
More file actions
277 lines (228 loc) · 10 KB
/
XHMessage.m
File metadata and controls
277 lines (228 loc) · 10 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
//
// XHMessage.m
// MessageDisplayExample
//
// Created by qtone-1 on 14-4-24.
// Copyright (c) 2014年 曾宪华 开发团队(http://iyilunba.com ) 本人QQ:543413507 本人QQ群(142557668). All rights reserved.
//
#import "XHMessage.h"
@implementation XHMessage
- (instancetype)initWithText:(NSString *)text
sender:(NSString *)sender
timestamp:(NSDate *)timestamp {
self = [super init];
if (self) {
self.text = text;
self.sender = sender;
self.timestamp = timestamp;
self.messageMediaType = XHBubbleMessageText;
}
return self;
}
/**
* 初始化图片类型的消息
*
* @param photo 目标图片
* @param thumbnailUrl 目标图片在服务器的缩略图地址
* @param originPhotoUrl 目标图片在服务器的原图地址
* @param sender 发送者
* @param date 发送时间
*
* @return 返回Message model 对象
*/
- (instancetype)initWithPhoto:(UIImage *)photo
thumbnailUrl:(NSString *)thumbnailUrl
originPhotoUrl:(NSString *)originPhotoUrl
sender:(NSString *)sender
timestamp:(NSDate *)timestamp {
self = [super init];
if (self) {
self.photo = photo;
self.thumbnailUrl = thumbnailUrl;
self.originPhotoUrl = originPhotoUrl;
self.sender = sender;
self.timestamp = timestamp;
self.messageMediaType = XHBubbleMessagePhoto;
}
return self;
}
/**
* 初始化视频类型的消息
*
* @param videoConverPhoto 目标视频的封面图
* @param videoPath 目标视频的本地路径,如果是下载过,或者是从本地发送的时候,会存在
* @param videoUrl 目标视频在服务器上的地址
* @param sender 发送者
* @param date 发送时间
*
* @return 返回Message model 对象
*/
- (instancetype)initWithVideoConverPhoto:(UIImage *)videoConverPhoto
videoPath:(NSString *)videoPath
videoUrl:(NSString *)videoUrl
sender:(NSString *)sender
timestamp:(NSDate *)timestamp {
self = [super init];
if (self) {
self.videoConverPhoto = videoConverPhoto;
self.videoPath = videoPath;
self.videoUrl = videoUrl;
self.sender = sender;
self.timestamp = timestamp;
self.messageMediaType = XHBubbleMessageVideo;
}
return self;
}
/**
* 初始化语音类型的消息
*
* @param voicePath 目标语音的本地路径
* @param voiceUrl 目标语音在服务器的地址
* @param sender 发送者
* @param date 发送时间
*
* @return 返回Message model 对象
*/
- (instancetype)initWithVoicePath:(NSString *)voicePath
voiceUrl:(NSString *)voiceUrl
sender:(NSString *)sender
timestamp:(NSDate *)timestamp {
self = [super init];
if (self) {
self.voicePath = voicePath;
self.videoUrl = voiceUrl;
self.sender = sender;
self.timestamp = timestamp;
self.messageMediaType = XHBubbleMessageVoice;
}
return self;
}
- (instancetype)initWithEmotionPath:(NSString *)emotionPath
sender:(NSString *)sender
timestamp:(NSDate *)timestamp {
self = [super init];
if (self) {
self.emotionPath = emotionPath;
self.sender = sender;
self.timestamp = timestamp;
self.messageMediaType = XHBubbleMessageFace;
}
return self;
}
- (instancetype)initWithLocalPositionPhoto:(UIImage *)localPositionPhoto
geolocations:(NSString *)geolocations
location:(CLLocation *)location
sender:(NSString *)sender
timestamp:(NSDate *)timestamp {
self = [super init];
if (self) {
self.localPositionPhoto = localPositionPhoto;
self.geolocations = geolocations;
self.location = location;
self.sender = sender;
self.timestamp = timestamp;
self.messageMediaType = XHBubbleMessageLocalPosition;
}
return self;
}
- (void)dealloc {
_text = nil;
_photo = nil;
_thumbnailUrl = nil;
_originPhotoUrl = nil;
_videoConverPhoto = nil;
_videoPath = nil;
_videoUrl = nil;
_voicePath = nil;
_voiceUrl = nil;
_emotionPath = nil;
_localPositionPhoto = nil;
_geolocations = nil;
_location = nil;
_avator = nil;
_avatorUrl = nil;
_sender = nil;
_timestamp = nil;
}
#pragma mark - NSCoding
- (id)initWithCoder:(NSCoder *)aDecoder {
self = [super init];
if (self) {
_text = [aDecoder decodeObjectForKey:@"text"];
_photo = [aDecoder decodeObjectForKey:@"photo"];
_thumbnailUrl = [aDecoder decodeObjectForKey:@"thumbnailUrl"];
_originPhotoUrl = [aDecoder decodeObjectForKey:@"originPhotoUrl"];
_videoConverPhoto = [aDecoder decodeObjectForKey:@"videoConverPhoto"];
_videoPath = [aDecoder decodeObjectForKey:@"videoPath"];
_videoUrl = [aDecoder decodeObjectForKey:@"videoUrl"];
_voicePath = [aDecoder decodeObjectForKey:@"voicePath"];
_voiceUrl = [aDecoder decodeObjectForKey:@"voiceUrl"];
_emotionPath = [aDecoder decodeObjectForKey:@"emotionPath"];
_localPositionPhoto = [aDecoder decodeObjectForKey:@"localPositionPhoto"];
_geolocations = [aDecoder decodeObjectForKey:@"geolocations"];
_location = [aDecoder decodeObjectForKey:@"location"];
_avator = [aDecoder decodeObjectForKey:@"avator"];
_avatorUrl = [aDecoder decodeObjectForKey:@"avatorUrl"];
_sender = [aDecoder decodeObjectForKey:@"sender"];
_timestamp = [aDecoder decodeObjectForKey:@"timestamp"];
}
return self;
}
- (void)encodeWithCoder:(NSCoder *)aCoder {
[aCoder encodeObject:self.text forKey:@"text"];
[aCoder encodeObject:self.photo forKey:@"photo"];
[aCoder encodeObject:self.thumbnailUrl forKey:@"thumbnailUrl"];
[aCoder encodeObject:self.originPhotoUrl forKey:@"originPhotoUrl"];
[aCoder encodeObject:self.videoConverPhoto forKey:@"videoConverPhoto"];
[aCoder encodeObject:self.videoPath forKey:@"videoPath"];
[aCoder encodeObject:self.videoUrl forKey:@"videoUrl"];
[aCoder encodeObject:self.voicePath forKey:@"voicePath"];
[aCoder encodeObject:self.voiceUrl forKey:@"voiceUrl"];
[aCoder encodeObject:self.voicePath forKey:@"voicePath"];
[aCoder encodeObject:self.voiceUrl forKey:@"voiceUrl"];
[aCoder encodeObject:self.emotionPath forKey:@"emotionPath"];
[aCoder encodeObject:self.localPositionPhoto forKey:@"localPositionPhoto"];
[aCoder encodeObject:self.geolocations forKey:@"geolocations"];
[aCoder encodeObject:self.location forKey:@"location"];
[aCoder encodeObject:self.sender forKey:@"sender"];
[aCoder encodeObject:self.timestamp forKey:@"timestamp"];
}
#pragma mark - NSCopying
- (id)copyWithZone:(NSZone *)zone {
switch (self.messageMediaType) {
case XHBubbleMessageText:
return [[[self class] allocWithZone:zone] initWithText:[self.text copy]
sender:[self.sender copy]
timestamp:[self.timestamp copy]];
case XHBubbleMessagePhoto:
return [[[self class] allocWithZone:zone] initWithPhoto:[self.photo copy]
thumbnailUrl:[self.thumbnailUrl copy]
originPhotoUrl:[self.originPhotoUrl copy]
sender:[self.sender copy]
timestamp:[self.timestamp copy]];
case XHBubbleMessageVideo:
return [[[self class] allocWithZone:zone] initWithVideoConverPhoto:[self.videoConverPhoto copy]
videoPath:[self.videoPath copy]
videoUrl:[self.videoUrl copy]
sender:[self.sender copy]
timestamp:[self.timestamp copy]];
case XHBubbleMessageVoice:
return [[[self class] allocWithZone:zone] initWithVoicePath:[self.voicePath copy]
voiceUrl:[self.voiceUrl copy]
sender:[self.sender copy]
timestamp:[self.timestamp copy]];
case XHBubbleMessageFace:
return [[[self class] allocWithZone:zone] initWithEmotionPath:[self.emotionPath copy]
sender:[self.sender copy]
timestamp:[self.timestamp copy]];
case XHBubbleMessageLocalPosition:
return [[[self class] allocWithZone:zone] initWithLocalPositionPhoto:[self.localPositionPhoto copy]
geolocations:self.geolocations
location:[self.location copy]
sender:[self.sender copy]
timestamp:[self.timestamp copy]];
default:
return nil;
}
}
@end