All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.hn.im.easemob.api.impl.EasemobChatGroup Maven / Gradle / Ivy

There is a newer version: 1.0.18
Show newest version
package com.hn.im.easemob.api.impl;

import com.hn.im.easemob.api.ChatGroupAPI;
import com.hn.im.easemob.api.EasemobRestAPI;
import com.hn.im.easemob.comm.constant.HTTPMethod;
import com.hn.im.easemob.comm.helper.HeaderHelper;
import com.hn.im.easemob.comm.wrapper.BodyWrapper;
import com.hn.im.easemob.comm.wrapper.HeaderWrapper;
import com.hn.im.easemob.comm.wrapper.QueryWrapper;
import cn.hutool.core.util.StrUtil;

public class EasemobChatGroup extends EasemobRestAPI implements ChatGroupAPI {
    private static final String ROOT_URI = "/chatgroups";

    public Object getChatGroups(Long limit, String cursor) {
        String url = getContext().getSeriveURL() + getResourceRootURI();
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();
        QueryWrapper query = QueryWrapper.newInstance().addLimit(limit).addCursor(cursor);

        return getInvoker().sendRequest(HTTPMethod.METHOD_GET, url, header, null, query);
    }

    public Object getChatGroupDetails(String[] groupIds) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + StrUtil.join(",",groupIds);
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_GET, url, header, null, null);
    }

    public Object createChatGroup(Object payload) {
        String url = getContext().getSeriveURL() + getResourceRootURI();
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();
        BodyWrapper body = (BodyWrapper) payload;

        return getInvoker().sendRequest(HTTPMethod.METHOD_POST, url, header, body, null);
    }

    public Object modifyChatGroup(String groupId, Object payload) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId;
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();
        BodyWrapper body = (BodyWrapper) payload;

        return getInvoker().sendRequest(HTTPMethod.METHOD_PUT, url, header, body, null);
    }

    public Object deleteChatGroup(String groupId) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId;
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_DELETE, url, header, null, null);
    }

    public Object getChatGroupUsers(String groupId) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/users";
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_GET, url, header, null, null);
    }

    public Object addSingleUserToChatGroup(String groupId, String userId) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/users/" + userId;
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_POST, url, header, null, null);
    }

    public Object addBatchUsersToChatGroup(String groupId, Object payload) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/users";
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();
        BodyWrapper body = (BodyWrapper) payload;

        return getInvoker().sendRequest(HTTPMethod.METHOD_POST, url, header, body, null);
    }

    public Object removeSingleUserFromChatGroup(String groupId, String userId) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/users/" + userId;
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_DELETE, url, header, null, null);
    }

    public Object removeBatchUsersFromChatGroup(String groupId, String[] userIds) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/users/" + StrUtil.join(",",userIds);
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_DELETE, url, header, null, null);
    }

    public Object transferChatGroupOwner(String groupId, Object payload) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId;
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();
        BodyWrapper body = (BodyWrapper) payload;

        return getInvoker().sendRequest(HTTPMethod.METHOD_PUT, url, header, body, null);
    }

    public Object getChatGroupBlockUsers(String groupId) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/blocks/users";
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_GET, url, header, null, null);
    }

    public Object addSingleBlockUserToChatGroup(String groupId, String userId) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/blocks/users/" + userId;
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_POST, url, header, null, null);
    }

    public Object addBatchBlockUsersToChatGroup(String groupId, Object payload) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/blocks/users";
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();
        BodyWrapper body = (BodyWrapper) payload;

        return getInvoker().sendRequest(HTTPMethod.METHOD_POST, url, header, body, null);
    }

    public Object removeSingleBlockUserFromChatGroup(String groupId, String userId) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/blocks/users/" + userId;
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_DELETE, url, header, null, null);
    }

    public Object removeBatchBlockUsersFromChatGroup(String groupId, String[] userIds) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/blocks/users/" + StrUtil.join(",", userIds);
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_DELETE, url, header, null, null);
    }

    /**
     *  添加禁言
     */
    public Object mute(String groupId,Object payload) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupId + "/mute";
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();
        BodyWrapper body = (BodyWrapper) payload;

        return getInvoker().sendRequest(HTTPMethod.METHOD_POST, url, header, body, null);
    }

    /**
     *  取消禁言
     */
    @Override
    public Object removeMute(String groupNum, String[] userIds) {
        String url = getContext().getSeriveURL() + getResourceRootURI() + "/" + groupNum + "/mute/" + StrUtil.join(",",userIds);
        HeaderWrapper header = HeaderHelper.getDefaultHeaderWithToken();

        return getInvoker().sendRequest(HTTPMethod.METHOD_DELETE, url, header, null, null);
    }


    @Override
    public String getResourceRootURI() {
        return ROOT_URI;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy