mirror of
https://gitee.com/xchao/j-im.git
synced 2024-12-02 11:57:43 +08:00
重构加入群组命令
This commit is contained in:
parent
25e462d34d
commit
8ee99e6e2b
@ -7,21 +7,37 @@ import java.util.List;
|
||||
|
||||
/**
|
||||
* 版本: [1.0]
|
||||
* 功能说明:
|
||||
* 功能说明: 用户群组
|
||||
* 作者: WChao 创建时间: 2017年9月21日 下午1:54:04
|
||||
*/
|
||||
public class Group extends Message{
|
||||
|
||||
private static final long serialVersionUID = -3817755433171220952L;
|
||||
private String group_id;
|
||||
private String name;//群组名称;
|
||||
private String avatar;//群组头像;
|
||||
private Integer online;//在线人数;
|
||||
private List<User> users;//组用户;
|
||||
/**
|
||||
* 群组ID
|
||||
*/
|
||||
private String groupId;
|
||||
/**
|
||||
* 群组名称
|
||||
*/
|
||||
private String name;
|
||||
/**
|
||||
* 群组头像
|
||||
*/
|
||||
private String avatar;
|
||||
/**
|
||||
* 在线人数
|
||||
*/
|
||||
private Integer online;
|
||||
/**
|
||||
* 组用户
|
||||
*/
|
||||
private List<User> users;
|
||||
|
||||
public Group(){}
|
||||
public Group(String group_id , String name){
|
||||
this.group_id = group_id;
|
||||
|
||||
public Group(String groupId , String name){
|
||||
this.groupId = groupId;
|
||||
this.name = name;
|
||||
}
|
||||
public String getName() {
|
||||
@ -49,10 +65,11 @@ public class Group extends Message{
|
||||
public void setUsers(List<User> users) {
|
||||
this.users = users;
|
||||
}
|
||||
public String getGroup_id() {
|
||||
return group_id;
|
||||
public String getGroupId() {
|
||||
return groupId;
|
||||
}
|
||||
public void setGroup_id(String group_id) {
|
||||
this.group_id = group_id;
|
||||
|
||||
public void setGroupId(String groupId) {
|
||||
this.groupId = groupId;
|
||||
}
|
||||
}
|
||||
|
@ -107,10 +107,6 @@ public class LoginServiceProcessor implements LoginCmdProcessor {
|
||||
return ImgMnService.nextImg();
|
||||
}
|
||||
|
||||
public String newToken() {
|
||||
return UUID.randomUUID().toString();
|
||||
}
|
||||
|
||||
/**
|
||||
* doLogin方法注意:J-IM登陆命令是根据user是否为空判断是否登陆成功,
|
||||
*
|
||||
@ -128,7 +124,6 @@ public class LoginServiceProcessor implements LoginCmdProcessor {
|
||||
@Override
|
||||
public void onSuccess(User user, ImChannelContext channelContext) {
|
||||
logger.info("登录成功回调方法");
|
||||
ImSessionContext imSessionContext = channelContext.getSessionContext();
|
||||
if(user.getGroups() != null){
|
||||
//发送加入群组通知
|
||||
for(Group group : user.getGroups()){
|
||||
|
@ -41,12 +41,13 @@ public class LoginReqHandler extends AbstractCmdHandler {
|
||||
ImSessionContext imSessionContext = imChannelContext.getSessionContext();
|
||||
LoginReqBody loginReqBody = JsonKit.toBean(packet.getBody(), LoginReqBody.class);
|
||||
LoginCmdProcessor loginProcessor = this.getSingleProcessor(LoginCmdProcessor.class);
|
||||
LoginRespBody loginRespBody = null;
|
||||
LoginRespBody loginRespBody = LoginRespBody.success();
|
||||
User user = null;
|
||||
if(Objects.nonNull(loginProcessor)){
|
||||
loginRespBody = loginProcessor.doLogin(loginReqBody, imChannelContext);
|
||||
if (Objects.isNull(loginRespBody) || loginRespBody.getCode() != ImStatus.C10007.getCode()) {
|
||||
log.warn("login failed, userId:{}, password:{}", loginReqBody.getUserId(), loginReqBody.getPassword());
|
||||
loginProcessor.onFailed(imChannelContext);
|
||||
Jim.bSend(imChannelContext, ProtocolManager.Converter.respPacket(loginRespBody, imChannelContext));
|
||||
Jim.remove(imChannelContext, "userId or token is incorrect");
|
||||
return null;
|
||||
@ -61,7 +62,7 @@ public class LoginReqHandler extends AbstractCmdHandler {
|
||||
imSessionContext.getClient().setUser(user);
|
||||
Jim.bindUser(imServerChannelContext, user.getUserId());
|
||||
//初始化绑定或者解绑群组;
|
||||
bindUnbindGroup(imChannelContext, user);
|
||||
//bindUnbindGroup(imChannelContext, user);
|
||||
loginProcessor.onSuccess(user, imChannelContext);
|
||||
return ProtocolManager.Converter.respPacket(loginRespBody, imChannelContext);
|
||||
}
|
||||
@ -83,7 +84,7 @@ public class LoginReqHandler extends AbstractCmdHandler {
|
||||
//绑定群组
|
||||
for(Group group : groups){
|
||||
if(isStore && groupIds != null){
|
||||
groupIds.remove(group.getGroup_id());
|
||||
groupIds.remove(group.getGroupId());
|
||||
}
|
||||
ImPacket groupPacket = new ImPacket(Command.COMMAND_JOIN_GROUP_REQ,JsonKit.toJsonBytes(group));
|
||||
try {
|
||||
|
@ -28,7 +28,7 @@ public interface LoginCmdProcessor extends SingleProtocolCmdProcessor {
|
||||
*/
|
||||
User getUser(LoginReqBody loginReqBody, ImChannelContext imChannelContext);
|
||||
/**
|
||||
* 登录成功回调方法
|
||||
* 登录成功(指的是J-IM会在用户校验完登陆逻辑后进行J-IM内部绑定)回调方法
|
||||
* @param imChannelContext
|
||||
*/
|
||||
void onSuccess(User user, ImChannelContext imChannelContext);
|
||||
|
Loading…
Reference in New Issue
Block a user