@@ -10,45 +10,16 @@ import UIKit
1010import EaseChatUIKit
1111
1212class CustomMessageListController : MessageListController {
13-
14- override func processFollowInputAttachmentAction( ) {
15- if Appearance . chat. messageAttachmentMenuStyle == . followInput {
16- if let fileItem = Appearance . chat. inputExtendActions. first ( where: { $0. tag == " File " } ) {
17- fileItem. action = { [ weak self] item, object in
18- self ? . handleAttachmentAction ( item: item)
19- }
20- }
21- if let photoItem = Appearance . chat. inputExtendActions. first ( where: { $0. tag == " Photo " } ) {
22- photoItem. action = { [ weak self] item, object in
23- self ? . handleAttachmentAction ( item: item)
24- }
25- }
26- if let cameraItem = Appearance . chat. inputExtendActions. first ( where: { $0. tag == " Camera " } ) {
27- cameraItem. action = { [ weak self] item, object in
28- self ? . handleAttachmentAction ( item: item)
29- }
30- }
31- if let contactItem = Appearance . chat. inputExtendActions. first ( where: { $0. tag == " Contact " } ) {
32- contactItem. action = { [ weak self] item, object in
33- self ? . handleAttachmentAction ( item: item)
34- }
35- }
36- if let redPackageItem = Appearance . chat. inputExtendActions. first ( where: { $0. tag == " Red " } ) {
37- redPackageItem. action = { [ weak self] item, object in
38- self ? . handleAttachmentAction ( item: item)
39- }
40- }
41-
42- }
43- }
44-
13+
4514 override func handleAttachmentAction( item: any ActionSheetItemProtocol ) {
4615 switch item. tag {
4716 case " File " : self . selectFile ( )
4817 case " Photo " : self . selectPhoto ( )
4918 case " Camera " : self . openCamera ( )
5019 case " Contact " : self . selectContact ( )
5120 case " Red " : self . redPackageMessage ( )
21+ case " Gift " : self . giftMessage ( )
22+ case " Music " : self . musicMessage ( )
5223 default :
5324 break
5425 }
@@ -58,19 +29,31 @@ class CustomMessageListController: MessageListController {
5829 self . viewModel. sendRedPackageMessage ( )
5930 }
6031
32+ private func giftMessage( ) {
33+ self . viewModel. sendGiftMessage ( )
34+ }
35+
36+ private func musicMessage( ) {
37+ self . viewModel. sendMusicMessage ( )
38+ }
39+
6140}
6241
6342let redPackageIdentifier = " redPackage "
6443
44+ let giftIdentifier = " gift "
45+
46+ let musicIdentifier = " music "
47+
6548extension MessageListViewModel {
6649 func sendRedPackageMessage( ) {
6750 var ext = Dictionary < String , Any > ( )
68- ext [ " something " ] = " 发红包 "
51+ ext [ " something " ] = " Send Red Package "
6952 let json = ChatUIKitContext . shared? . currentUser? . toJsonObject ( ) ?? [ : ]
7053 ext. merge ( json) { _, new in
7154 new
7255 }
73- let chatMessage = ChatMessage ( conversationID: self . to, body: ChatCustomMessageBody ( event: redPackageIdentifier, customExt: [ " money " : " 20 " , " name " : " 张三 " , " message " : " 恭喜发财大吉大利 " ] ) , ext: ext)
56+ let chatMessage = ChatMessage ( conversationID: self . to, body: ChatCustomMessageBody ( event: redPackageIdentifier, customExt: [ " money " : " 20 " , " name " : " zhangsan " , " message " : " Hello World " ] ) , ext: ext)
7457 self . driver? . showMessage ( message: chatMessage)
7558 self . chatService? . send ( message: chatMessage) { [ weak self] error, message in
7659 if error == nil {
@@ -86,6 +69,51 @@ extension MessageListViewModel {
8669 }
8770 }
8871
72+ func sendGiftMessage( ) {
73+ var ext = Dictionary < String , Any > ( )
74+ ext [ " something " ] = " Send Gift "
75+ let json = ChatUIKitContext . shared? . currentUser? . toJsonObject ( ) ?? [ : ]
76+ ext. merge ( json) { _, new in
77+ new
78+ }
79+ let chatMessage = ChatMessage ( conversationID: self . to, body: ChatCustomMessageBody ( event: giftIdentifier, customExt: [ " gift " : " gift " ] ) , ext: ext)
80+ self . driver? . showMessage ( message: chatMessage)
81+ self . chatService? . send ( message: chatMessage) { [ weak self] error, message in
82+ if error == nil {
83+ if let message = message {
84+ self ? . driver? . updateMessageStatus ( message: message, status: . succeed)
85+ }
86+ } else {
87+ consoleLogInfo ( " send text message failure: \( error? . errorDescription ?? " " ) " , type: . error)
88+ if let message = message {
89+ self ? . driver? . updateMessageStatus ( message: message, status: . failure)
90+ }
91+ }
92+ }
93+ }
94+
95+ func sendMusicMessage( ) {
96+ var ext = Dictionary < String , Any > ( )
97+ ext [ " something " ] = " Send music "
98+ let json = ChatUIKitContext . shared? . currentUser? . toJsonObject ( ) ?? [ : ]
99+ ext. merge ( json) { _, new in
100+ new
101+ }
102+ let chatMessage = ChatMessage ( conversationID: self . to, body: ChatCustomMessageBody ( event: musicIdentifier, customExt: [ " music " : " music " ] ) , ext: ext)
103+ self . driver? . showMessage ( message: chatMessage)
104+ self . chatService? . send ( message: chatMessage) { [ weak self] error, message in
105+ if error == nil {
106+ if let message = message {
107+ self ? . driver? . updateMessageStatus ( message: message, status: . succeed)
108+ }
109+ } else {
110+ consoleLogInfo ( " send text message failure: \( error? . errorDescription ?? " " ) " , type: . error)
111+ if let message = message {
112+ self ? . driver? . updateMessageStatus ( message: message, status: . failure)
113+ }
114+ }
115+ }
116+ }
89117
90118}
91119
0 commit comments