Advertisement
Guest User

Untitled

a guest
Jul 24th, 2017
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.16 KB | None | 0 0
  1. import UIKit
  2. import Quickblox
  3.  
  4.  
  5.  
  6. class ViewController: UIViewController, QBChatDelegate {
  7. @IBOutlet weak var block_user_button: UIButton!
  8. @IBOutlet weak var logout_user_button: UIButton!
  9.  
  10. //var listPrivacy :QBPrivacyList? = nil
  11.  
  12. func chatDidReceivePrivacyListNames(_ listNames: [String]) {
  13. for name in listNames {
  14. print("\n----- name : \(name)\n")
  15. }
  16. }
  17.  
  18. func get_all_user_dialogs() {
  19. }
  20.  
  21.  
  22.  
  23. func chatDidSetPrivacyList(withName name: String) {
  24. print("\n chat did set privacy list \n")
  25. }
  26.  
  27. func chatDidReceive(_ message: QBChatMessage) {
  28. print("\nRECEIVED THAT MSG\n")
  29. }
  30. func chatDidNotSetDefaultPrivacyList(withName name: String, error: Any?) {
  31. print("\n -- Did not set default privacy list ----\n")
  32. print(" \n cannot set default : \(name) with the following error : \(error ?? "")\n")
  33. }
  34.  
  35. func chatDidNotSetActivePrivacyList(withName name: String, error: Any?) {
  36. print("\n -- Did not set active privacy list ----\n")
  37. print(" \n cannot set active : \(name) with the following error : \(error ?? "")\n")
  38. }
  39.  
  40. func chatDidSetDefaultPrivacyList(withName name: String) {
  41. print("\n -- Did set default privacy list : \(name)----\n")
  42. }
  43.  
  44. func chatDidSetActivePrivacyList(withName name: String) {
  45. print("\n -- Did set active privacy list : \(name)----\n")
  46. }
  47. func chatDidRemovedPrivacyList(withName name: String) {
  48. print("\n ---- List \(name) removed \n")
  49. }
  50.  
  51. func chatDidNotSetPrivacyList(withName name: String, error: Any?) {
  52. //QBChat.instance().retrievePrivacyList(withName: name)
  53. print(" \n ---- FAILED TO REMOVE LIST : \(name) ---- \n")
  54. print("\n --- chat did not set set privacy list : \(name)--- \n")
  55. print(error ?? "\n NO ERROR WHILE SETTING A NEW PRIVACY LIST\n")
  56. }
  57.  
  58. func chatDidReceive(_ privacyList: QBPrivacyList) {
  59.  
  60. print("\n----- chat did receive list -----\n")
  61.  
  62.  
  63. }
  64.  
  65. func chatDidNotReceivePrivacyList(withName name: String, error: Any?) {
  66. print("\n chat did not receive privacy list\n")
  67. }
  68.  
  69.  
  70.  
  71. func chatRoomDidReceive(_ message: QBChatMessage, fromDialogID dialogID: String) {
  72. print("\nmessage : \(message), and dialog is : \(dialogID)\n")
  73. }
  74.  
  75.  
  76. func chatDidReceiveSystemMessage(_ message: QBChatMessage) {
  77. print("\n the message is : \(message)\n ")
  78. }
  79.  
  80. override func viewDidLoad() {
  81. super.viewDidLoad()
  82. // Do any additional setup after loading the view, typically from a nib.
  83.  
  84. block_user_button.addTarget(self, action: #selector(removePrivacyList(button:)), for: .touchUpInside)
  85. logout_user_button.addTarget(self, action: #selector(logoutUser(button:)), for: .touchUpInside)
  86.  
  87. let user = QBUUser()
  88. user.id = 29777896
  89. user.password = "03121995"
  90.  
  91. QBChat.instance().addDelegate(self)
  92.  
  93. QBChat.instance().connect(with: user) {
  94. (error) in
  95. if error != nil {
  96. print("error: \(String(describing: error))")
  97. return
  98. } else {
  99. print("\nsuccess connecting to QB chat\n")
  100.  
  101. QBRequest.logIn(withUserLogin: "chem", password: "03121995", successBlock: { (response: QBResponse, user: QBUUser?) in
  102. print("\n ---------------> connected \n")
  103.  
  104.  
  105.  
  106. // here goes code
  107.  
  108. self.createNewListAndSetDefault()
  109.  
  110.  
  111.  
  112. })
  113. }
  114. }
  115.  
  116.  
  117. // chatDialog.occupantIDs = [29777896, 29782373]
  118.  
  119.  
  120. print("\n processing ... 👀\n")
  121.  
  122.  
  123.  
  124.  
  125. }
  126.  
  127.  
  128.  
  129.  
  130. func removePrivacyList(button: UIButton) {
  131.  
  132.  
  133. //QBChat.instance().retrievePrivacyList(withName: "public")
  134.  
  135. QBChat.instance().removePrivacyList(withName: "public")
  136.  
  137.  
  138.  
  139. }
  140.  
  141. func createNewListAndSetDefault() {
  142. let item: QBPrivacyItem = QBPrivacyItem(privacyType: QBPrivacyType.groupUserID , userID: 29782373, allow: false)!
  143. item.mutualBlock = true
  144. let privacyList = QBPrivacyList(name: "tmp", items: [item])
  145. QBChat.instance().setPrivacyList(privacyList)
  146. QBChat.instance().setDefaultPrivacyListWithName("tmp")
  147. QBChat.instance().setActivePrivacyListWithName("tmp")
  148.  
  149.  
  150. print("\n -- Done setting a new list as default -- \n")
  151. }
  152.  
  153.  
  154. func logoutUser(button: UIButton) {
  155. QBChat.instance().disconnect { (Error) in
  156. print(Error ?? "NO ERROR when disconnecting")
  157. }
  158. QBRequest.logOut(successBlock: { (QBResponse) in
  159. print(QBResponse)
  160. print("\n ----- Log out successfull ------ \n")
  161. }) { (QBResponse) in
  162. print("\n ----- Log out error ------ \n")
  163. print(QBResponse)
  164. }
  165. }
  166.  
  167. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement