-
Notifications
You must be signed in to change notification settings - Fork 1.3k
/
Copy pathPrivateMessage.m
executable file
·106 lines (97 loc) · 3.3 KB
/
PrivateMessage.m
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
//
// PrivateMessage.m
// Coding_iOS
//
// Created by 王 原闯 on 14-8-29.
// Copyright (c) 2014年 Coding. All rights reserved.
//
#import "PrivateMessage.h"
#import "Login.h"
@implementation PrivateMessage
- (instancetype)init
{
self = [super init];
if (self) {
_sendStatus = PrivateMessageStatusSendSucess;
_id = @(-1);
}
return self;
}
- (void)setContent:(NSString *)content{
if (_content != content) {
_htmlMedia = [HtmlMedia htmlMediaWithString:content showType:MediaShowTypeCode];
if (_htmlMedia.contentDisplay.length <= 0 && _htmlMedia.imageItems.count <= 0 && !_nextImg) {
_content = @" ";//占位
}else{
_content = _htmlMedia.contentDisplay;
}
}
}
- (BOOL)hasMedia{
return self.nextImg || (self.htmlMedia && self.htmlMedia.imageItems.count> 0);
}
- (BOOL)isSingleBigMonkey{
BOOL isSingleBigMonkey = NO;
if (self.content.length == 0) {
if (_htmlMedia.imageItems.count == 1) {
HtmlMediaItem *item = [_htmlMedia.imageItems firstObject];
if (item.type == HtmlMediaItemType_EmotionMonkey) {
isSingleBigMonkey = YES;
}
}
}
return isSingleBigMonkey;
}
- (BOOL)isVoice{
return (_type.integerValue == 1 || _voiceMedia);
}
+ (instancetype)privateMessageWithObj:(id)obj andFriend:(User *)curFriend{
PrivateMessage *nextMsg = [[PrivateMessage alloc] init];
nextMsg.sender = [Login curLoginUser];
nextMsg.friend = curFriend;
nextMsg.sendStatus = PrivateMessageStatusSending;
nextMsg.created_at = [NSDate date];
if ([obj isKindOfClass:[NSString class]]) {
nextMsg.content = obj;
nextMsg.extra = @"";
}else if ([obj isKindOfClass:[UIImage class]]){
nextMsg.nextImg = obj;
nextMsg.content = @"";
nextMsg.extra = @"";
}else if ([obj isKindOfClass:[VoiceMedia class]]){
nextMsg.voiceMedia = obj;
nextMsg.extra = @"";
}else if ([obj isKindOfClass:[PrivateMessage class]]){
PrivateMessage *originalMsg = (PrivateMessage *)obj;
NSMutableString *content = [[NSMutableString alloc] initWithString:originalMsg.content];
NSMutableString *extra = [[NSMutableString alloc] init];
if (originalMsg.htmlMedia.mediaItems && originalMsg.htmlMedia.mediaItems.count > 0) {
for (HtmlMediaItem *item in originalMsg.htmlMedia.mediaItems) {
if (item.type == HtmlMediaItemType_Image) {
if (extra.length > 0) {
[extra appendFormat:@",%@", item.src];
}else{
[extra appendString:item.src];
}
}else if (item.type == HtmlMediaItemType_EmotionMonkey){
[content appendFormat:@" :%@: ", item.title];
}
}
}
nextMsg.content = content;
nextMsg.extra = extra;
}
return nextMsg;
};
- (NSString *)toSendPath{
return @"api/message/send";
}
- (NSDictionary *)toSendParams{
return @{@"content" : _content? [_content aliasedString]: @"",
@"extra" : _extra? _extra: @"",
@"receiver_global_key" : _friend.global_key};
}
- (NSString *)toDeletePath{
return [NSString stringWithFormat:@"api/message/%ld", _id.longValue];
}
@end