Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import UIKit
- import Quickblox
- class ViewController: UIViewController, QBChatDelegate {
- @IBOutlet weak var block_user_button: UIButton!
- @IBOutlet weak var logout_user_button: UIButton!
- //var listPrivacy :QBPrivacyList? = nil
- func chatDidReceivePrivacyListNames(_ listNames: [String]) {
- for name in listNames {
- print("\n----- name : \(name)\n")
- }
- }
- func get_all_user_dialogs() {
- }
- func chatDidSetPrivacyList(withName name: String) {
- print("\n chat did set privacy list \n")
- }
- func chatDidReceive(_ message: QBChatMessage) {
- print("\nRECEIVED THAT MSG\n")
- }
- func chatDidNotSetDefaultPrivacyList(withName name: String, error: Any?) {
- print("\n -- Did not set default privacy list ----\n")
- print(" \n cannot set default : \(name) with the following error : \(error ?? "")\n")
- }
- func chatDidNotSetActivePrivacyList(withName name: String, error: Any?) {
- print("\n -- Did not set active privacy list ----\n")
- print(" \n cannot set active : \(name) with the following error : \(error ?? "")\n")
- }
- func chatDidSetDefaultPrivacyList(withName name: String) {
- print("\n -- Did set default privacy list : \(name)----\n")
- }
- func chatDidSetActivePrivacyList(withName name: String) {
- print("\n -- Did set active privacy list : \(name)----\n")
- }
- func chatDidRemovedPrivacyList(withName name: String) {
- print("\n ---- List \(name) removed \n")
- }
- func chatDidNotSetPrivacyList(withName name: String, error: Any?) {
- //QBChat.instance().retrievePrivacyList(withName: name)
- print(" \n ---- FAILED TO REMOVE LIST : \(name) ---- \n")
- print("\n --- chat did not set set privacy list : \(name)--- \n")
- print(error ?? "\n NO ERROR WHILE SETTING A NEW PRIVACY LIST\n")
- }
- func chatDidReceive(_ privacyList: QBPrivacyList) {
- print("\n----- chat did receive list -----\n")
- }
- func chatDidNotReceivePrivacyList(withName name: String, error: Any?) {
- print("\n chat did not receive privacy list\n")
- }
- func chatRoomDidReceive(_ message: QBChatMessage, fromDialogID dialogID: String) {
- print("\nmessage : \(message), and dialog is : \(dialogID)\n")
- }
- func chatDidReceiveSystemMessage(_ message: QBChatMessage) {
- print("\n the message is : \(message)\n ")
- }
- override func viewDidLoad() {
- super.viewDidLoad()
- // Do any additional setup after loading the view, typically from a nib.
- block_user_button.addTarget(self, action: #selector(removePrivacyList(button:)), for: .touchUpInside)
- logout_user_button.addTarget(self, action: #selector(logoutUser(button:)), for: .touchUpInside)
- let user = QBUUser()
- user.id = 29777896
- user.password = "03121995"
- QBChat.instance().addDelegate(self)
- QBChat.instance().connect(with: user) {
- (error) in
- if error != nil {
- print("error: \(String(describing: error))")
- return
- } else {
- print("\nsuccess connecting to QB chat\n")
- QBRequest.logIn(withUserLogin: "chem", password: "03121995", successBlock: { (response: QBResponse, user: QBUUser?) in
- print("\n ---------------> connected \n")
- // here goes code
- self.createNewListAndSetDefault()
- })
- }
- }
- // chatDialog.occupantIDs = [29777896, 29782373]
- print("\n processing ... 👀\n")
- }
- func removePrivacyList(button: UIButton) {
- //QBChat.instance().retrievePrivacyList(withName: "public")
- QBChat.instance().removePrivacyList(withName: "public")
- }
- func createNewListAndSetDefault() {
- let item: QBPrivacyItem = QBPrivacyItem(privacyType: QBPrivacyType.groupUserID , userID: 29782373, allow: false)!
- item.mutualBlock = true
- let privacyList = QBPrivacyList(name: "tmp", items: [item])
- QBChat.instance().setPrivacyList(privacyList)
- QBChat.instance().setDefaultPrivacyListWithName("tmp")
- QBChat.instance().setActivePrivacyListWithName("tmp")
- print("\n -- Done setting a new list as default -- \n")
- }
- func logoutUser(button: UIButton) {
- QBChat.instance().disconnect { (Error) in
- print(Error ?? "NO ERROR when disconnecting")
- }
- QBRequest.logOut(successBlock: { (QBResponse) in
- print(QBResponse)
- print("\n ----- Log out successfull ------ \n")
- }) { (QBResponse) in
- print("\n ----- Log out error ------ \n")
- print(QBResponse)
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement