群组

群组结构

group:{
    gid:"",
    name:"",
    members:['account1','account2'],
    owner:'account1',
    limit:500,
    is_public:true,
    is_request:false,
    avatar:"",
    type:0, // 0 person 1 fixed
}
参数 说明
gid 群组ID
name 群组名称
members 群组成员
owner 群主
limit 群成员人数限制
is_public 0 不公开 1 公开 (公开的群能被搜索到)
is_request 0 不需要申请入群 1 需申请入群
avatar 群头像

群组列表

var _ = this ;
var uid = IM.my.id;
var options = {
    success:function(data){
        _.loading = 0;
        _.groups = data.list;
        _.groups_search = _.groups;
    },
    fail:function(res){
        _.$alert(res.errmsg);
    }
};
IM.groupManager.getGroupList(options);

创建群组

var options = {
    name:"",
    members:[],
    owner:1,
    limit:500,
    is_public:true,
    is_request:false,
    avatar:"",
    type:0, 
    success:function(data){
    },
    fail:function(data){
        _.$alert(res.errmsg);
    },
}

IM.groupManager.createGroup(options);

得到群详情

var _ = this ;
var options = {
    group_id:this.$route.query.id,
    user_limit:8,
    success:function(data){
        data.members.sort(IM.groupManager.utils.sortBy('role', true, parseInt));
        _.owner = IM.groupManager.utils.listSearchOne(data.members,"account",IM.my.id);
        _.creator = IM.groupManager.utils.listSearchOne(data.members,"role",2);
        _.group = data ;
    },
    fail:function(res){
        _.$alert(res.errmsg);
    }
};
IM.groupManager.getGroupInfo(options);

修改群组

var options = {
    group_id:_.group.gid,
    avatar:value,
    success:function(res){
        _.group.avatar = value ;
    },
    fail:function(res){
        _.$alert(res.errmsg);
    }
};
IM.groupManager.updateGroupAttr(options);

删除(销毁)群组

只有群主才有删除(销毁)功能

var _ = this ;
var options = {
    group_id:_.group.gid,
    success:function(res){
        _.$router.push({ path: '/chat'});
    },
    fail:function(res){        
        _.$alert(res.errmsg);
    }
};
IM.groupManager.dissolveGroup(options);

退出群

var _ = this ;
var options = {
    group_id:_.group.gid,
    success:function(data){
        _.$router.push({ path: '/chat'});
    },
    fail:function(res){
        _.$alert(res.errmsg);
    }
};
IM.groupManager.leaveGroup(options);

转让群

var _ = this;
var options = {
    group_id:this.$route.query.id,
    owner:this.owner,
    success:function(data){
        _.goBack();
    },
    fail:function(res){
        _.$tip(res.errmsg);
    }
};
IM.groupManager.setGroupOwner(options);

搜索群

var _ = this ;
var options = {
    key:_.searchkey,
    success:function(data){
        _.loading = 0;
        _.groups = data.list;
    },
    fail:function(res){
        _.loading = 0;
        _.$alert(res.errmsg);
    }
};
_.loading = 1;
IM.groupManager.searchGroup(options);

申请加入群

var _ = this ;
var options = {
    group_id:group.gid,
    request_reason:"",
    success:function(data){
        _.groups[key].is_request = 1;
        _.$alert("申请已经发送");
    },
    fail:function(res){
        _.groups[key].is_request = 2;
        _.$alert(res.errmsg);
    }
};
IM.groupManager.joinGroup(options);

获得群申请列表

var _ = this ;
var options = {
    success:function(data){
        _.loading = 0 ;
        _.requests = data;
    },
    fail:function(res){
        _.loading = 0 ;
        _.$alert(res.errmsg);
    }
};
_.loading = 1 ;
IM.groupManager.getGroupRequestList(options);

处理群申请

var _ = this;
var options = {
    account:request.account,
    group_id:request.target_id,
    deal_status:status,
    deal_reason:"",
    success:function(res){
        request.deal_status = status;
    },
    fail:function(res){
        _.$alert(res.errmsg);
    }
};
IM.groupManager.dealGroupRequest(options);

加入群黑名称

var _ = this;
var options = {
    group_id:request.target_id,
    block_account:request.account,
    success:function(res){
        request.deal_status = 2;
    },
    fail:function(res){
        _.$alert(res.errmsg);
    }
};
IM.groupManager.setGroupBlock(options);

设置禁言

//mute_expire 0 不禁言 -1 禁言  >0 禁言截止时间戳
item.mute_expire = (item.mute_expire == 0?-1:0);
var options = {
    group_id:group_id,
    user:item.account,
    value:item.mute_expire,
    success:function(data){
    }
};
IM.groupManager.setGroupMute(options);

添加群成员

var _ = this;
var options = {
    group_id:this.group.gid,
    members:['account1','account2'],
    success:function(){
    },
    fail:function(res){
        _.$alert(res.errmsg);
    }
}
IM.groupManager.addGroupMembers(options);

删除群成员

var options = {
    group_id:_.group.gid,
    members:['account1','account2'],
    success:function(res){
    },
    fail:function(res){
        _.$alert(res.errmsg);
    }
}
IM.groupManager.removeGroupMembers(options);

获到群公告

var _ = this ;
_.loading = 1 ;
_.group.id = this.$route.query.id ;
_.group.name = this.$route.query.title ;
var options = {
    group_id:_.group.id,
    success:function(list){
        _.loading = 0 ;
        _.list = list ;
    }
};
IM.groupManager.getGroupNotifys(options);

发布群公告

var _ = this;
var options = {
    group_id:"",
    notice:"",
    account:"account1",
    success:function(data){
    },
    fail:function(res){
        _.$tip(res.errmsg);
    },
}
IM.groupManager.createGroupNotify(options);

删除群公告

var options = {
    group_id:_.group.id,
    notice_id:item.gid,
    success:function(res){
        var index = _.list.indexOf(item);
        if (index>-1){
            _.list.splice(index,1); 
        }
    },
    fail:function(){
        _.$tip(res.errmsg);
    }
};
IM.groupManager.deleteGroupNotify(options);

获到群文件

var options = {
    group_id:_.group.id,
    success:function(res){
        _.loading = 0 ;
        _.list = res.list ;
    }
};
IM.groupManager.getGroupFiles(options);

发布群文件

let fileForm = document.getElementById("fileForm");
let formData = new FormData(fileForm);
if (fileForm.value == ""){
    return ;
}

var _ = this ;
formData.append("group_id",_.group.id);
formData.append("type",'group');
formData.append("account",IM.my.id);
_.isUploading = true;
IM.groupManager.uploadFile(formData,function(res){
    if (res.status == 1){
        _.isUploading = false;
        _.list.push(res.data);
    }else{
        _.$alert(res.errmsg);
    }

})

删除群文件

var options = {
    group_id:_.group.id,
    file_id:item.gid,
    success:function(res){
        var index = _.list.indexOf(item);
        if (index>-1){
            _.list.splice(index,1); 
        }
    },
    fail:function(res){
        _.$tip(res.errmsg);
    }
};
IM.groupManager.deleteGroupFile(options);

results matching ""

    No results matching ""