Merge pull request #35 from erlangzhang/main

[Add] new add ios support
main
hrxiang 4 years ago committed by GitHub
commit de57d7254f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. BIN
      .DS_Store
  2. 4
      .gitignore
  3. 68
      example/ios/Runner.xcodeproj/project.pbxproj
  4. 3
      example/ios/Runner.xcworkspace/contents.xcworkspacedata
  5. 2
      example/pubspec.lock
  6. 27
      ios/Classes/BaseCallback.swift
  7. 301
      ios/Classes/CommonUtil.swift
  8. 3
      ios/Classes/JsonUtil.swift
  9. 50
      ios/Classes/Module/BaseServiceManager.swift
  10. 59
      ios/Classes/Module/ConversationManager.swift
  11. 68
      ios/Classes/Module/FriendshipManager.swift
  12. 96
      ios/Classes/Module/GroupManager.swift
  13. 60
      ios/Classes/Module/IMManager.swift
  14. 252
      ios/Classes/Module/MessageManager.swift
  15. 236
      ios/Classes/SwiftFlutterOpenimSdkPlugin.swift
  16. 23
      ios/Classes/Util/Any+Extension.swift
  17. 109
      ios/Classes/Util/FlutterMethodCall+Extension.swift

BIN
.DS_Store vendored

Binary file not shown.

4
.gitignore vendored

@ -0,0 +1,4 @@
.DS_Store
/.packages
/.dart_tool
/example/ios/Podfile.lock

@ -9,6 +9,7 @@
/* Begin PBXBuildFile section */
1498D2341E8E89220040F4C2 /* GeneratedPluginRegistrant.m in Sources */ = {isa = PBXBuildFile; fileRef = 1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
6F7F8B794B6D663E7A65A104 /* Pods_Runner.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 1971A63CCEC4B744C25980F8 /* Pods_Runner.framework */; };
74858FAF1ED2DC5600515810 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 74858FAE1ED2DC5600515810 /* AppDelegate.swift */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
97C146FE1CF9000F007C117D /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FD1CF9000F007C117D /* Assets.xcassets */; };
@ -29,12 +30,16 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
076751BE520B721535096B75 /* Pods-Runner.profile.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.profile.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.profile.xcconfig"; sourceTree = "<group>"; };
1498D2321E8E86230040F4C2 /* GeneratedPluginRegistrant.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = GeneratedPluginRegistrant.h; sourceTree = "<group>"; };
1498D2331E8E89220040F4C2 /* GeneratedPluginRegistrant.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = GeneratedPluginRegistrant.m; sourceTree = "<group>"; };
1971A63CCEC4B744C25980F8 /* Pods_Runner.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Runner.framework; sourceTree = BUILT_PRODUCTS_DIR; };
3A6AB9CCD90A2F5C2CE719D0 /* Pods-Runner.release.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.release.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"; sourceTree = "<group>"; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "<group>"; };
74858FAD1ED2DC5600515810 /* Runner-Bridging-Header.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = "Runner-Bridging-Header.h"; sourceTree = "<group>"; };
74858FAE1ED2DC5600515810 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
7AFA3C8E1D35360C0083082E /* Release.xcconfig */ = {isa = PBXFileReference; lastKnownFileType = text.xcconfig; name = Release.xcconfig; path = Flutter/Release.xcconfig; sourceTree = "<group>"; };
7CF14C3CACE83F04F858C9EC /* Pods-Runner.debug.xcconfig */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = text.xcconfig; name = "Pods-Runner.debug.xcconfig"; path = "Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"; sourceTree = "<group>"; };
9740EEB21CF90195004384FC /* Debug.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Debug.xcconfig; path = Flutter/Debug.xcconfig; sourceTree = "<group>"; };
9740EEB31CF90195004384FC /* Generated.xcconfig */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.xcconfig; name = Generated.xcconfig; path = Flutter/Generated.xcconfig; sourceTree = "<group>"; };
97C146EE1CF9000F007C117D /* Runner.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Runner.app; sourceTree = BUILT_PRODUCTS_DIR; };
@ -49,12 +54,21 @@
isa = PBXFrameworksBuildPhase;
buildActionMask = 2147483647;
files = (
6F7F8B794B6D663E7A65A104 /* Pods_Runner.framework in Frameworks */,
);
runOnlyForDeploymentPostprocessing = 0;
};
/* End PBXFrameworksBuildPhase section */
/* Begin PBXGroup section */
4B877210D623EE0FDE18A08F /* Frameworks */ = {
isa = PBXGroup;
children = (
1971A63CCEC4B744C25980F8 /* Pods_Runner.framework */,
);
name = Frameworks;
sourceTree = "<group>";
};
9740EEB11CF90186004384FC /* Flutter */ = {
isa = PBXGroup;
children = (
@ -72,6 +86,8 @@
9740EEB11CF90186004384FC /* Flutter */,
97C146F01CF9000F007C117D /* Runner */,
97C146EF1CF9000F007C117D /* Products */,
E653626F5A38799455FF26C4 /* Pods */,
4B877210D623EE0FDE18A08F /* Frameworks */,
);
sourceTree = "<group>";
};
@ -98,6 +114,17 @@
path = Runner;
sourceTree = "<group>";
};
E653626F5A38799455FF26C4 /* Pods */ = {
isa = PBXGroup;
children = (
7CF14C3CACE83F04F858C9EC /* Pods-Runner.debug.xcconfig */,
3A6AB9CCD90A2F5C2CE719D0 /* Pods-Runner.release.xcconfig */,
076751BE520B721535096B75 /* Pods-Runner.profile.xcconfig */,
);
name = Pods;
path = Pods;
sourceTree = "<group>";
};
/* End PBXGroup section */
/* Begin PBXNativeTarget section */
@ -105,12 +132,14 @@
isa = PBXNativeTarget;
buildConfigurationList = 97C147051CF9000F007C117D /* Build configuration list for PBXNativeTarget "Runner" */;
buildPhases = (
FA9CAD2EF743D14467F7D993 /* [CP] Check Pods Manifest.lock */,
9740EEB61CF901F6004384FC /* Run Script */,
97C146EA1CF9000F007C117D /* Sources */,
97C146EB1CF9000F007C117D /* Frameworks */,
97C146EC1CF9000F007C117D /* Resources */,
9705A1C41CF9048500538489 /* Embed Frameworks */,
3B06AD1E1E4923F5004D2608 /* Thin Binary */,
215A1CA82008A326A8ECBF65 /* [CP] Embed Pods Frameworks */,
);
buildRules = (
);
@ -169,6 +198,23 @@
/* End PBXResourcesBuildPhase section */
/* Begin PBXShellScriptBuildPhase section */
215A1CA82008A326A8ECBF65 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-input-files.xcfilelist",
);
name = "[CP] Embed Pods Frameworks";
outputFileListPaths = (
"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks-${CONFIGURATION}-output-files.xcfilelist",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${PODS_ROOT}/Target Support Files/Pods-Runner/Pods-Runner-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3B06AD1E1E4923F5004D2608 /* Thin Binary */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
@ -197,6 +243,28 @@
shellPath = /bin/sh;
shellScript = "/bin/sh \"$FLUTTER_ROOT/packages/flutter_tools/bin/xcode_backend.sh\" build";
};
FA9CAD2EF743D14467F7D993 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputFileListPaths = (
);
inputPaths = (
"${PODS_PODFILE_DIR_PATH}/Podfile.lock",
"${PODS_ROOT}/Manifest.lock",
);
name = "[CP] Check Pods Manifest.lock";
outputFileListPaths = (
);
outputPaths = (
"$(DERIVED_FILE_DIR)/Pods-Runner-checkManifestLockResult.txt",
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_PODFILE_DIR_PATH}/Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [ $? != 0 ] ; then\n # print error to STDERR\n echo \"error: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\" >&2\n exit 1\nfi\n# This output is used by Xcode 'outputs' to avoid re-running this script phase.\necho \"SUCCESS\" > \"${SCRIPT_OUTPUT_FILE_0}\"\n";
showEnvVarsInLog = 0;
};
/* End PBXShellScriptBuildPhase section */
/* Begin PBXSourcesBuildPhase section */

@ -4,4 +4,7 @@
<FileRef
location = "group:Runner.xcodeproj">
</FileRef>
<FileRef
location = "group:Pods/Pods.xcodeproj">
</FileRef>
</Workspace>

@ -68,7 +68,7 @@ packages:
path: ".."
relative: true
source: path
version: "0.0.6"
version: "0.0.8+1"
flutter_test:
dependency: "direct dev"
description: flutter

@ -0,0 +1,27 @@
//
// BaseCallback.swift
// flutter_openim_sdk
//
// Created by willem on 2021/10/9.
//
import Foundation
import OpenIMCore
public class BaseCallback: NSObject, Open_im_sdkBaseProtocol {
private let result:FlutterResult
init(result:@escaping FlutterResult) {
self.result = result
}
public func onError(_ errCode: Int, errMsg: String?) {
print("BaseResult: " + errMsg!)
safeMainAsync { self.result(FlutterError(code: "\(errCode)", message: errMsg, details: nil)) }
}
public func onSuccess(_ data: String?) {
safeMainAsync { self.result(data) }
}
}

@ -4,24 +4,6 @@ import Foundation
public class CommonUtil {
public static func getParamValue(methodCall:FlutterMethodCall, param: String)->Any? {
let argument = methodCall.arguments as! NSDictionary
let arg = argument.value(forKey: param)
return arg;
}
public static func getSDKJsonParam(methodCall: FlutterMethodCall, key: String) -> String{
let argument = methodCall.arguments as! NSDictionary
let arg = argument.value(forKey: key) as AnyObject
return JsonUtil.toString(object: arg);
}
public static func getSDKJsonParam(methodCall: FlutterMethodCall) -> String{
let argument = methodCall.arguments as AnyObject
let s = JsonUtil.toString(object: argument)
return s
}
public static func emitEvent(channel: FlutterMethodChannel, method: String, type: String, errCode: Int?, errMsg: String?, data: Any?){
DispatchQueue.main.async {
let res: NSMutableDictionary = NSMutableDictionary(capacity: 0)
@ -39,287 +21,4 @@ public class CommonUtil {
channel.invokeMethod(method, arguments: res)
}
}
public static func getUid(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_UID) as! String
return result
}
public static func getJsonUid(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_UID) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getToken(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_TOKEN) as! String
return result
}
public static func getUidList(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_USER_IDS) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getMessageText(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_TEXT) as! String
return result
}
public static func getAtUserList(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_AT_USER_LIST) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getImagePath(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_IMAGE_PATH) as! String
return result
}
public static func getSoundPath(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_SOUND_PATH) as! String
return result
}
public static func getSoundDuration(methodCall: FlutterMethodCall)->Int64{
let result: Int64 = getParamValue(methodCall: methodCall, param: KEY_SOUND_DURATION) as! Int64
return result
}
public static func getVideoPath(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_VIDEO_PATH) as! String
return result
}
public static func getVideoType(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_VIDEO_TYPE) as! String
return result
}
public static func getVideoDuration(methodCall: FlutterMethodCall)->Int64{
let result: Int64 = getParamValue(methodCall: methodCall, param: KEY_VIDEO_DURATION) as! Int64
return result
}
public static func getVideoSnapshotPath(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_VIDEO_SNAPSHOT_PATH) as! String
return result
}
public static func getFilePath(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_FILE_PATH) as! String
return result
}
public static func getFileName(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_FILE_NAME) as! String
return result
}
public static func getMergerMessageList(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_MERGER_MESSAGE_LIST) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getMergerMessageTitle(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_MERGER_MESSAGE_TITLE) as! String
return result
}
public static func getSummaryList(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_SUMMARY_LIST) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getForwardMessage(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_FORWARD_MESSAGE) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getSendMessageContent(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_SEND_MESSAGE_CONTENT)
if result is NSDictionary && result != nil {
return JsonUtil.toString(object: result as? NSDictionary)
}
return result as! String
}
public static func getSendMessageClientMsgID(methodCall: FlutterMethodCall)->String{
let r = getParamValue(methodCall: methodCall, param: KEY_SEND_MESSAGE_CONTENT) as! NSDictionary
let result = r.value(forKey: KEY_SEND_MESSAGE_CONTENT_CLIENT_ID)
return result as! String
}
public static func getSendMessageReceiver(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_SEND_MESSAGE_RECEIVER) as! String
return result
}
public static func getSendMessageGroupId(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_SEND_MESSAGE_GROUP_ID) as! String
return result
}
public static func getSendMessageOnlineOnly(methodCall: FlutterMethodCall)->Bool{
let result: Int = getParamValue(methodCall: methodCall, param: KEY_SEND_MESSAGE_ONLINE_ONLY) as! Int
return (result != 0)
}
public static func getSingleMessageContent(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_SINGLE_MESSAGE_CONTENT) as! String
return result
}
public static func getSingleMessageUserid(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_SINGLE_MESSAGE_USERID) as! String
return result
}
public static func getGroupMessageGroupid(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_GROUP_MESSAGE_GROUPID) as! String
return result
}
public static func getSingleMessageSender(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_SINGLE_MESSAGE_SENDER) as! String
return result
}
public static func getFindMessageIds(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_FIND_MESSAGE_IDS) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getConversationId(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_CONVERSATION_ID) as! String
return result
}
public static func getConversationIds(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_CONVERSATION_IDS) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getConversationSourceId(methodCall: FlutterMethodCall)->String {
let result: String = getParamValue(methodCall: methodCall, param: KEY_CONVERSATION_SOURCE_ID) as! String;
return result
}
public static func getConversationSessionType(methodCall: FlutterMethodCall)->Int{
let result: Int = getParamValue(methodCall: methodCall, param: KEY_CONVERSATION_SESSION_TYPE) as! Int
return result
}
public static func getConversationDraft(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_CONVERSATION_DRAFT) as! String
return result
}
public static func isPinnedConversation(methodCall: FlutterMethodCall)->Bool{
let result: Int = getParamValue(methodCall: methodCall, param: KEY_SINGLE_MESSAGE_USERID) as! Int
return (result != 0)
}
public static func getGid(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_GROUP_ID) as! String
return result
}
public static func getGidList(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_GROUP_IDS) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getGroupOpReason(methodCall: FlutterMethodCall)->String{
let result: String = getParamValue(methodCall: methodCall, param: KEY_GROUP_OP_REASON) as! String
return result
}
public static func getGroupListFilter(methodCall: FlutterMethodCall)->Int32{
let result: Int32 = getParamValue(methodCall: methodCall, param: KEY_GROUP_LIST_FILTER) as! Int32
return result
}
public static func getGroupListNext(methodCall: FlutterMethodCall)->Int32{
let result: Int32 = getParamValue(methodCall: methodCall, param: KEY_GROUP_LIST_NEXT) as! Int32
return result
}
public static func getGroupInfo(methodCall: FlutterMethodCall)->String{
let result = getParamValue(methodCall: methodCall, param: KEY_GROUP_INFO) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getGroupMemberRoleList(methodCall: FlutterMethodCall)->String {
let result = getParamValue(methodCall: methodCall, param: KEY_GROUP_MEMBER_ROLE_LIST) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
public static func getGroupApplicationInfo(methodCall: FlutterMethodCall)->String {
let result = getParamValue(methodCall: methodCall, param: KEY_GROUP_APPLICATION_INFO) as AnyObject
let r = JsonUtil.toString(object: result)
return r
}
//login
private static let KEY_UID: String = "uid";
private static let KEY_TOKEN: String = "token";
//create message body
private static let KEY_TEXT: String = "text";
private static let KEY_AT_USER_LIST: String = "atUserList";
private static let KEY_IMAGE_PATH: String = "imagePath";
private static let KEY_SOUND_PATH: String = "soundPath";
private static let KEY_SOUND_DURATION: String = "duration";
private static let KEY_VIDEO_PATH: String = "videoPath";
private static let KEY_VIDEO_TYPE: String = "videoType";
private static let KEY_VIDEO_DURATION: String = "duration";
private static let KEY_VIDEO_SNAPSHOT_PATH: String = "snapshotPath";
private static let KEY_FILE_PATH: String = "filePath";
private static let KEY_FILE_NAME: String = "fileName";
private static let KEY_MERGER_MESSAGE_LIST: String = "messageList";
private static let KEY_MERGER_MESSAGE_TITLE: String = "title";
private static let KEY_SUMMARY_LIST: String = "summaryList";
private static let KEY_FORWARD_MESSAGE: String = "message";
//send message
private static let KEY_SEND_MESSAGE_CONTENT: String = "message";
private static let KEY_SEND_MESSAGE_CONTENT_CLIENT_ID: String = "clientMsgID";
private static let KEY_SEND_MESSAGE_RECEIVER: String = "receiver";
private static let KEY_SEND_MESSAGE_GROUP_ID: String = "groupID";
private static let KEY_SEND_MESSAGE_ONLINE_ONLY: String = "onlineUserOnly";
//single chat
private static let KEY_SINGLE_MESSAGE_CONTENT: String = "message";
private static let KEY_SINGLE_MESSAGE_USERID: String = "userID";
private static let KEY_SINGLE_MESSAGE_SENDER: String = "sender";
//group chat
private static let KEY_GROUP_MESSAGE_GROUPID: String = "groupID";
// find message
private static let KEY_FIND_MESSAGE_IDS: String = "messageIDList";
// conversation
private static let KEY_CONVERSATION_ID: String = "conversationID";
private static let KEY_CONVERSATION_IDS: String = "conversationIDList";
private static let KEY_CONVERSATION_DRAFT: String = "draftText";
private static let KEY_CONVERSATION_PINNED: String = "isPinned";
private static let KEY_CONVERSATION_SOURCE_ID: String = "sourceID";
private static let KEY_CONVERSATION_SESSION_TYPE: String = "sessionType";
// user info
private static let KEY_USER_IDS: String = "uidList";
// group
private static let KEY_GROUP_ID: String = "gid";
private static let KEY_GROUP_IDS: String = "gidList";
private static let KEY_GROUP_OP_REASON: String = "reason";
private static let KEY_GROUP_LIST_FILTER: String = "filter";
private static let KEY_GROUP_LIST_NEXT: String = "next";
private static let KEY_GROUP_INFO: String = "gInfo";
private static let KEY_GROUP_MEMBER_ROLE_LIST: String = "memberList";
private static let KEY_GROUP_APPLICATION_INFO: String = "application";
}

@ -9,7 +9,7 @@ import Foundation
public class JsonUtil {
public static func toString(object: AnyObject?)->String{
public static func toString(object: AnyObject?)->String {
if object == nil {
return "";
}
@ -23,5 +23,4 @@ public class JsonUtil {
let jsonStr = NSString(data: data!, encoding: String.Encoding.utf8.rawValue)
return jsonStr! as String
}
}

@ -0,0 +1,50 @@
//
// BaseServiceManager.swift
// flutter_openim_sdk
//
// Created by willem on 2021/10/9.
//
import Flutter
import OpenIMCore
import UIKit
public typealias ImHandler = (_ methodCall: FlutterMethodCall, _ result: @escaping FlutterResult) -> Void
open class BaseServiceManager {
public let channel: FlutterMethodChannel
private var methodHandlers: [String: ImHandler] = [:]
public init(channel: FlutterMethodChannel) {
self.channel = channel
self.registerHandlers()
}
public func handleMethod(call: FlutterMethodCall, result: @escaping FlutterResult) {
let method: String = call.method
guard let handler = methodHandlers[method] else {
print("Handle MethodName Error: \(typeName(self))'s method: [\(method)] not found")
return
}
handler(call, result)
}
public subscript(_ key: String) -> ImHandler? {
get {
methodHandlers[key]
}
set {
methodHandlers[key] = newValue
}
}
public func registerHandlers() {
}
public func callBack(_ result: @escaping FlutterResult, _ content: Any? = nil) {
safeMainAsync {
result(content)
}
}
}

@ -8,44 +8,73 @@
import Foundation
import OpenIMCore
public class ConversationManager:NSObject{
private let channel:FlutterMethodChannel
init(channel:FlutterMethodChannel) {
self.channel = channel
public class ConversationManager: BaseServiceManager {
public override func registerHandlers() {
super.registerHandlers()
self["setConversationListener"] = setConversationListener
self["getAllConversationList"] = getAllConversationList
self["getOneConversation"] = getOneConversation
self["getMultipleConversation"] = getMultipleConversation
self["deleteConversation"] = deleteConversation
self["setConversationDraft"] = setConversationDraft
self["pinConversation"] = pinConversation
self["markSingleMessageHasRead"] = markSingleMessageHasRead
self["markGroupMessageHasRead"] = markGroupMessageHasRead
self["getTotalUnreadMsgCount"] = getTotalUnreadMsgCount
self["getConversationIDBySessionType"] = getConversationIDBySessionType
}
func setConversationListener(methodCall: FlutterMethodCall, result: FlutterResult){
func setConversationListener(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkSetConversationListener(ConversationListener(channel: channel))
callBack(result)
}
func getAllConversationList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetAllConversationList(BaseImpl(result: result))
Open_im_sdkGetAllConversationList(BaseCallback(result: result))
}
func getOneConversation(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetOneConversation(CommonUtil.getConversationSourceId(methodCall: methodCall), CommonUtil.getConversationSessionType(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkGetOneConversation(methodCall[string: "sourceID"], methodCall[int: "sessionType"], BaseCallback(result: result))
}
func getMultipleConversation(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetMultipleConversation(CommonUtil.getConversationIds(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkGetMultipleConversation(methodCall[jsonString: "conversationIDList"], BaseCallback(result: result))
}
func deleteConversation(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkDeleteConversation(CommonUtil.getConversationId(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkDeleteConversation(methodCall[string: "conversationID"], BaseCallback(result: result))
}
func setConversationDraft(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkSetConversationDraft(CommonUtil.getConversationId(methodCall: methodCall), CommonUtil.getConversationDraft(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkSetConversationDraft(methodCall[string: "conversationID"], methodCall[string: "draftText"], BaseCallback(result: result))
}
func pinConversation(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkPinConversation(CommonUtil.getConversationId(methodCall: methodCall), CommonUtil.isPinnedConversation(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkPinConversation(methodCall[string: "conversationID"], methodCall[bool: "isPinned"], BaseCallback(result: result))
}
func markSingleMessageHasRead(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkMarkSingleMessageHasRead(BaseCallback(result: result), methodCall[string: "userID"])
}
func markGroupMessageHasRead(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkMarkGroupMessageHasRead(BaseCallback(result: result), methodCall[string: "groupID"])
}
func getTotalUnreadMsgCount(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetTotalUnreadMsgCount(BaseCallback(result: result))
}
func getConversationIDBySessionType(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let conversationID = Open_im_sdkGetConversationIDBySessionType(methodCall[string: "sourceID"], methodCall[int: "sessionType"])
callBack(result, conversationID)
}
}
public class ConversationListener:NSObject,Open_im_sdkOnConversationListenerProtocol {
public class ConversationListener: NSObject, Open_im_sdkOnConversationListenerProtocol {
private let channel:FlutterMethodChannel
@ -76,8 +105,6 @@ public class ConversationListener:NSObject,Open_im_sdkOnConversationListenerProt
public func onTotalUnreadMessageCountChanged(_ totalUnreadCount: Int32) {
CommonUtil.emitEvent(channel: channel, method: "conversationListener", type: "onTotalUnreadMessageCountChanged", errCode: nil, errMsg: nil, data: totalUnreadCount)
}
}

@ -8,79 +8,98 @@
import Foundation
import OpenIMCore
public class FriendshipManager:NSObject{
private let channel:FlutterMethodChannel
init(channel:FlutterMethodChannel) {
self.channel = channel
}
func setFriendListener(methodCall: FlutterMethodCall, result: FlutterResult){
public class FriendshipManager: BaseServiceManager {
public override func registerHandlers() {
super.registerHandlers()
self["setFriendListener"] = setFriendListener
self["getFriendsInfo"] = getFriendsInfo
self["addFriend"] = addFriend
self["getFriendApplicationList"] = getFriendApplicationList
self["getFriendList"] = getFriendList
self["setFriendInfo"] = setFriendInfo
self["addToBlackList"] = addToBlackList
self["getBlackList"] = getBlackList
self["deleteFromBlackList"] = deleteFromBlackList
self["checkFriend"] = checkFriend
self["deleteFromFriendList"] = deleteFromFriendList
self["acceptFriendApplication"] = acceptFriendApplication
self["refuseFriendApplication"] = refuseFriendApplication
self["forceSyncFriendApplication"] = forceSyncFriendApplication
self["forceSyncFriend"] = forceSyncFriend
self["forceSyncBlackList"] = forceSyncBlackList
}
func setFriendListener(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkSetFriendListener(FriendshipListener(channel: channel))
callBack(result)
}
func getFriendsInfo(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetFriendsInfo(BaseImpl(result: result), CommonUtil.getUidList(methodCall: methodCall))
Open_im_sdkGetFriendsInfo(BaseCallback(result: result), methodCall[jsonString: "uidList"])
}
func addFriend(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkAddFriend(BaseImpl(result: result), CommonUtil.getSDKJsonParam(methodCall: methodCall))
Open_im_sdkAddFriend(BaseCallback(result: result), methodCall.toJsonString())
}
func getFriendApplicationList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetFriendApplicationList(BaseImpl(result: result))
Open_im_sdkGetFriendApplicationList(BaseCallback(result: result))
}
func getFriendList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetFriendList(BaseImpl(result: result))
Open_im_sdkGetFriendList(BaseCallback(result: result))
}
func setFriendInfo(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkSetFriendInfo(CommonUtil.getSDKJsonParam(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkSetFriendInfo(methodCall.toJsonString(), BaseCallback(result: result))
}
func addToBlackList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkAddToBlackList(BaseImpl(result: result), CommonUtil.getJsonUid(methodCall: methodCall))
Open_im_sdkAddToBlackList(BaseCallback(result: result), methodCall[string: "uid"])
}
func getBlackList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetBlackList(BaseImpl(result: result))
Open_im_sdkGetBlackList(BaseCallback(result: result))
}
func deleteFromBlackList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkDeleteFromBlackList(BaseImpl(result: result), CommonUtil.getJsonUid(methodCall: methodCall))
Open_im_sdkDeleteFromBlackList(BaseCallback(result: result), methodCall[string: "uid"])
}
func checkFriend(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkCheckFriend(BaseImpl(result: result), CommonUtil.getUidList(methodCall: methodCall))
Open_im_sdkCheckFriend(BaseCallback(result: result), methodCall[jsonString: "uidList"])
}
func deleteFromFriendList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkDeleteFromFriendList(CommonUtil.getJsonUid(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkDeleteFromFriendList(methodCall[string: "uid"], BaseCallback(result: result))
}
func acceptFriendApplication(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkAcceptFriendApplication(BaseImpl(result: result), CommonUtil.getJsonUid(methodCall: methodCall))
Open_im_sdkAcceptFriendApplication(BaseCallback(result: result), methodCall[string: "uid"])
}
func refuseFriendApplication(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkRefuseFriendApplication(BaseImpl(result: result), CommonUtil.getJsonUid(methodCall: methodCall))
Open_im_sdkRefuseFriendApplication(BaseCallback(result: result), methodCall[string: "uid"])
}
func forceSyncFriendApplication(methodCall: FlutterMethodCall, result: FlutterResult){
func forceSyncFriendApplication(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkForceSyncFriendApplication();
callBack(result)
}
func forceSyncFriend(methodCall: FlutterMethodCall, result: FlutterResult){
func forceSyncFriend(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkForceSyncFriend()
callBack(result)
}
func forceSyncBlackList(methodCall: FlutterMethodCall, result: FlutterResult){
func forceSyncBlackList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkForceSyncBlackList()
callBack(result)
}
}
public class FriendshipListener:NSObject,Open_im_sdkOnFriendshipListenerProtocol {
public class FriendshipListener: NSObject, Open_im_sdkOnFriendshipListenerProtocol {
private let channel:FlutterMethodChannel
init(channel:FlutterMethodChannel) {
@ -124,3 +143,4 @@ public class FriendshipListener:NSObject,Open_im_sdkOnFriendshipListenerProtocol
}
}

@ -8,88 +8,114 @@
import Foundation
import OpenIMCore
public class GroupManager:NSObject{
private let channel:FlutterMethodChannel
init(channel:FlutterMethodChannel) {
self.channel = channel
public class GroupManager: BaseServiceManager {
public override func registerHandlers() {
super.registerHandlers()
self["setGroupListener"] = setGroupListener
self["inviteUserToGroup"] = inviteUserToGroup
self["kickGroupMember"] = kickGroupMember
self["getGroupMembersInfo"] = getGroupMembersInfo
self["getGroupMemberList"] = getGroupMemberList
self["getJoinedGroupList"] = getJoinedGroupList
self["createGroup"] = createGroup
self["setGroupInfo"] = setGroupInfo
self["getGroupsInfo"] = getGroupsInfo
self["joinGroup"] = joinGroup
self["quitGroup"] = quitGroup
self["transferGroupOwner"] = transferGroupOwner
self["getGroupApplicationList"] = getGroupApplicationList
self["acceptGroupApplication"] = acceptGroupApplication
self["refuseGroupApplication"] = refuseGroupApplication
self["forceSyncApplyGroupRequest"] = forceSyncApplyGroupRequest
self["forceSyncGroupRequest"] = forceSyncGroupRequest
self["forceSyncJoinedGroup"] = forceSyncJoinedGroup
self["forceSyncJoinedGroupMember"] = forceSyncJoinedGroupMember
}
func setGroupListener(methodCall: FlutterMethodCall, result: FlutterResult){
func setGroupListener(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkSetGroupListener(GroupListener(channel: channel))
callBack(result)
}
func inviteUserToGroup(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkInviteUserToGroup(CommonUtil.getGid(methodCall: methodCall), CommonUtil.getGroupOpReason(methodCall: methodCall), CommonUtil.getUidList(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkInviteUserToGroup(methodCall[string: "gid"], methodCall[string: "reason"],
methodCall[jsonString: "uidList"], BaseCallback(result: result))
}
func kickGroupMember(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkKickGroupMember(CommonUtil.getGid(methodCall: methodCall), CommonUtil.getGroupOpReason(methodCall: methodCall), CommonUtil.getUidList(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkKickGroupMember(methodCall[string: "gid"], methodCall[string: "reason"],
methodCall[jsonString: "uidList"], BaseCallback(result: result))
}
func getGroupMembersInfo(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetGroupMembersInfo(CommonUtil.getGid(methodCall: methodCall), CommonUtil.getUidList(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkGetGroupMembersInfo(methodCall[string: "gid"], methodCall[jsonString: "uidList"], BaseCallback(result: result))
}
func getGroupMemberList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetGroupMemberList(CommonUtil.getGid(methodCall: methodCall), CommonUtil.getGroupListFilter(methodCall: methodCall), CommonUtil.getGroupListNext(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkGetGroupMemberList(methodCall[string: "gid"], methodCall[int32: "filter"],
methodCall[int32: "next"], BaseCallback(result: result))
}
func getJoinedGroupList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetJoinedGroupList(BaseImpl(result: result))
Open_im_sdkGetJoinedGroupList(BaseCallback(result: result))
}
func createGroup(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkCreateGroup(CommonUtil.getGroupInfo(methodCall: methodCall), CommonUtil.getGroupMemberRoleList(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkCreateGroup(methodCall[jsonString: "gInfo"], methodCall[jsonString: "memberList"], BaseCallback(result: result))
}
func setGroupInfo(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkSetGroupInfo(CommonUtil.getGroupInfo(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkSetGroupInfo(methodCall[jsonString: "gInfo"], BaseCallback(result: result))
}
func getGroupsInfo(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetGroupsInfo(CommonUtil.getGidList(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkGetGroupsInfo(methodCall[jsonString: "gidList"], BaseCallback(result: result))
}
func joinGroup(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkJoinGroup(CommonUtil.getGid(methodCall: methodCall), CommonUtil.getGroupOpReason(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkJoinGroup(methodCall[string: "gid"], methodCall[string: "reason"], BaseCallback(result: result))
}
func quitGroup(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkQuitGroup(CommonUtil.getGid(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkQuitGroup(methodCall[string: "gid"], BaseCallback(result: result))
}
func transferGroupOwner(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkTransferGroupOwner(CommonUtil.getGid(methodCall: methodCall), CommonUtil.getUid(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkTransferGroupOwner(methodCall[string: "gid"], methodCall[string: "uid"], BaseCallback(result: result))
}
func getGroupApplicationList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetGroupApplicationList(BaseImpl(result: result))
Open_im_sdkGetGroupApplicationList(BaseCallback(result: result))
}
func acceptGroupApplication(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkAcceptGroupApplication(CommonUtil.getGroupApplicationInfo(methodCall: methodCall), CommonUtil.getGroupOpReason(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkAcceptGroupApplication(methodCall[jsonString: "application"], methodCall[string: "reason"], BaseCallback(result: result))
}
func refuseGroupApplication(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkRefuseGroupApplication(CommonUtil.getGroupApplicationInfo(methodCall: methodCall), CommonUtil.getGroupOpReason(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkRefuseGroupApplication(methodCall[jsonString: "application"], methodCall[string: "reason"], BaseCallback(result: result))
}
// func forceSyncApplyGroupRequest(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
// Open_im_sdkForceSyncApplyGroupRequest()
// }
//
// func forceSyncGroupRequest(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
// Open_im_sdkForceSyncGroupRequest()
// }
//
// func forceSyncJoinedGroup(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
// Open_im_sdkForceSyncJoinedGroup()
// }
//
// func forceSyncJoinedGroupMember(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
// Open_im_sdkForceSyncJoinedGroupMember()
// }
func forceSyncApplyGroupRequest(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkForceSyncApplyGroupRequest()
callBack(result)
}
func forceSyncGroupRequest(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkForceSyncGroupRequest()
callBack(result)
}
func forceSyncJoinedGroup(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkForceSyncJoinedGroup()
callBack(result)
}
func forceSyncJoinedGroupMember(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkForceSyncJoinedGroupMember()
callBack(result)
}
}
public class GroupListener:NSObject,Open_im_sdkOnGroupListenerProtocol {

@ -8,52 +8,63 @@
import Foundation
import OpenIMCore
public class IMMananger:NSObject{
public class IMMananger: BaseServiceManager {
private let channel:FlutterMethodChannel
init(channel:FlutterMethodChannel) {
self.channel = channel
public override func registerHandlers() {
super.registerHandlers()
self["initSDK"] = initSDK
self["login"] = login
self["logout"] = logout
self["getLoginStatus"] = getLoginStatus
self["getLoginUid"] = getLoginUid
self["getUsersInfo"] = getUsersInfo
self["setSelfInfo"] = setSelfInfo
self["forceSyncLoginUerInfo"] = forceSyncLoginUerInfo
self["forceReConn"] = forceReConn
}
func initSDK(methodCall: FlutterMethodCall, result: FlutterResult){
Open_im_sdkInitSDK(CommonUtil.getSDKJsonParam(methodCall: methodCall), SDKListener(channel: self.channel))
func initSDK(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkInitSDK(methodCall.toJsonString(), SDKListener(channel: self.channel))
callBack(result)
}
func login(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkLogin(CommonUtil.getUid(methodCall: methodCall), CommonUtil.getToken(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkLogin(methodCall[string: "uid"], methodCall[string: "token"], BaseCallback(result: result))
}
func logout(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkLogout(BaseImpl(result: result))
Open_im_sdkLogout(BaseCallback(result: result))
}
func getLoginStatus(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
DispatchQueue.main.async { result(Open_im_sdkGetLoginStatus()) }
callBack(result, Open_im_sdkGetLoginStatus())
}
func getLoginUid(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
DispatchQueue.main.async { result(Open_im_sdkGetLoginUser()) }
callBack(result, Open_im_sdkGetLoginUser())
}
func getUsersInfo(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkGetUsersInfo(CommonUtil.getUidList(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkGetUsersInfo(methodCall[jsonString: "uidList"], BaseCallback(result: result))
}
func setSelfInfo(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkSetSelfInfo(CommonUtil.getSDKJsonParam(methodCall: methodCall), BaseImpl(result: result))
Open_im_sdkSetSelfInfo(methodCall.toJsonString(), BaseCallback(result: result))
}
func forceSyncLoginUerInfo(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkForceSyncLoginUerInfo()
callBack(result)
}
func forceReConn(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkForceReConn()
callBack(result)
}
}
public class SDKListener:NSObject,Open_im_sdkIMSDKListenerProtocol {
public class SDKListener: NSObject, Open_im_sdkIMSDKListenerProtocol {
private let channel:FlutterMethodChannel
init(channel:FlutterMethodChannel) {
@ -84,22 +95,3 @@ public class SDKListener:NSObject,Open_im_sdkIMSDKListenerProtocol {
CommonUtil.emitEvent(channel: self.channel, method: "initSDKListener", type: "onUserTokenExpired", errCode: nil, errMsg: nil, data: nil);
}
}
public class BaseImpl:NSObject,Open_im_sdkBaseProtocol {
private let result:FlutterResult
init(result:@escaping FlutterResult) {
self.result = result
}
public func onError(_ errCode: Int, errMsg: String?) {
print("BaseImpl: " + errMsg!)
DispatchQueue.main.async { self.result(FlutterError(code: "\(errCode)", message: errMsg, details: nil)) }
}
public func onSuccess(_ data: String?) {
DispatchQueue.main.async { self.result(data) }
}
}

@ -8,17 +8,43 @@
import Foundation
import OpenIMCore
public class MessageManager:NSObject{
public class MessageManager: BaseServiceManager {
private let KEY_ID: String = "id"
private let channel:FlutterMethodChannel
private let listeners: NSMutableDictionary = NSMutableDictionary(capacity: 0)
init(channel:FlutterMethodChannel) {
self.channel = channel
public override func registerHandlers() {
super.registerHandlers()
self["addAdvancedMsgListener"] = addAdvancedMsgListener
self["removeAdvancedMsgListener"] = removeAdvancedMsgListener
self["sendMessage"] = sendMessage
self["getHistoryMessageList"] = getHistoryMessageList
self["revokeMessage"] = revokeMessage
self["deleteMessageFromLocalStorage"] = deleteMessageFromLocalStorage
self["deleteMessages"] = deleteMessages
self["insertSingleMessageToLocalStorage"] = insertSingleMessageToLocalStorage
self["findMessages"] = findMessages
self["markC2CMessageAsRead"] = markC2CMessageAsRead
self["typingStatusUpdate"] = typingStatusUpdate
self["createTextMessage"] = createTextMessage
self["createTextAtMessage"] = createTextAtMessage
self["createImageMessage"] = createImageMessage
self["createImageMessageFromFullPath"] = createImageMessageFromFullPath
self["createSoundMessage"] = createSoundMessage
self["createSoundMessageFromFullPath"] = createSoundMessageFromFullPath
self["createVideoMessage"] = createVideoMessage
self["createVideoMessageFromFullPath"] = createVideoMessageFromFullPath
self["createFileMessage"] = createFileMessage
self["createMergerMessage"] = createMergerMessage
self["createForwardMessage"] = createForwardMessage
self["createLocationMessage"] = createLocationMessage
self["createCustomMessage"] = createCustomMessage
self["createQuoteMessage"] = createQuoteMessage
self["createCardMessage"] = createCardMessage
self["forceSyncMsg"] = forceSyncMsg
}
func addAdvancedMsgListener(methodCall: FlutterMethodCall, result: FlutterResult){
func addAdvancedMsgListener(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let d = methodCall.arguments as! NSDictionary
let key = d.value(forKey: KEY_ID) as! String
if !listeners.allKeys.contains(where: {($0 as! String).compare(key) == .orderedSame}) {
@ -29,9 +55,10 @@ public class MessageManager:NSObject{
Open_im_sdkAddAdvancedMsgListener(lis)
print("=================add msg listener======\n\(lis)");
}
callBack(result)
}
func removeAdvancedMsgListener(methodCall: FlutterMethodCall, result: FlutterResult){
func removeAdvancedMsgListener(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let k = methodCall.arguments as! NSDictionary
let s = k.value(forKey: KEY_ID) as! String
if listeners.allKeys.contains(where: {($0 as! String).compare(s) == .orderedSame}) {
@ -39,6 +66,7 @@ public class MessageManager:NSObject{
listeners.removeObject(forKey: s)
Open_im_sdkRemoveAdvancedMsgListener(lis)
}
callBack(result)
}
func sendMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
@ -46,151 +74,183 @@ public class MessageManager:NSObject{
sendMsgProgressListener.setCall(methodCall: methodCall)
sendMsgProgressListener.setResult(result: result)
print("===============sendMessage===============")
Open_im_sdkSendMessage(sendMsgProgressListener, CommonUtil.getSendMessageContent(methodCall: methodCall), CommonUtil.getSendMessageReceiver(methodCall: methodCall), CommonUtil.getSendMessageGroupId(methodCall: methodCall), CommonUtil.getSendMessageOnlineOnly(methodCall: methodCall))
Open_im_sdkSendMessage(sendMsgProgressListener, methodCall[jsonString: "message"], methodCall[string: "receiver"],
methodCall[string: "groupID"], methodCall[bool: "onlineUserOnly"])
}
func getHistoryMessageList(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetHistoryMessageList(BaseImpl(result: result), CommonUtil.getSDKJsonParam(methodCall: methodCall))
Open_im_sdkGetHistoryMessageList(BaseCallback(result: result), methodCall.toJsonString())
}
func revokeMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkRevokeMessage(BaseImpl(result: result), CommonUtil.getSDKJsonParam(methodCall: methodCall))
Open_im_sdkRevokeMessage(BaseCallback(result: result), methodCall.toJsonString())
}
func deleteMessageFromLocalStorage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkDeleteMessageFromLocalStorage(BaseImpl(result: result), CommonUtil.getSDKJsonParam(methodCall: methodCall))
Open_im_sdkDeleteMessageFromLocalStorage(BaseCallback(result: result), methodCall.toJsonString())
}
// deprecated
func deleteMessages(methodCall: FlutterMethodCall, result: FlutterResult){
}
func insertSingleMessageToLocalStorage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkInsertSingleMessageToLocalStorage(BaseImpl(result: result), CommonUtil.getSingleMessageContent(methodCall: methodCall), CommonUtil.getSingleMessageUserid(methodCall: methodCall), CommonUtil.getSingleMessageSender(methodCall: methodCall))
Open_im_sdkInsertSingleMessageToLocalStorage(BaseCallback(result: result), methodCall[jsonString: "message"],
methodCall[string: "userID"], methodCall[string: "sender"])
}
func findMessages(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkFindMessages(BaseImpl(result: result), CommonUtil.getFindMessageIds(methodCall: methodCall))
Open_im_sdkFindMessages(BaseCallback(result: result), methodCall[jsonString: "messageIDList"])
}
func markSingleMessageHasRead(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkMarkSingleMessageHasRead(BaseImpl(result: result), CommonUtil.getSingleMessageUserid(methodCall: methodCall))
func markC2CMessageAsRead(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkMarkC2CMessageAsRead(BaseCallback(result: result), methodCall[string: "userID"], methodCall[jsonString: "messageIDList"])
}
func markGroupMessageHasRead(methodCall: FlutterMethodCall, result: @escaping FlutterResult) {
Open_im_sdkMarkGroupMessageHasRead(BaseImpl(result: result), CommonUtil.getGroupMessageGroupid(methodCall: methodCall))
func typingStatusUpdate(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkTypingStatusUpdate(methodCall[string: "userID"], methodCall[string: "typing"])
callBack(result)
}
func createTextMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateTextMessage(CommonUtil.getMessageText(methodCall: methodCall))
DispatchQueue.main.async { result(prama) }
callBack(result, Open_im_sdkCreateTextMessage(methodCall[string: "text"]))
}
func createTextAtMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateTextAtMessage(CommonUtil.getMessageText(methodCall: methodCall), CommonUtil.getAtUserList(methodCall: methodCall))
DispatchQueue.main.async { result(prama) }
callBack(result, Open_im_sdkCreateTextAtMessage(methodCall[string: "text"], methodCall[jsonString: "atUserList"]))
}
func createImageMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateImageMessage(CommonUtil.getImagePath(methodCall: methodCall))
DispatchQueue.main.async { result(prama) }
callBack(result, Open_im_sdkCreateImageMessage(methodCall[string: "imagePath"]))
}
func createSoundMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateSoundMessage(CommonUtil.getSoundPath(methodCall: methodCall),CommonUtil.getSoundDuration(methodCall: methodCall))
DispatchQueue.main.async { result(prama) }
func createImageMessageFromFullPath(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
callBack(result, Open_im_sdkCreateImageMessageFromFullPath(methodCall[string: "imagePath"]))
}
func createVideoMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateVideoMessage(CommonUtil.getVideoPath(methodCall: methodCall), CommonUtil.getVideoType(methodCall: methodCall), CommonUtil.getVideoDuration(methodCall: methodCall), CommonUtil.getVideoSnapshotPath(methodCall: methodCall))
DispatchQueue.main.async { result(prama) }
func createSoundMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
callBack(result, Open_im_sdkCreateSoundMessage(methodCall[string: "soundPath"], methodCall[int64: "duration"]))
}
func createFileMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateFileMessage(CommonUtil.getFilePath(methodCall: methodCall), CommonUtil.getFileName(methodCall: methodCall))
DispatchQueue.main.async { result(prama) }
func createSoundMessageFromFullPath(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
callBack(result, Open_im_sdkCreateSoundMessageFromFullPath(methodCall[string: "soundPath"], methodCall[int64: "duration"]))
}
func createMergerMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateMergerMessage(CommonUtil.getMergerMessageList(methodCall: methodCall), CommonUtil.getMergerMessageTitle(methodCall: methodCall), CommonUtil.getSummaryList(methodCall: methodCall))
DispatchQueue.main.async { result(prama) }
func createVideoMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateVideoMessage(methodCall[string: "videoPath"], methodCall[string: "videoType"],
methodCall[int64: "duration"], methodCall[string: "snapshotPath"])
callBack(result, prama)
}
func createForwardMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateForwardMessage(CommonUtil.getForwardMessage(methodCall: methodCall))
DispatchQueue.main.async { result(prama) }
func createVideoMessageFromFullPath(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateVideoMessageFromFullPath(methodCall[string: "videoPath"], methodCall[string: "videoType"],
methodCall[int64: "duration"], methodCall[string: "snapshotPath"])
callBack(result, prama)
}
func getTotalUnreadMsgCount(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkGetTotalUnreadMsgCount(BaseImpl(result: result))
}
func forceSyncMsg(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkForceSyncMsg()
}
public class SendMsgProgressListener:NSObject, Open_im_sdkSendMsgCallBackProtocol {
private let channel: FlutterMethodChannel
private var result: FlutterResult?
private var call: FlutterMethodCall?
private let values: NSMutableDictionary = NSMutableDictionary(capacity: 0)
init(channel: FlutterMethodChannel) {
self.channel = channel
func createFileMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
callBack(result, Open_im_sdkCreateFileMessage(methodCall[string: "filePath"], methodCall[string: "fileName"]))
}
func setResult(result: @escaping FlutterResult){
self.result = result
func createMergerMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateMergerMessage(methodCall[jsonString: "messageList"], methodCall[string: "title"],
methodCall[jsonString: "summaryList"])
callBack(result, prama)
}
func setCall(methodCall: FlutterMethodCall){
self.call = methodCall
func createForwardMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
callBack(result, Open_im_sdkCreateForwardMessage(methodCall[jsonString: "message"]))
}
public func onError(_ errCode: Int, errMsg: String?) {
print("=================onError============\nerrcode:\(errCode),errMsg:\(errMsg!)");
DispatchQueue.main.async { self.result!(FlutterError(code: "\(errCode)", message: errMsg, details: nil)) }
func createLocationMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateLocationMessage(methodCall[string: "description"],
methodCall[double: "longitude"], methodCall[double: "latitude"])
callBack(result, prama)
}
public func onProgress(_ progress: Int) {
print("=================onProgress============\nprogress:\(progress)");
values.setValue(CommonUtil.getSendMessageClientMsgID(methodCall: self.call!), forKey: "clientMsgID")
values.setValue(progress, forKey: "progress")
CommonUtil.emitEvent(channel: channel, method: "msgSendProgressListener", type: "onProgress", errCode: nil, errMsg: nil, data: values)
func createCustomMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateCustomMessage(methodCall[string: "data"],
methodCall[string: "extension"], methodCall[string: "description"])
callBack(result, prama)
}
public func onSuccess(_ data: String?) {
print("=================onSuccess============\nsuccess:\(data!)");
DispatchQueue.main.async { self.result!(data) }
func createQuoteMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
let prama = Open_im_sdkCreateQuoteMessage(methodCall[string: "quoteText"], methodCall[jsonString: "quoteMessage"])
callBack(result, prama)
}
}
public class AdvancedMsgListener: NSObject, Open_im_sdkOnAdvancedMsgListenerProtocol {
private let channel: FlutterMethodChannel
private let values: NSMutableDictionary = NSMutableDictionary(capacity: 0)
init(channel: FlutterMethodChannel, id: String) {
self.channel = channel
values.setValue(id, forKey: "id")
func createCardMessage(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
callBack(result, Open_im_sdkCreateCardMessage(methodCall[jsonString: "cardMessage"]))
}
public func onRecvC2CReadReceipt(_ msgReceiptList: String?) {
values.setValue(msgReceiptList, forKey: "message")
CommonUtil.emitEvent(channel: channel, method: "advancedMsgListener", type: "onRecvC2CReadReceipt", errCode: nil, errMsg: nil, data: values)
func forceSyncMsg(methodCall: FlutterMethodCall, result: @escaping FlutterResult){
Open_im_sdkForceSyncMsg()
callBack(result)
}
public func onRecvMessageRevoked(_ msgId: String?) {
values.setValue(msgId, forKey: "message")
CommonUtil.emitEvent(channel: channel, method: "advancedMsgListener", type: "onRecvMessageRevoked", errCode: nil, errMsg: nil, data: values)
public class SendMsgProgressListener:NSObject, Open_im_sdkSendMsgCallBackProtocol {
private let channel: FlutterMethodChannel
private var result: FlutterResult?
private var call: FlutterMethodCall?
private let values: NSMutableDictionary = NSMutableDictionary(capacity: 0)
init(channel: FlutterMethodChannel) {
self.channel = channel
}
func setResult(result: @escaping FlutterResult){
self.result = result
}
func setCall(methodCall: FlutterMethodCall){
self.call = methodCall
}
public func onError(_ errCode: Int, errMsg: String?) {
print("=================onError============\nerrcode:\(errCode),errMsg:\(errMsg!)");
DispatchQueue.main.async { self.result!(FlutterError(code: "\(errCode)", message: errMsg, details: nil)) }
}
public func onProgress(_ progress: Int) {
guard let call = call else {
return
}
print("=================onProgress============\nprogress:\(progress)");
values.setValue(call[string: "clientMsgID"], forKey: "clientMsgID")
values.setValue(progress, forKey: "progress")
CommonUtil.emitEvent(channel: channel, method: "msgSendProgressListener", type: "onProgress", errCode: nil, errMsg: nil, data: values)
}
public func onSuccess(_ data: String?) {
print("=================onSuccess============\nsuccess:\(data!)");
DispatchQueue.main.async { self.result!(data) }
}
}
public func onRecvNewMessage(_ message: String?) {
values.setValue(message, forKey: "message")
CommonUtil.emitEvent(channel: channel, method: "advancedMsgListener", type: "onRecvNewMessage", errCode: nil, errMsg: nil, data: values)
public class AdvancedMsgListener: NSObject, Open_im_sdkOnAdvancedMsgListenerProtocol {
private let channel: FlutterMethodChannel
private let values: NSMutableDictionary = NSMutableDictionary(capacity: 0)
init(channel: FlutterMethodChannel, id: String) {
self.channel = channel
values.setValue(id, forKey: "id")
}
public func onRecvC2CReadReceipt(_ msgReceiptList: String?) {
values.setValue(msgReceiptList, forKey: "message")
CommonUtil.emitEvent(channel: channel, method: "advancedMsgListener", type: "onRecvC2CReadReceipt", errCode: nil, errMsg: nil, data: values)
}
public func onRecvMessageRevoked(_ msgId: String?) {
values.setValue(msgId, forKey: "message")
CommonUtil.emitEvent(channel: channel, method: "advancedMsgListener", type: "onRecvMessageRevoked", errCode: nil, errMsg: nil, data: values)
}
public func onRecvNewMessage(_ message: String?) {
values.setValue(message, forKey: "message")
CommonUtil.emitEvent(channel: channel, method: "advancedMsgListener", type: "onRecvNewMessage", errCode: nil, errMsg: nil, data: values)
}
}
}
}

@ -2,217 +2,43 @@ import Flutter
import UIKit
public class SwiftFlutterOpenimSdkPlugin: NSObject, FlutterPlugin {
let imManager: IMMananger
let conversationManager: ConversationManager
let friendshipManager: FriendshipManager
let messageManager: MessageManager
let groupManager: GroupManager
init(channel: FlutterMethodChannel) {
self.imManager = IMMananger(channel: channel)
self.conversationManager = ConversationManager(channel: channel)
self.friendshipManager = FriendshipManager(channel: channel)
self.messageManager = MessageManager(channel: channel)
self.groupManager = GroupManager(channel: channel)
}
let imManager: IMMananger
let conversationManager: ConversationManager
let friendshipManager: FriendshipManager
let messageManager: MessageManager
let groupManager: GroupManager
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "flutter_openim_sdk", binaryMessenger: registrar.messenger())
let instance = SwiftFlutterOpenimSdkPlugin(channel: channel)
registrar.addMethodCallDelegate(instance, channel: channel)
}
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let managerName: String = CommonUtil.getParamValue(methodCall: call, param: "ManagerName") as! String
if managerName == "imManager" {
handleIMManager(call: call, result: result)
}else if managerName == "conversationManager"{
handleConversationManager(call: call, result: result)
}else if managerName == "friendshipManager"{
handleFriendshipManager(call: call, result: result)
}else if managerName == "messageManager"{
handleMessageManager(call: call, result: result)
}else if managerName == "groupManager"{
handleGroupManager(call: call, result: result)
}else{
print("Handle ManagerName Error: \(managerName) not found")
init(channel: FlutterMethodChannel) {
self.imManager = IMMananger(channel: channel)
self.conversationManager = ConversationManager(channel: channel)
self.friendshipManager = FriendshipManager(channel: channel)
self.messageManager = MessageManager(channel: channel)
self.groupManager = GroupManager(channel: channel)
}
}
private func handleIMManager(call: FlutterMethodCall, result: @escaping FlutterResult){
let method: String = call.method
if method == "initSDK" {
imManager.initSDK(methodCall: call, result: result)
}else if method == "login" {
imManager.login(methodCall: call, result: result)
}else if method == "logout" {
imManager.logout(methodCall: call, result: result)
}else if method == "getLoginStatus" {
imManager.getLoginStatus(methodCall: call, result: result)
}else if method == "getLoginUid" {
imManager.getLoginUid(methodCall: call, result: result)
}else if method == "getUsersInfo" {
imManager.getUsersInfo(methodCall: call, result: result)
}else if method == "setSelfInfo" {
imManager.setSelfInfo(methodCall: call, result: result)
}else if method == "forceSyncLoginUerInfo" {
imManager.forceSyncLoginUerInfo(methodCall: call, result: result)
}else if method == "forceReConn" {
imManager.forceReConn(methodCall: call, result: result)
}else{
print("Handle MethodName Error: IMManager method: \(method) not found")
}
public static func register(with registrar: FlutterPluginRegistrar) {
let channel = FlutterMethodChannel(name: "flutter_openim_sdk", binaryMessenger: registrar.messenger())
let instance = SwiftFlutterOpenimSdkPlugin(channel: channel)
registrar.addMethodCallDelegate(instance, channel: channel)
}
private func handleConversationManager(call: FlutterMethodCall, result: @escaping FlutterResult){
let method: String = call.method
if method == "setConversationListener" {
conversationManager.setConversationListener(methodCall: call, result: result)
}else if method == "getAllConversationList" {
conversationManager.getAllConversationList(methodCall: call, result: result)
}else if method == "getOneConversation" {
conversationManager.getOneConversation(methodCall: call, result: result)
}else if method == "getMultipleConversation" {
conversationManager.getMultipleConversation(methodCall: call, result: result)
}else if method == "deleteConversation" {
conversationManager.deleteConversation(methodCall: call, result: result)
}else if method == "setConversationDraft" {
conversationManager.setConversationDraft(methodCall: call, result: result)
}else if method == "pinConversation" {
conversationManager.pinConversation(methodCall: call, result: result)
}else{
print("Handle MethodName Error: ConversationManager method: \(method) not found")
public func handle(_ call: FlutterMethodCall, result: @escaping FlutterResult) {
let managerName: String = call[string: "ManagerName"]
switch managerName {
case "imManager":
imManager.handleMethod(call: call, result: result)
case "conversationManager":
conversationManager.handleMethod(call: call, result: result)
case "messageManager":
messageManager.handleMethod(call: call, result: result)
case "friendshipManager":
friendshipManager.handleMethod(call: call, result: result)
case "groupManager":
groupManager.handleMethod(call: call, result: result)
default:
print("Handle ManagerName Error: \(managerName) not found")
}
}
private func handleFriendshipManager(call: FlutterMethodCall, result: @escaping FlutterResult){
let method: String = call.method
if method == "setFriendListener" {
friendshipManager.setFriendListener(methodCall: call, result: result)
}else if method == "getFriendsInfo" {
friendshipManager.getFriendsInfo(methodCall: call, result: result)
}else if method == "addFriend" {
friendshipManager.addFriend(methodCall: call, result: result)
}else if method == "getFriendApplicationList" {
friendshipManager.getFriendApplicationList(methodCall: call, result: result)
}else if method == "getFriendList" {
friendshipManager.getFriendList(methodCall: call, result: result)
}else if method == "setFriendInfo" {
friendshipManager.setFriendInfo(methodCall: call, result: result)
}else if method == "addToBlackList" {
friendshipManager.addToBlackList(methodCall: call, result: result)
}else if method == "getBlackList" {
friendshipManager.getBlackList(methodCall: call, result: result)
}else if method == "deleteFromBlackList" {
friendshipManager.deleteFromBlackList(methodCall: call, result: result)
}else if method == "checkFriend" {
friendshipManager.checkFriend(methodCall: call, result: result)
}else if method == "deleteFromFriendList" {
friendshipManager.deleteFromFriendList(methodCall: call, result: result)
}else if method == "acceptFriendApplication" {
friendshipManager.acceptFriendApplication(methodCall: call, result: result)
}else if method == "refuseFriendApplication" {
friendshipManager.refuseFriendApplication(methodCall: call, result: result)
}else if method == "forceSyncFriendApplication" {
friendshipManager.forceSyncFriendApplication(methodCall: call, result: result)
}else if method == "forceSyncFriend" {
friendshipManager.forceSyncFriend(methodCall: call, result: result)
}else if method == "forceSyncBlackList" {
friendshipManager.forceSyncBlackList(methodCall: call, result: result)
}else{
print("Handle MethodName Error: FriendshipManager method: \(method) not found")
}
}
private func handleMessageManager(call: FlutterMethodCall, result: @escaping FlutterResult){
let method: String = call.method
if method == "addAdvancedMsgListener" {
messageManager.addAdvancedMsgListener(methodCall: call, result: result)
}else if method == "removeAdvancedMsgListener" {
messageManager.removeAdvancedMsgListener(methodCall: call, result: result)
}else if method == "sendMessage" {
messageManager.sendMessage(methodCall: call, result: result)
}else if method == "getHistoryMessageList" {
messageManager.getHistoryMessageList(methodCall: call, result: result)
}else if method == "revokeMessage" {
messageManager.revokeMessage(methodCall: call, result: result)
}else if method == "deleteMessageFromLocalStorage" {
messageManager.deleteMessageFromLocalStorage(methodCall: call, result: result)
}else if method == "deleteMessages" {
messageManager.deleteMessages(methodCall: call, result: result)
}else if method == "insertSingleMessageToLocalStorage" {
messageManager.insertSingleMessageToLocalStorage(methodCall: call, result: result)
}else if method == "findMessages" {
messageManager.findMessages(methodCall: call, result: result)
}else if method == "markSingleMessageHasRead" {
messageManager.markSingleMessageHasRead(methodCall: call, result: result)
}else if method == "createTextMessage" {
messageManager.createTextMessage(methodCall: call, result: result)
}else if method == "createTextAtMessage" {
messageManager.createTextAtMessage(methodCall: call, result: result)
}else if method == "createImageMessage" {
messageManager.createImageMessage(methodCall: call, result: result)
}else if method == "createSoundMessage" {
messageManager.createSoundMessage(methodCall: call, result: result)
}else if method == "createVideoMessage" {
messageManager.createVideoMessage(methodCall: call, result: result)
}else if method == "createFileMessage" {
messageManager.createFileMessage(methodCall: call, result: result)
}else if method == "createMergerMessage" {
messageManager.createMergerMessage(methodCall: call, result: result)
}else if method == "createForwardMessage" {
messageManager.createForwardMessage(methodCall: call, result: result)
}else if method == "getTotalUnreadMsgCount" {
messageManager.getTotalUnreadMsgCount(methodCall: call, result: result)
}else{
print("Handle MethodName Error: MessageManager method: \(method) not found")
}
}
private func handleGroupManager(call: FlutterMethodCall, result: @escaping FlutterResult){
let method: String = call.method
if method == "setGroupListener" {
groupManager.setGroupListener(methodCall: call, result: result)
}else if method == "inviteUserToGroup" {
groupManager.inviteUserToGroup(methodCall: call, result: result)
}else if method == "kickGroupMember" {
groupManager.kickGroupMember(methodCall: call, result: result)
}else if method == "getGroupMembersInfo" {
groupManager.getGroupMembersInfo(methodCall: call, result: result)
}else if method == "getGroupMemberList" {
groupManager.getGroupMemberList(methodCall: call, result: result)
}else if method == "getJoinedGroupList" {
groupManager.getJoinedGroupList(methodCall: call, result: result)
}else if method == "createGroup" {
groupManager.createGroup(methodCall: call, result: result)
}else if method == "setGroupInfo" {
groupManager.setGroupInfo(methodCall: call, result: result)
}else if method == "getGroupsInfo" {
groupManager.getGroupsInfo(methodCall: call, result: result)
}else if method == "joinGroup" {
groupManager.joinGroup(methodCall: call, result: result)
}else if method == "quitGroup" {
groupManager.quitGroup(methodCall: call, result: result)
}else if method == "transferGroupOwner" {
groupManager.transferGroupOwner(methodCall: call, result: result)
}else if method == "getGroupApplicationList" {
groupManager.getGroupApplicationList(methodCall: call, result: result)
}else if method == "acceptGroupApplication" {
groupManager.acceptGroupApplication(methodCall: call, result: result)
}else if method == "refuseGroupApplication" {
groupManager.refuseGroupApplication(methodCall: call, result: result)
// }else if method == "forceSyncApplyGroupRequest" {
// groupManager.forceSyncApplyGroupRequest(methodCall: call, result: result)
// }else if method == "forceSyncGroupRequest" {
// groupManager.forceSyncGroupRequest(methodCall: call, result: result)
// }else if method == "forceSyncJoinedGroup" {
// groupManager.forceSyncJoinedGroup(methodCall: call, result: result)
// }else if method == "forceSyncJoinedGroupMember" {
// groupManager.forceSyncJoinedGroupMember(methodCall: call, result: result)
}else{
print("Handle MethodName Error: MessageManager method: \(method) not found")
}
}
}

@ -0,0 +1,23 @@
//
// Any+Extension.swift
// flutter_openim_sdk
//
// Created by willem on 2021/10/9.
//
import Foundation
public func typeName(_ obj: Any) -> String {
if obj is AnyClass {
return "\(obj)"
}
return "\(type(of: obj))"
}
public func safeMainAsync(_ work: @escaping @convention(block) () -> Void) {
if Thread.isMainThread {
work()
} else {
DispatchQueue.main.async(execute: work)
}
}

@ -0,0 +1,109 @@
//
// FlutterMethodCall+Extension.swift
// flutter_openim_sdk
//
// Created by willem on 2021/10/9.
//
import Foundation
import Flutter
public protocol Stringable {
var rawValue: String { get }
}
extension String: Stringable {
public var rawValue: String { self }
}
public extension FlutterMethodCall {
subscript(_ key: Stringable) -> Any? {
guard let params = self.arguments as? [String: Any] else {
return nil
}
return params[key.rawValue]
}
subscript(string key: Stringable) -> String {
return self[key] as? String ?? ""
}
subscript(jsonString key: Stringable) -> String {
guard let params = self.arguments as? [String: Any] else {
return ""
}
let arg = params[key.rawValue] as AnyObject
return JsonUtil.toString(object: arg)
}
subscript(int32 key: Stringable) -> Int32 {
guard let value = self[key] else {
return 0
}
if let value = value as? Int32 {
return value
} else if let value = value as? String {
return Int32(value) ?? 0
}
return 0
}
subscript(int64 key: Stringable) -> Int64 {
guard let value = self[key] else {
return 0
}
if let value = value as? Int64 {
return value
} else if let value = value as? String {
return Int64(value) ?? 0
}
return 0
}
subscript(int key: Stringable) -> Int {
guard let value = self[key] else {
return 0
}
if let value = value as? Int {
return value
} else if let value = value as? String {
return Int(value) ?? 0
}
return 0
}
subscript(double key: Stringable) -> Double {
guard let value = self[key] else {
return 0
}
if let value = value as? Double {
return value
} else if let value = value as? String {
return Double(value) ?? 0.0
}
return 0
}
subscript(bool key: Stringable, default default: Bool = false) -> Bool {
guard let value = self[key] else {
return `default`
}
if let value = value as? Bool {
return value
} else if let value = value as? Int {
return value != 0
} else if let value = value as? NSString {
return value.boolValue
}
return `default`
}
subscript(dict key: Stringable) -> [AnyHashable: Any] {
return self[key] as? [AnyHashable: Any] ?? [:]
}
func toJsonString() -> String {
let params = self.arguments as AnyObject
return JsonUtil.toString(object: params)
}
}
Loading…
Cancel
Save