This commit is contained in:
bekannax
2025-02-06 12:24:38 +07:00
parent bea9cbcb7a
commit b99ac0c086
2 changed files with 38 additions and 0 deletions

View File

@@ -34,6 +34,11 @@ open class ChatApi {
} }
} }
public func setInfo(_ token: String, params: Dictionary<String, Any>, callback: @escaping (NSDictionary?) -> Void) {
send(token, "chat/client/setInfo", params, callback: callback)
}
public func messages(_ token: String, params: Dictionary<String, Any>, callback: @escaping (NSDictionary?) -> Void) { public func messages(_ token: String, params: Dictionary<String, Any>, callback: @escaping (NSDictionary?) -> Void) {
send(token, "chat/message/getList", params, callback: callback) send(token, "chat/message/getList", params, callback: callback)
} }
@@ -53,4 +58,8 @@ open class ChatApi {
] as [String : Any] ] as [String : Any]
(ChatApi()).messages(token, params: params, callback: callback) (ChatApi()).messages(token, params: params, callback: callback)
} }
public static func setInfo(_ token: String, _ params: Dictionary<String, Any>, callback: @escaping (NSDictionary?) -> Void) {
(ChatApi()).setInfo(token, params: params, callback: callback)
}
} }

View File

@@ -134,6 +134,23 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
callback( ChatController.getNewMessagesCallback(result!) ) callback( ChatController.getNewMessagesCallback(result!) )
}) })
} }
public static func setInfoCustomDataValue(key: String, value: String, callback: @escaping (NSDictionary?) -> Void) {
DispatchQueue.global().async {
ChatApi.setInfo(
ChatConfig.getApiToken(),
[
"client": [
"id": ChatConfig.getClientId(),
"customData": [
key: value
]
],
] as [String : Any],
callback: callback
)
}
}
override public func loadView() { override public func loadView() {
let contentController = WKUserContentController() let contentController = WKUserContentController()
@@ -288,6 +305,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
} }
private func callJs(_ script: String) { private func callJs(_ script: String) {
print("callJs : \(script)")
chatView.evaluateJavaScript(script) chatView.evaluateJavaScript(script)
} }
@@ -487,6 +505,7 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
switch name { switch name {
case ChatController.method_pageLoaded: case ChatController.method_pageLoaded:
injectCss(style: self.css) injectCss(style: self.css)
onChatWasOpen()
break break
case ChatController.event_closeSupport: case ChatController.event_closeSupport:
onCloseSupport() onCloseSupport()
@@ -520,6 +539,14 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
onEvent(name, data!) onEvent(name, data!)
} }
open func onChatWasOpen() {
}
open func onChatWasClosed() {
}
open func onCloseSupport() { open func onCloseSupport() {
if chatView == nil { if chatView == nil {
return return
@@ -530,6 +557,8 @@ open class ChatController: UIViewController, WKNavigationDelegate, WKScriptMessa
dismiss(animated: true, completion: nil) dismiss(animated: true, completion: nil)
navigationController?.popViewController(animated: true) navigationController?.popViewController(animated: true)
onChatWasClosed()
} }
open override func viewDidDisappear(_ animated: Bool) { open override func viewDidDisappear(_ animated: Bool) {