# User Client ```kotlin val userClient = SportsTalk247.UserClient( config = ClientConfig( appId = "c84cb9c852932a6b0411e75e", // This is just a sample app id apiToken = "5MGq3XbsspBEQf3kj154_OSQV-jygEKwHJyuHjuAeWHA", // This is just a sample token endpoint = "http://api.custom.endpoint/v3/" // This is just a sample API endpoint ) ) ``` ## Create or Update User Invoke this function if you want to create a user or update an existing user. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val createdUser = withContext(Dispatchers.IO) { userClient.createOrUpdateUser( request = CreateUpdateUserRequest( userid = "023976080242ac120002", handle = "sample_handle_123", displayname = "Test Name 123", // OPTIONAL pictureurl = "", // OPTIONAL profileurl = "" // OPTIONAL ) ) } // Resolve `createdUser` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.createOrUpdateUser( request = CreateUpdateUserRequest( userid = "023976080242ac120002", handle = "sample_handle_123", displayname = "Test Name 123", // OPTIONAL pictureurl = "", // OPTIONAL profileurl = "" // OPTIONAL ) ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { createdUser -> // Resolve `createdUser` (ex. Display prompt OR Update UI) } ``` ## Get User Details This will return all the information about the user. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val userDetails = withContext(Dispatchers.IO) { userClient.getUserDetails( userid = "023976080242ac120002" ) } // Resolve `userDetails` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.getUserDetails( userid = "023976080242ac120002" ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { userDetails -> // Resolve `userDetails` (ex. Display prompt OR Update UI) } ``` ## List Users Use this function to cursor through a list of users. This function will return users in the order in which they were created, so it is safe to add new users while cursoring through the list. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val listUsers = withContext(Dispatchers.IO) { userClient.listUsers( limit = 10, /* Defaults to 200 on backend API server */ cursor = null // OPTIONAL: The cursor value from previous search attempt to indicate next paginated fetch. Null if fetching the first list of user(s). ) } // Resolve `listUsers` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.listUsers( limit = 10, /* Defaults to 200 on backend API server */ cursor = null // OPTIONAL: The cursor value from previous search attempt to indicate next paginated fetch. Null if fetching the first list of user(s). ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { listUsers -> // Resolve `listUsers` (ex. Display prompt OR Update UI) } ``` ## Ban User This function toggles the specified user's `banned` flag. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val bannedUser = withContext(Dispatchers.IO) { userClient.setBanStatus( userid = "023976080242ac120002", applyeffect = true, // If set to true, attempt to ban the user. If set to false, attempt to remove the ban from user expireseconds = 3600 // [Optional] if not specified, the ban is permanent until user is restored. If specified, then the ban will be temporarily applied for the specified number of seconds. ) } // Resolve `bannedUser` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.setBanStatus( userid = "023976080242ac120002", applyeffect = true, // If set to true, attempt to ban the user. If set to false, attempt to remove the ban from user expireseconds = 3600 // [Optional] if not specified, the ban is permanent until user is restored. If specified, then the ban will be temporarily applied for the specified number of seconds. ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { bannedUser -> // Resolve `bannedUser` (ex. Display prompt OR Update UI) } ``` ## Globally Purge User Content This function will purge all chat content published by the specified user. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val response = withContext(Dispatchers.IO) { userClient.globallyPurgeUserContent( userid = "023976080242ac120002", // ID of the User who's content is about to be purged byuserid = "1234567890" // ID of the User who is about to perform the purge action(requires admin privileges) ) } // Resolve `response` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.globallyPurgeUserContent( userid = "023976080242ac120002", // ID of the User who's content is about to be purged byuserid = "1234567890" // ID of the User who is about to perform the purge action(requires admin privileges) ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { response -> // Resolve `response` (ex. Display prompt OR Update UI) } ``` ## Mute User This function toggles the specified user's mute effect. A muted user is in a read-only state. The muted user can join chat rooms and observe but cannot communicate. This method applies mute on the global level (applies to all talk contexts). You can optionally specify an expiration time. If the expiration time is specified, then each time the shadow banned user tries to send a message the API will check if the shadow ban has expired and will lift the ban. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val mutedUser = withContext(Dispatchers.IO) { userClient.muteUser( userId = "023976080242ac120002", applyeffect = true, // If set to true, user will be set to muted state. Otherwise, will be set to non-banned state. expireseconds = 3600 // [OPTIONAL]: Duration of mute in seconds. If specified, the mute will be lifted when this time is reached. If not specified, mute effect remains until explicitly lifted. Maximum seconds is a double byte value. ) } // Resolve `mutedUser` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.muteUser( userId = "023976080242ac120002", applyeffect = true, // If set to true, user will be set to muted state. Otherwise, will be set to non-banned state. expireseconds = 3600 // [OPTIONAL]: Duration of mute in seconds. If specified, the mute will be lifted when this time is reached. If not specified, mute effect remains until explicitly lifted. Maximum seconds is a double byte value. ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { mutedUser -> // Resolve `mutedUser` (ex. Display prompt OR Update UI) } ``` ## Set Shadow Ban Status This function toggles the specified user's `shadowbanned` flag. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val shadowBannedUser = withContext(Dispatchers.IO) { userClient.setShadowBanStatus( userId = "023976080242ac120002", applyeffect = true, // If set to true, user can send messages into a chat room, however those messages are flagged as shadow banned. expireseconds = 3600 // [OPTIONAL]: Duration of shadowban value in seconds. If specified, the shadow ban will be lifted when this time is reached. If not specified, shadowban remains until explicitly lifted. Maximum seconds is a double byte value. ) } // Resolve `shadowBannedUser` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.setShadowBanStatus( userId = "023976080242ac120002", applyeffect = true, // If set to true, user can send messages into a chat room, however those messages are flagged as shadow banned. expireseconds = 3600 // [OPTIONAL]: Duration of shadowban value in seconds. If specified, the shadow ban will be lifted when this time is reached. If not specified, shadowban remains until explicitly lifted. Maximum seconds is a double byte value. ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { shadowBannedUser -> // Resolve `shadowBannedUser` (ex. Display prompt OR Update UI) } ``` ## Search User(s) This function searches the users in an app. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) // Search by Handle val searchedUsersByHandle = withContext(Dispatchers.IO) { userClient.searchUsers( handle = "testhandle1", limit = 20, // Defaults to 200 on backend API server cursor = null // OPTIONAL: The cursor value from previous search attempt to indicate next paginated fetch. Null if fetching the first list of user(s). ) } // Search by Name val searchedUsersByName = withContext(Dispatchers.IO) { userClient.searchUsers( name = "Josie Rizal", limit = 20, // Defaults to 200 on backend API server cursor = null // OPTIONAL: The cursor value from previous search attempt to indicate next paginated fetch. Null if fetching the first list of user(s). ) } // Search by User ID val searchedUsersByUserId = withContext(Dispatchers.IO) { userClient.searchUsers( userid = "userid_georgew", limit = 20, // Defaults to 200 on backend API server cursor = null // OPTIONAL: The cursor value from previous search attempt to indicate next paginated fetch. Null if fetching the first list of user(s). ) } } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() // Search by Handle userClient.searchUsers( handle = "testhandle1", limit = 20, // Defaults to 200 on backend API server cursor = null // OPTIONAL: The cursor value from previous search attempt to indicate next paginated fetch. Null if fetching the first list of user(s). ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { searchedUsersByHandle -> // Resolve `searchedUsersByHandle` (ex. Display prompt OR Update UI) } // Search by Name userClient.searchUsers( name = "Josie Rizal", limit = 20, // Defaults to 200 on backend API server cursor = null // OPTIONAL: The cursor value from previous search attempt to indicate next paginated fetch. Null if fetching the first list of user(s). ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { searchedUsersByName -> // Resolve `searchedUsersByName` (ex. Display prompt OR Update UI) } // Search by User ID userClient.searchUsers( userid = "userid_georgew", limit = 20, // Defaults to 200 on backend API server cursor = null // OPTIONAL: The cursor value from previous search attempt to indicate next paginated fetch. Null if fetching the first list of user(s). ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { searchedUsersByUserId -> // Resolve `searchedUsersByUserId` (ex. Display prompt OR Update UI) } ``` ## Delete User This function will delete the specified user. All rooms with messages by that user will have the messages from this user purged in the rooms. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val deletedUser = withContext(Dispatchers.IO) { userClient.deleteUser( userid = "023976080242ac120002" ) } // Resolve `deletedUser` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.deleteUser( userid = "023976080242ac120002" ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { deletedUser -> // Resolve `deletedUser` (ex. Display prompt OR Update UI) } ``` ## Report User This function REPORTS a USER to the moderation team. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val reportedUser = withContext(Dispatchers.IO) { userClient.reportUser( userid = "023976080242ac120002" ) } // Resolve `reportedUser` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.reportUser( userid = "023976080242ac120002" ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { reportedUser -> // Resolve `reportedUser` (ex. Display prompt OR Update UI) } ``` ## List User Notifications This function returns a list of user notifications. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val listUserNotifications = withContext(Dispatchers.IO) { userClient.listUserNotifications( userid = "023976080242ac120002", limit = 10, // Can be any arbitrary number filterNotificationTypes = listOf(UserNotification.Type.CHAT_REPLY, UserNotification.Type.CHAT_QUOTE), // [OPTIONAL] List could also have either `CHAT_REPLY` or `CHAT_QUOTE` ONLY cursor = null, includeread = false, // If [true], will only return a list of user notifications whose value `isread = true`. Otherwise, returns a list of user notifications whose value `isread = false`. filterChatRoomId = "080001297623242ac002", // ID of an existing chat room filterChatRoomCustomId = null // OR you may also use an existing chat room's custom ID ) } // Resolve `listUserNotifications` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.listUserNotifications( userid = "023976080242ac120002", limit = 10, // Can be any arbitrary number filterNotificationTypes = listOf(UserNotification.Type.CHAT_REPLY, UserNotification.Type.CHAT_QUOTE), // [OPTIONAL] List could also have either `CHAT_REPLY` or `CHAT_QUOTE` ONLY cursor = null, includeread = false, // If [true], will only return a list of user notifications whose value `isread = true`. Otherwise, returns a list of user notifications whose value `isread = false`. filterChatRoomId = "080001297623242ac002", // ID of an existing chat room filterChatRoomCustomId = null // OR you may also use an existing chat room's custom ID ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { listUserNotifications -> // Resolve `listUserNotifications` (ex. Display prompt OR Update UI) } ``` ## Set User Notification as Read This marks a notification as being in READ status. That will prevent the notification from being returned in a call to List User Notifications unless the default filters are overridden. Notifications that are marked as read will be automatically deleted after some time. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val updatedNotification = withContext(Dispatchers.IO) { userClient.setUserNotificationAsRead( userid = "023976080242ac120002", // The ID of user who owns the notification about to update notificationId = "070200623280c142a902", // The ID of notifications about to update read = true ) } // Resolve `updatedNotification` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.setUserNotificationAsRead( userid = "023976080242ac120002", // The ID of user who owns the notification about to update notificationId = "070200623280c142a902", // The ID of notifications about to update read = true ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { updatedNotification -> // Resolve `updatedNotification` (ex. Display prompt OR Update UI) } ``` ## Set User Notification as Read by Chat Event This marks a notification as being in READ status. That will prevent the notification from being returned in a call to List User Notifications unless the default filters are overridden. Notifications that are marked as read will be automatically deleted after some time. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val updatedNotification = withContext(Dispatchers.IO) { userClient.setUserNotificationAsReadByChatEvent( userid = "023976080242ac120002", // The ID of user who owns the notification about to update chatEventId = "070200623280c142a902", // The ID of chatevent for which the notification was generated from, about to update read = true ) } // Resolve `updatedNotification` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.setUserNotificationAsReadByChatEvent( userid = "023976080242ac120002", // The ID of user who owns the notification about to update chatEventId = "070200623280c142a902", // The ID of chatevent for which the notification was generated from, about to update read = true ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { updatedNotification -> // Resolve `updatedNotification` (ex. Display prompt OR Update UI) } ``` ## Delete User Notification This function immediately deletes a user notification. Unless your workflow specifically implements access to read notifications, you should delete notifications after they are consumed. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val deletedNotification = withContext(Dispatchers.IO) { userClient.deleteUserNotification( userid = "023976080242ac120002", // The ID of user who owns the notification about to delete notificationId = "070200623280c142a902" // The ID of notifications about to delete ) } // Resolve `deletedNotification` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.deleteUserNotification( userid = "023976080242ac120002", // The ID of user who owns the notification about to delete notificationId = "070200623280c142a902" // The ID of notifications about to delete ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { deletedNotification -> // Resolve `deletedNotification` (ex. Display prompt OR Update UI) } ``` ## Delete User Notification by Chat Event This function immediately deletes a user notification. Unless your workflow specifically implements access to read notifications, you should delete notifications after they are consumed. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) val deletedNotification = withContext(Dispatchers.IO) { userClient.deleteUserNotificationByChatEvent( userid = "023976080242ac120002", // The ID of user who owns the notification about to update chatEventId = "070200623280c142a902" // The ID of chatevent for which the notification was generated from, about to delete ) } // Resolve `deletedNotification` from HERE onwards(ex. update UI displaying the response data)... } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.deleteUserNotificationByChatEvent( userid = "023976080242ac120002", // The ID of user who owns the notification about to update chatEventId = "070200623280c142a902" // The ID of chatevent for which the notification was generated from, about to delete ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { deletedNotification -> // Resolve `deletedNotification` (ex. Display prompt OR Update UI) } ``` ## Mark All User Notifications as Read This marks a all notifications of the user as being in READ status. If delete is set to true, notifications are deleted instead of updated. Refer to the SportsTalk API Documentation for more details: Below is a code sample on how to use this SDK feature: ``` tabs:: .. code-tab:: kotlin sdk-coroutine // Launch thru coroutine block // https://developer.android.com/topic/libraries/architecture/coroutines lifecycleScope.launch { // Switch to IO Coroutine Context(Operation will be executed on IO Thread) withContext(Dispatchers.IO) { userClient.markAllUserNotificationsAsRead( userid = "023976080242ac120002", // The ID of user who owns the notification about to update delete = true ) } } .. code-tab:: kotlin sdk-reactive-rx2 val rxDisposeBag = CompositeDisposable() userClient.markAllUserNotificationsAsRead( userid = "023976080242ac120002", // The ID of user who owns the notification about to update delete = true ) .subscribeOn(Schedulers.io()) .observeOn(AndroidSchedulers.mainThread()) .doOnSubscribe { rxDisposeBag.add(it) } .subscribe { // Do something afterwards... } ```