@@ -402,6 +402,12 @@ public class IMConversation {
402402 public func countMembers( completion: @escaping ( LCCountResult ) -> Void ) {
403403 self . _countMembers ( completion: completion)
404404 }
405+
406+ /// Check whether *client* joined this conversation.
407+ /// - Parameter completion: Result callback.
408+ public func checkJoined( completion: @escaping ( LCGenericResult < Bool > ) -> Void ) {
409+ self . _checkJoined ( completion: completion)
410+ }
405411
406412 /// Mute this conversation.
407413 ///
@@ -1711,6 +1717,52 @@ extension IMConversation {
17111717 }
17121718 }
17131719 }
1720+
1721+ func _checkJoined( completion: @escaping ( LCGenericResult < Bool > ) -> Void ) {
1722+ self . client? . sendCommand ( constructor: { ( ) -> IMGenericCommand in
1723+ var outCommand = IMGenericCommand ( )
1724+ outCommand. cmd = . conv
1725+ outCommand. op = . isMember
1726+ var convCommand = IMConvCommand ( )
1727+ convCommand. cids = [ self . ID]
1728+ outCommand. convMessage = convCommand
1729+ return outCommand
1730+ } , completion: { ( client, result) in
1731+ switch result {
1732+ case . inCommand( let inCommand) :
1733+ assert ( client. specificAssertion)
1734+ do {
1735+ if let convMessage = ( inCommand. hasConvMessage ? inCommand. convMessage : nil ) ,
1736+ let jsonObject = ( convMessage. hasResults ? convMessage. results : nil ) ,
1737+ let dataString = ( jsonObject. hasData ? jsonObject. data : nil ) ,
1738+ let results: [ String : Any ] = try dataString. jsonObject ( ) ,
1739+ let boolValue = results [ self . ID] as? Bool {
1740+ client. eventQueue. async {
1741+ completion ( . success(
1742+ value: boolValue) )
1743+ }
1744+ } else {
1745+ client. eventQueue. async {
1746+ completion ( . failure(
1747+ error: LCError (
1748+ code: . commandInvalid) ) )
1749+ }
1750+ }
1751+ } catch {
1752+ client. eventQueue. async {
1753+ completion ( . failure(
1754+ error: LCError (
1755+ error: error) ) )
1756+ }
1757+ }
1758+ case . error( let error) :
1759+ client. eventQueue. async {
1760+ completion ( . failure(
1761+ error: error) )
1762+ }
1763+ }
1764+ } )
1765+ }
17141766}
17151767
17161768extension IMConversation {
@@ -2744,6 +2796,11 @@ public class IMChatRoom: IMConversation {
27442796 case normal = 2
27452797 case low = 3
27462798 }
2799+
2800+ @available ( * , unavailable)
2801+ public override func checkJoined( completion: @escaping ( LCGenericResult < Bool > ) -> Void ) {
2802+ completion ( . failure( error: LCError . conversationNotSupport ( convType: type ( of: self ) ) ) )
2803+ }
27472804
27482805 @available ( * , unavailable)
27492806 public override func read( message: IMMessage ? = nil ) { }
@@ -2917,52 +2974,12 @@ public class IMServiceConversation: IMConversation {
29172974 public func unsubscribe( completion: @escaping ( LCBooleanResult ) -> Void ) throws {
29182975 try self . leave ( completion: completion)
29192976 }
2920-
2921- /// Check whether subscribed this Service Conversation.
2922- ///
2923- /// - Parameter completion: callback, dispatch to client.eventQueue .
2977+
2978+ /// Check whether *client* subscribed this conversation.
2979+ /// - Parameter completion: Result callback.
29242980 public func checkSubscription( completion: @escaping ( LCGenericResult < Bool > ) -> Void ) {
2925- self . client? . sendCommand ( constructor: { ( ) -> IMGenericCommand in
2926- var outCommand = IMGenericCommand ( )
2927- outCommand. cmd = . conv
2928- outCommand. op = . isMember
2929- var convCommand = IMConvCommand ( )
2930- convCommand. cids = [ self . ID]
2931- outCommand. convMessage = convCommand
2932- return outCommand
2933- } , completion: { ( client, result) in
2934- switch result {
2935- case . inCommand( let inCommand) :
2936- assert ( client. specificAssertion)
2937- do {
2938- if
2939- let convMessage = ( inCommand. hasConvMessage ? inCommand. convMessage : nil ) ,
2940- let jsonObject = ( convMessage. hasResults ? convMessage. results : nil ) ,
2941- let dataString = ( jsonObject. hasData ? jsonObject. data : nil ) ,
2942- let results: [ String : Any ] = try dataString. jsonObject ( ) ,
2943- let boolValue: Bool = results [ self . ID] as? Bool
2944- {
2945- client. eventQueue. async {
2946- completion ( . success( value: boolValue) )
2947- }
2948- } else {
2949- client. eventQueue. async {
2950- completion ( . failure( error: LCError ( code: . commandInvalid) ) )
2951- }
2952- }
2953- } catch {
2954- client. eventQueue. async {
2955- completion ( . failure( error: LCError ( error: error) ) )
2956- }
2957- }
2958- case . error( let error) :
2959- client. eventQueue. async {
2960- completion ( . failure( error: error) )
2961- }
2962- }
2963- } )
2981+ self . _checkJoined ( completion: completion)
29642982 }
2965-
29662983}
29672984
29682985/// IM Temporary Conversation
@@ -3005,9 +3022,15 @@ public class IMTemporaryConversation: IMConversation {
30053022 throw LCError . conversationNotSupport ( convType: type ( of: self ) )
30063023 }
30073024
3025+ @available ( * , unavailable)
30083026 public override func countMembers( completion: @escaping ( LCCountResult ) -> Void ) {
30093027 completion ( . failure( error: LCError . conversationNotSupport ( convType: type ( of: self ) ) ) )
30103028 }
3029+
3030+ @available ( * , unavailable)
3031+ public override func checkJoined( completion: @escaping ( LCGenericResult < Bool > ) -> Void ) {
3032+ completion ( . failure( error: LCError . conversationNotSupport ( convType: type ( of: self ) ) ) )
3033+ }
30113034
30123035 @available ( * , unavailable)
30133036 public override func mute( completion: @escaping ( LCBooleanResult ) -> Void ) {
0 commit comments