/** 请求未读消息列表 */ private void reqUnreadMsgContactList() { logger.i("unread#1reqUnreadMsgContactList"); int loginId = IMLoginManager.instance().getLoginId(); IMMessage.IMUnreadMsgCntReq unreadMsgCntReq = IMMessage.IMUnreadMsgCntReq.newBuilder().setUserId(loginId).build(); int sid = IMBaseDefine.ServiceID.SID_MSG_VALUE; int cid = IMBaseDefine.MessageCmdID.CID_MSG_UNREAD_CNT_REQUEST_VALUE; imSocketManager.sendRequest(unreadMsgCntReq, sid, cid); }
/** 联系人页面正式群的请求 todo 正式群与临时群逻辑上的分开的,但是底层应该是想通的 */ private void reqGetNormalGroupList() { logger.i("group#reqGetNormalGroupList"); int loginId = imLoginManager.getLoginId(); IMGroup.IMNormalGroupListReq normalGroupListReq = IMGroup.IMNormalGroupListReq.newBuilder().setUserId(loginId).build(); int sid = IMBaseDefine.ServiceID.SID_GROUP_VALUE; int cid = IMBaseDefine.GroupCmdID.CID_GROUP_NORMAL_LIST_REQUEST_VALUE; imSocketManager.sendRequest(normalGroupListReq, sid, cid); logger.i("group#send packet to server"); }
public void ackReadMsg(UnreadEntity unreadEntity) { logger.d("chat#ackReadMsg -> msg:%s", unreadEntity); int loginId = loginManager.getLoginId(); IMBaseDefine.SessionType sessionType = Java2ProtoBuf.getProtoSessionType(unreadEntity.getSessionType()); IMMessage.IMMsgDataReadAck readAck = IMMessage.IMMsgDataReadAck.newBuilder() .setMsgId(unreadEntity.getLaststMsgId()) .setSessionId(unreadEntity.getPeerId()) .setSessionType(sessionType) .setUserId(loginId) .build(); int sid = IMBaseDefine.ServiceID.SID_MSG_VALUE; int cid = IMBaseDefine.MessageCmdID.CID_MSG_READ_ACK_VALUE; imSocketManager.sendRequest(readAck, sid, cid); }
/** 请求群组的详细信息 */ public void reqGetGroupDetailInfo(List<IMBaseDefine.GroupVersionInfo> versionInfoList) { logger.i("group#reqGetGroupDetailInfo"); if (versionInfoList == null || versionInfoList.size() <= 0) { logger.e("group#reqGetGroupDetailInfo# please check your params,cause by empty/null"); return; } int loginId = imLoginManager.getLoginId(); IMGroup.IMGroupInfoListReq groupInfoListReq = IMGroup.IMGroupInfoListReq.newBuilder() .setUserId(loginId) .addAllGroupVersionList(versionInfoList) .build(); int sid = IMBaseDefine.ServiceID.SID_GROUP_VALUE; int cid = IMBaseDefine.GroupCmdID.CID_GROUP_INFO_REQUEST_VALUE; imSocketManager.sendRequest(groupInfoListReq, sid, cid); }
/** 创建群 默认是创建临时群,且客户端只能创建临时群 */ public void reqCreateTempGroup(String groupName, Set<Integer> memberList) { logger.i("group#reqCreateTempGroup, tempGroupName = %s", groupName); int loginId = imLoginManager.getLoginId(); IMGroup.IMGroupCreateReq groupCreateReq = IMGroup.IMGroupCreateReq.newBuilder() .setUserId(loginId) .setGroupType(IMBaseDefine.GroupType.GROUP_TYPE_TMP) .setGroupName(groupName) .setGroupAvatar("") // todo 群头像 现在是四宫格 .addAllMemberIdList(memberList) .build(); int sid = IMBaseDefine.ServiceID.SID_GROUP_VALUE; int cid = IMBaseDefine.GroupCmdID.CID_GROUP_CREATE_REQUEST_VALUE; imSocketManager.sendRequest( groupCreateReq, sid, cid, new Packetlistener() { @Override public void onSuccess(Object response) { try { IMGroup.IMGroupCreateRsp groupCreateRsp = IMGroup.IMGroupCreateRsp.parseFrom((CodedInputStream) response); IMGroupManager.instance().onReqCreateTempGroup(groupCreateRsp); } catch (IOException e) { logger.e("reqCreateTempGroup parse error"); triggerEvent(new GroupEvent(GroupEvent.Event.CREATE_GROUP_FAIL)); } } @Override public void onFaild() { triggerEvent(new GroupEvent(GroupEvent.Event.CREATE_GROUP_FAIL)); } @Override public void onTimeout() { triggerEvent(new GroupEvent(GroupEvent.Event.CREATE_GROUP_TIMEOUT)); } }); }
private void reqChangeGroupMember( int groupId, IMBaseDefine.GroupModifyType groupModifyType, Set<Integer> changeMemberlist) { logger.i("group#reqChangeGroupMember, changeGroupMemberType = %s", groupModifyType.toString()); final int loginId = imLoginManager.getLoginId(); IMGroup.IMGroupChangeMemberReq groupChangeMemberReq = IMGroup.IMGroupChangeMemberReq.newBuilder() .setUserId(loginId) .setChangeType(groupModifyType) .addAllMemberIdList(changeMemberlist) .setGroupId(groupId) .build(); int sid = IMBaseDefine.ServiceID.SID_GROUP_VALUE; int cid = IMBaseDefine.GroupCmdID.CID_GROUP_CHANGE_MEMBER_REQUEST_VALUE; imSocketManager.sendRequest( groupChangeMemberReq, sid, cid, new Packetlistener() { @Override public void onSuccess(Object response) { try { IMGroup.IMGroupChangeMemberRsp groupChangeMemberRsp = IMGroup.IMGroupChangeMemberRsp.parseFrom((CodedInputStream) response); IMGroupManager.instance().onReqChangeGroupMember(groupChangeMemberRsp); } catch (IOException e) { logger.e("reqChangeGroupMember parse error!"); triggerEvent(new GroupEvent(GroupEvent.Event.CHANGE_GROUP_MEMBER_FAIL)); } } @Override public void onFaild() { triggerEvent(new GroupEvent(GroupEvent.Event.CHANGE_GROUP_MEMBER_FAIL)); } @Override public void onTimeout() { triggerEvent(new GroupEvent(GroupEvent.Event.CHANGE_GROUP_MEMBER_TIMEOUT)); } }); }
/** 屏蔽群消息 IMGroupShieldReq 备注:应为屏蔽之后大部分操作依旧需要客户端做 */ public void reqShieldGroup(final int groupId, final int shieldType) { final GroupEntity entity = groupMap.get(groupId); if (entity == null) { logger.i("GroupEntity do not exist!"); return; } final int loginId = IMLoginManager.instance().getLoginId(); IMGroup.IMGroupShieldReq shieldReq = IMGroup.IMGroupShieldReq.newBuilder() .setShieldStatus(shieldType) .setGroupId(groupId) .setUserId(loginId) .build(); int sid = IMBaseDefine.ServiceID.SID_GROUP_VALUE; int cid = IMBaseDefine.GroupCmdID.CID_GROUP_SHIELD_GROUP_REQUEST_VALUE; imSocketManager.sendRequest( shieldReq, sid, cid, new Packetlistener() { @Override public void onSuccess(Object response) { try { IMGroup.IMGroupShieldRsp groupShieldRsp = IMGroup.IMGroupShieldRsp.parseFrom((CodedInputStream) response); int resCode = groupShieldRsp.getResultCode(); if (resCode != 0) { triggerEvent(new GroupEvent(GroupEvent.Event.SHIELD_GROUP_FAIL)); return; } if (groupShieldRsp.getGroupId() != groupId || groupShieldRsp.getUserId() != loginId) { return; } // 更新DB状态 entity.setStatus(shieldType); dbInterface.insertOrUpdateGroup(entity); // 更改未读计数状态 boolean isFor = shieldType == DBConstant.GROUP_STATUS_SHIELD; IMUnreadMsgManager.instance() .setForbidden( EntityChangeEngine.getSessionKey(groupId, DBConstant.SESSION_TYPE_GROUP), isFor); triggerEvent(new GroupEvent(GroupEvent.Event.SHIELD_GROUP_OK, entity)); } catch (IOException e) { logger.e("reqChangeGroupMember parse error!"); triggerEvent(new GroupEvent(GroupEvent.Event.SHIELD_GROUP_FAIL)); } } @Override public void onFaild() { triggerEvent(new GroupEvent(GroupEvent.Event.SHIELD_GROUP_FAIL)); } @Override public void onTimeout() { triggerEvent(new GroupEvent(GroupEvent.Event.SHIELD_GROUP_TIMEOUT)); } }); }