Skip to content

Commit 8622ab1

Browse files
author
mengyaoyao
committed
模拟回复部分
1 parent d643b58 commit 8622ab1

File tree

20 files changed

+476
-36
lines changed

20 files changed

+476
-36
lines changed

.DS_Store

0 Bytes
Binary file not shown.

CocoaAsyncSocket_TCP.xcodeproj/project.pbxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
B8661AA71ECD95680022753D /* ChatRecordTool.m in Sources */ = {isa = PBXBuildFile; fileRef = B8661AA61ECD95680022753D /* ChatRecordTool.m */; };
8282
B8661AAA1ECD998E0022753D /* UIImageView+GIF.m in Sources */ = {isa = PBXBuildFile; fileRef = B8661AA91ECD998E0022753D /* UIImageView+GIF.m */; };
8383
B89E046A1ED03F23000863F1 /* UIImage+photoPicker.m in Sources */ = {isa = PBXBuildFile; fileRef = B89E04691ED03F23000863F1 /* UIImage+photoPicker.m */; };
84+
B8CD69BD1ED6D53300AFCD93 /* ChatAudioPlayTool.m in Sources */ = {isa = PBXBuildFile; fileRef = B8CD69BC1ED6D53300AFCD93 /* ChatAudioPlayTool.m */; };
8485
B8EEC0C91ED47E2800F52E79 /* ChatConfigModel.m in Sources */ = {isa = PBXBuildFile; fileRef = B8EEC0C81ED47E2800F52E79 /* ChatConfigModel.m */; };
8586
E1527204E4A6C66E20ABAB19 /* Pods_CocoaAsyncSocket_TCP.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 24AA3076491D2596209CE424 /* Pods_CocoaAsyncSocket_TCP.framework */; };
8687
/* End PBXBuildFile section */
@@ -253,6 +254,8 @@
253254
B8661AA91ECD998E0022753D /* UIImageView+GIF.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImageView+GIF.m"; sourceTree = "<group>"; };
254255
B89E04681ED03F23000863F1 /* UIImage+photoPicker.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "UIImage+photoPicker.h"; sourceTree = "<group>"; };
255256
B89E04691ED03F23000863F1 /* UIImage+photoPicker.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "UIImage+photoPicker.m"; sourceTree = "<group>"; };
257+
B8CD69BB1ED6D53300AFCD93 /* ChatAudioPlayTool.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChatAudioPlayTool.h; sourceTree = "<group>"; };
258+
B8CD69BC1ED6D53300AFCD93 /* ChatAudioPlayTool.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChatAudioPlayTool.m; sourceTree = "<group>"; };
256259
B8EEC0C71ED47E2800F52E79 /* ChatConfigModel.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ChatConfigModel.h; sourceTree = "<group>"; };
257260
B8EEC0C81ED47E2800F52E79 /* ChatConfigModel.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = ChatConfigModel.m; sourceTree = "<group>"; };
258261
/* End PBXFileReference section */
@@ -324,6 +327,8 @@
324327
B8661A9B1ECD7D120022753D /* RecordUtil */,
325328
B8661AA51ECD95680022753D /* ChatRecordTool.h */,
326329
B8661AA61ECD95680022753D /* ChatRecordTool.m */,
330+
B8CD69BB1ED6D53300AFCD93 /* ChatAudioPlayTool.h */,
331+
B8CD69BC1ED6D53300AFCD93 /* ChatAudioPlayTool.m */,
327332
);
328333
path = ChatRecordCover;
329334
sourceTree = "<group>";
@@ -905,6 +910,7 @@
905910
B8661AAA1ECD998E0022753D /* UIImageView+GIF.m in Sources */,
906911
B85F3A491EC9C9C600B2EA9E /* NSDate+extension.m in Sources */,
907912
B816A1D81ED040A20024859F /* TZGifPhotoPreviewController.m in Sources */,
913+
B8CD69BD1ED6D53300AFCD93 /* ChatAudioPlayTool.m in Sources */,
908914
B85F3A621EC9C9C600B2EA9E /* ChatViewController.m in Sources */,
909915
B816A1E21ED040A20024859F /* UIView+Layout.m in Sources */,
910916
B85F3A4E1EC9C9C600B2EA9E /* MYCoretextResultTool.m in Sources */,
@@ -1086,6 +1092,7 @@
10861092
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
10871093
GCC_PREFIX_HEADER = CocoaAsyncSocket_TCP/Comon/PrefixHeader.pch;
10881094
INFOPLIST_FILE = CocoaAsyncSocket_TCP/Info.plist;
1095+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
10891096
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
10901097
LIBRARY_SEARCH_PATHS = (
10911098
"$(inherited)",
@@ -1103,6 +1110,7 @@
11031110
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
11041111
GCC_PREFIX_HEADER = CocoaAsyncSocket_TCP/Comon/PrefixHeader.pch;
11051112
INFOPLIST_FILE = CocoaAsyncSocket_TCP/Info.plist;
1113+
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
11061114
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
11071115
LIBRARY_SEARCH_PATHS = (
11081116
"$(inherited)",

CocoaAsyncSocket_TCP/.DS_Store

0 Bytes
Binary file not shown.

CocoaAsyncSocket_TCP/AppDelegate/AppDelegate.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(
2626

2727
//测试数据
2828
[Account account].myUserID = @"19910805";
29+
[Account account].nickName = @"程芳菲同学";
2930

3031
return YES;
3132
}

CocoaAsyncSocket_TCP/ChatHandler/ChatHandler.h

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@protocol ChatHandlerDelegate <NSObject>
2727

2828
@required
29+
2930
//接收消息代理
3031
- (void)didReceiveMessage:(ChatModel *)chatModel type:(ChatMessageType)messageType;
3132

@@ -40,7 +41,6 @@
4041
//socket连接状态
4142
@property (nonatomic, assign) SocketConnectStatus connectStatus;
4243

43-
4444
//聊天单例
4545
+ (instancetype)shareInstance;
4646
//连接服务器端口
@@ -54,4 +54,18 @@
5454
//发送消息
5555
- (void)sendMessage:(ChatModel *)chatModel timeOut:(NSUInteger)timeOut tag:(long)tag;
5656

57+
58+
59+
//发送文本消息
60+
- (void)sendTextMessage:(ChatModel *)textModel;
61+
62+
//发送语音消息
63+
- (void)sendAudioMessage:(ChatModel *)audioModel;
64+
65+
//发送图片消息
66+
- (void)sendPicMessage:(NSArray<ChatModel *>*)picModels;
67+
68+
//发送视频消息
69+
- (void)sendVideoMessage:(ChatModel *)videoModel;
70+
5771
@end

CocoaAsyncSocket_TCP/ChatHandler/ChatHandler.m

Lines changed: 125 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ - (void)sendMessage:(ChatModel *)chatModel timeOut:(NSUInteger)timeOut tag:(long
138138
- (void)executeDisconnectServer
139139
{
140140
//更新sokect连接状态
141-
_connectStatus = SocketConnectStatus_DisconnectByUser;
141+
_connectStatus = SocketConnectStatus_UnConnected;
142142
[self disconnect];
143143
}
144144

@@ -288,8 +288,8 @@ - (void)socketDidSecure:(GCDAsyncSocket *)sock
288288
#pragma mark - TCP已经断开连接
289289
- (void)socketDidDisconnect:(GCDAsyncSocket *)sock withError:(NSError *)err
290290
{
291-
//如果是主动断开连接
292-
if (_connectStatus == SocketConnectStatus_DisconnectByUser) return;
291+
// //如果是主动断开连接
292+
// if (_connectStatus == SocketConnectStatus_DisconnectByUser) return;
293293
//置为未连接状态
294294
_connectStatus = SocketConnectStatus_UnConnected;
295295
//自动重连
@@ -320,7 +320,7 @@ - (NSTimeInterval)socket:(GCDAsyncSocket *)sock shouldTimeoutWriteWithTag:(long)
320320
#pragma mark - 网络监听
321321
- (void)networkChanged:(NSNotification *)notification {
322322

323-
if (_connectStatus == SocketConnectStatus_DisconnectByUser) return; //主动断开连接
323+
// if (_connectStatus == SocketConnectStatus_DisconnectByUser) return; //主动断开连接
324324

325325
if (networkStatus == RealStatusNotReachable||_connectStatus == SocketConnectStatus_UnConnected) {
326326
[self serverInterruption];//断开连接,默认还会重连3次 ,还未连接自动断开
@@ -333,4 +333,125 @@ - (void)networkChanged:(NSNotification *)notification {
333333

334334

335335

336+
#pragma mark - 消息发送
337+
//发送文本消息
338+
- (void)sendTextMessage:(ChatModel *)textModel
339+
{
340+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
341+
342+
//模拟回执
343+
ChatModel *receipet = [[ChatModel alloc]init];
344+
receipet.messageType = Message_NormalReceipt;
345+
receipet.sendTime = textModel.sendTime;
346+
ChatMessageType type = ChatMessageType_NormalReceipt;
347+
for (id<ChatHandlerDelegate>delegate in self.delegates) {
348+
if ([delegate respondsToSelector:@selector(didReceiveMessage:type:)]) {
349+
[delegate didReceiveMessage:receipet type:type];
350+
}
351+
}
352+
});
353+
354+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
355+
356+
//模拟回复
357+
ChatModel *reply = [[ChatModel alloc]init];
358+
ChatContentModel *content = [[ChatContentModel alloc]init];
359+
reply.content = content;
360+
reply.content.text = @"收到文本内容";
361+
reply.messageType = Message_Normal;
362+
reply.contenType = Content_Text;
363+
reply.toUserID = textModel.fromUserID;
364+
reply.chatType = @"userChat";
365+
ChatMessageType type = ChatMessageType_Normal;
366+
for (id<ChatHandlerDelegate>delegate in self.delegates) {
367+
if ([delegate respondsToSelector:@selector(didReceiveMessage:type:)]) {
368+
[delegate didReceiveMessage:reply type:type];
369+
}
370+
}
371+
});
372+
}
373+
374+
//发送语音消息
375+
- (void)sendAudioMessage:(ChatModel *)audioModel
376+
{
377+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
378+
379+
//模拟回执
380+
ChatModel *receipet = [[ChatModel alloc]init];
381+
receipet.messageType = Message_NormalReceipt;
382+
receipet.sendTime = audioModel.sendTime;
383+
ChatMessageType type = ChatMessageType_NormalReceipt;
384+
for (id<ChatHandlerDelegate>delegate in self.delegates) {
385+
if ([delegate respondsToSelector:@selector(didReceiveMessage:type:)]) {
386+
[delegate didReceiveMessage:receipet type:type];
387+
}
388+
}
389+
});
390+
391+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
392+
393+
//模拟回复
394+
ChatModel *reply = [[ChatModel alloc]init];
395+
ChatContentModel *content = [[ChatContentModel alloc]init];
396+
reply.content = content;
397+
reply.content.text = @"收到语音";
398+
reply.messageType = Message_Normal;
399+
reply.contenType = Content_Text;
400+
reply.toUserID = audioModel.fromUserID;
401+
reply.chatType = @"userChat";
402+
ChatMessageType type = ChatMessageType_Normal;
403+
for (id<ChatHandlerDelegate>delegate in self.delegates) {
404+
if ([delegate respondsToSelector:@selector(didReceiveMessage:type:)]) {
405+
[delegate didReceiveMessage:reply type:type];
406+
}
407+
}
408+
});
409+
}
410+
411+
//发送图片消息
412+
- (void)sendPicMessage:(NSArray<ChatModel *>*)picModels
413+
{
414+
415+
[picModels enumerateObjectsUsingBlock:^(ChatModel * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
416+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
417+
418+
//模拟回执
419+
ChatModel *receipet = [[ChatModel alloc]init];
420+
receipet.messageType = Message_NormalReceipt;
421+
receipet.sendTime = obj.sendTime;
422+
ChatMessageType type = ChatMessageType_NormalReceipt;
423+
for (id<ChatHandlerDelegate>delegate in self.delegates) {
424+
if ([delegate respondsToSelector:@selector(didReceiveMessage:type:)]) {
425+
[delegate didReceiveMessage:receipet type:type];
426+
}
427+
}
428+
});
429+
430+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
431+
432+
//模拟回复
433+
ChatModel *reply = [[ChatModel alloc]init];
434+
ChatContentModel *content = [[ChatContentModel alloc]init];
435+
reply.content = content;
436+
reply.content.text = @"收到图片";
437+
reply.messageType = Message_Normal;
438+
reply.contenType = Content_Text;
439+
reply.toUserID = obj.fromUserID;
440+
reply.chatType = @"userChat";
441+
ChatMessageType type = ChatMessageType_Normal;
442+
for (id<ChatHandlerDelegate>delegate in self.delegates) {
443+
if ([delegate respondsToSelector:@selector(didReceiveMessage:type:)]) {
444+
[delegate didReceiveMessage:reply type:type];
445+
}
446+
}
447+
});
448+
}];
449+
}
450+
451+
//发送视频消息
452+
- (void)sendVideoMessage:(ChatModel *)videoModel
453+
{
454+
}
455+
456+
336457
@end

CocoaAsyncSocket_TCP/ChatHandler/ChatUtil.m

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ + (CGFloat)heightForMessage:(ChatModel *)currentChatmodel premodel:(ChatModel *)
4545
[coreLabel setText:currentChatmodel.content.text customLinks:nil keywords:nil];
4646
CGSize labelSize = [coreLabel sizeThatFits:CGSizeMake(SCREEN_WITDTH - 145, MAXFLOAT)];
4747
height = 5 + 10 + labelSize.height + 10;
48+
height = height < 50 ? 50 : height;
4849
//验证是否群聊
4950
[self groupChatConfig:currentChatmodel];
5051
return currentChatmodel.messageHeight += currentChatmodel.shouldShowTime ? height + 50 : height + 15;
@@ -123,7 +124,7 @@ + (ChatModel *)creatMessageModel:(ChatModel *)config
123124
chatModel.beatID = TCP_beatBody;
124125
chatModel.fromPortrait = [Account account].portrait;
125126
chatModel.toPortrait = config.toPortrait;
126-
chatModel.toNickName = config.toNickName;
127+
chatModel.nickName = config.nickName;
127128
chatModel.groupID = config.groupID;
128129
chatModel.groupName = config.groupName;
129130
chatModel.noDisturb = config.noDisturb;
@@ -145,7 +146,8 @@ + (ChatModel *)initAudioMessage:(ChatAlbumModel *)audio config:(ChatModel *)conf
145146
ChatModel *audioModel = [self creatMessageModel:config];
146147
audioModel.contenType = Content_Audio;
147148
audioModel.content.seconds = audio.duration;
148-
149+
NSString *name = [NSString stringWithFormat:@"ChatAudio_%@.mp3",audioModel.sendTime];
150+
audioModel.content.fileName = name;
149151
NSString *basePath = nil;
150152
if (hashEqual(config.chatType, @"userChat")) {
151153
basePath = [ChatCache_Path stringByAppendingPathComponent:config.toUserID];
@@ -159,7 +161,6 @@ + (ChatModel *)initAudioMessage:(ChatAlbumModel *)audio config:(ChatModel *)conf
159161
[manager createDirectoryAtPath:basePath withIntermediateDirectories:YES attributes:nil error:NULL];
160162
}
161163
//语音写入缓存
162-
NSString *name = [NSString stringWithFormat:@"ChatAudio_%@.mp3",audioModel.sendTime];
163164
[audio.audioData writeToFile:[basePath stringByAppendingPathComponent:name] atomically:YES];
164165
return audioModel;
165166
}

CocoaAsyncSocket_TCP/ChatModel/ChatModel.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ typedef NS_ENUM(NSInteger) {
2626

2727
SocketConnectStatus_UnConnected = 0<<0,//未连接状态
2828
SocketConnectStatus_Connected = 1<<0,//连接状态
29-
SocketConnectStatus_DisconnectByUser = 2<<0,//主动断开连接
29+
// SocketConnectStatus_DisconnectByUser = 2<<0,//主动断开连接
3030
SocketConnectStatus_Unknow = 3<<0 //未知
3131

3232
}SocketConnectStatus;
@@ -71,7 +71,7 @@ typedef NS_ENUM(NSInteger){
7171

7272
@property (nonatomic, copy) NSString *toPortrait; //对方头像url
7373

74-
@property (nonatomic, copy) NSString *toNickName; //我对好友命名的昵称
74+
@property (nonatomic, copy) NSString *nickName; //我对好友命名的昵称
7575

7676
@property (nonatomic, copy) NSArray<NSString *> *atToUserIDs; // @目标ID
7777

CocoaAsyncSocket_TCP/Comon/.DS_Store

-2 KB
Binary file not shown.

CocoaAsyncSocket_TCP/Comon/Account/Account.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@
3838

3939
@property (nonatomic ,copy) NSString *lastLoginTime; //最后登录时间
4040

41+
@property (nonatomic, copy) NSString *nickName; //我的昵称
42+
4143
@property (nonatomic, copy) NSString *portrait; //头像url
4244

4345
/*

CocoaAsyncSocket_TCP/Comon/Constant.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,16 @@ static NSString *ChatlistTitle = @"聊天列表"; //聊天列表标
5757
static NSString *ChatKeyboardResign = @"ChatKeyboardShouldResignFirstResponder"; //键盘失去第一响应者
5858

5959

60+
/*
61+
enum
62+
*/
63+
64+
//长按消息操作类型
65+
typedef NS_ENUM(NSInteger,LongpressSelectHandleType){
66+
LongpressSelectHandleTypeBack = 0<<0, //撤回
67+
LongpressSelectHandleTypeDelete = 1<<0, //删除
68+
LongpressSelectHandleTypeTransmit = 2<<0 //转发
69+
};
6070

6171

6272

CocoaAsyncSocket_TCP/Controller/ChatListViewController.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ - (void)getMessages
133133
ChatModel *chatModel = [[ChatModel alloc]init];
134134
ChatContentModel *chatContent = [[ChatContentModel alloc]init];
135135
chatModel.content = chatContent ;
136-
chatModel.toNickName = @"孟遥";
136+
chatModel.nickName = @"孟遥";
137137
if (index<tips.count) {
138138
chatModel.lastMessage = tips[index];
139139
}else{

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy