Change Member Scope
Change Scope of a Group Member
In order to change the scope of a group member, you can use the changeGroupMemberScope()
.
- Swift
let guid = "GUID"
let uid = "UID";
let scope:CometChat.MemberScope = .admin
CometChat.updateGroupMemberScope(UID: uid, GUID: guid, scope: scope, onSuccess: { (response) in
print("Update group member scope changed successfully.")
}) { (error) in
print("Update group member scope failed with error: " + error!.errorDescription);
}
This method takes the below parameters:
Paramter | Description |
---|---|
UID | The uid of the member |
GUID | The guid of the group for which the member's scope needs to be changed |
scope | The updated scope of the member. This can be either of the 3 values: 1. admin 2. moderator 3. participant |
The default scope of any member is participant
. Only the admin
of the group can change the scope of any participant in the group
Receive Real-Time Events
In other words, as a member of a group, how do I know when someone's scope is changed when my app is running?
In order to receive real-time events whenever a group member's scope changes, you will need to override the onGroupMemberScopeChanged()
method of the GroupListener
class.
You can receive live events related to ChangeMemberScope, In order to receive the Event, you must add protocol conformance CometChatGroupDelegate
as shown below:
- Swift
- Objective C
extension AppDelegate: CometChatGroupDelegate {
func onGroupMemberScopeChanged(action: ActionMessage, scopeChangeduser: User, scopeChangedBy: User, scopeChangedTo: String, scopeChangedFrom: String, group: Group) {
print("\(scopeChangedUser.name) scope changed from \(scopeChangedFrom) to \(scopeChangedTo) by \(scopeChangedBy.name) in the group \(group.name).")
}
}
@interface ViewController ()<CometChatGroupDelegate>
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[CometChat setGroupdelegate:self];
}
- (void)onGroupMemberScopeChangedWithAction:(Action *)action user:(User * _Nonnull)user scopeChangedTo:(NSString * _Nonnull)scopeChangedTo scopeChangedFrom:(NSString * _Nonnull)scopeChangedFrom group:(Group * _Nonnull)group {
// user scope changed
}
@end
Missed Group Member Scope Changed Events
In other words, as a member of a group, how do I know when someone's scope is changed when my app is not running?
When you retrieve the list of previous messages if a member's scope has been changed for any group that the logged-in user is a member of, the list of messages will contain an Action
message. An Action
message is a sub-class of BaseMessage
class.
For the group member scope changed event, in the Action
object received, the following fields can help you get the relevant information-
action
-scopeChanged
actionOn
- User object containing the details of the user whos scope has been changedactionBy
- User object containing the details of the user who changed the scope of the memberactionFor
- Group object containing the details of the group in which the member scope was changedoldScope
- The original scope of the membernewScope
- The updated scope of the member