群组管理

新建群组

createGroupBtn.onClick.AddListener (delegate () {
    if (groupName.text.Length > 0) {
        EMGroupCallback cb = new EMGroupCallback ();
        cb.onSuccessCreateGroupCallback = (group) => {
            logText.text = "create group success";
        };
        cb.onErrorCallback = (code, msg) => {
            logText.text = msg;
        };
        EMClient.Instance.createGroup (groupName.text, "desc:" + groupName.text, new string[0], "reason", 200, (GroupStyle)groupStyle.value, cb);
    }
});

加入群组

joinGroupBtn.onClick.AddListener (delegate () {
    EMBaseCallback cb = new EMBaseCallback();
    cb.onSuccessCallback = () => {
        logText.text = "join group success";
    };
    cb.onProgressCallback = (progress,status) => {};
    cb.onErrorCallback = (code,msg) => {
        logText.text = "join group failure msg=" + msg;
    };
    if(groupName.text.Length > 0)
        EMClient.Instance.joinGroup(groupName.text,cb);
    else
        logText.text = "input group id first";
});

退出群组

leaveGroupBtn.onClick.AddListener (delegate () {
    EMBaseCallback cb = new EMBaseCallback();
    cb.onSuccessCallback = () => {
        logText.text = "leave group success";
    };
    cb.onProgressCallback = (progress,status) => {};
    cb.onErrorCallback = (code,msg) => {
        logText.text = msg;
    };
    if(groupName.text.Length > 0)
        EMClient.Instance.leaveGroup(groupName.text,cb);
    else
        logText.text = "input group id first";
});

获取当前用户已经加入群组

getGroupsBtn.onClick.AddListener (delegate() {
    logText.text = "";
    groupList.Clear();
    EMGroupCallback cb = new EMGroupCallback();
    cb.onSuccessGetGroupListCallback = (groups) => {
        foreach(EMGroup group in groups){
            logText.text += "ID="+group.mGroupId + "," + group.mGroupName + "\n";
            groupList.Add(group);
            groupName.text = group.mGroupId;
        }
        logContent.sizeDelta = new Vector2 (0, logText.preferredHeight+5);
    };
    cb.onErrorCallback = (code,msg) => {
        logText.text = msg;
    };
    EMClient.Instance.getJoinedGroupsFromServer(cb);
});

群组加人

addToGroupBtn.onClick.AddListener (delegate() {
    EMBaseCallback cb = new EMBaseCallback();
    cb.onSuccessCallback = () => {
        logText.text = "add user to group success";
    };
    cb.onProgressCallback = (progress,status) => {};
    cb.onErrorCallback = (code,msg) => {
        logText.text = "failed to addUsersToGroup: " + msg;
    };
    string[] users = {groupUser.text};
    EMClient.Instance.addUsersToGroup(groupName.text,users,cb);
});

获取群组详情

GroupInfoBtn.onClick.AddListener(delegate() {
    if(groupName.text.Length > 0){
        EMGroup group = EMClient.Instance.getGroup(groupName.text);
        if(group != null)
            logText.text = "name="+group.mGroupName+",id="+group.mGroupId;
    }
    else
        logText.text = "input group id first";
});

上一章节:消息

下一页:会话管理