Commit 7bf40747 by Future

加密聊天

parent 800059ef
......@@ -90,4 +90,8 @@ public class ImConversation extends BaseEntity {
@TableField("is_forbid_send_link")
@ApiModelProperty("禁止发链接")
private Boolean forbidSendLink;
@ApiModelProperty("是否为加密聊天 0-否 1-是")
private Integer isEncrypt;
}
......@@ -175,7 +175,7 @@ public class ImFriendService extends BaseServiceImpl<ImFriendMapper, ImFriend> {
this.updateByKey(friend);
}
// 检查是否存在会话,如果存在 将会话类型修改为1 单聊 双方都显示
ImConversation existConversation = imConversationMapper.getRepetitionConversationSingle(currentClient.getId(), friendClient.getId());
ImConversation existConversation = imConversationMapper.getRepetitionConversationSingle(currentClient.getId(), friendClient.getId(), 0);
if (existConversation != null && ChatTypeEnum.TEMP.getCode().equals(existConversation.getChatType())) {
existConversation.setChatType(ChatTypeEnum.SINGLE.getCode());
imConversationMapper.updateById(existConversation);
......
......@@ -63,9 +63,10 @@ public interface ImConversationMapper extends BaseMapper<ImConversation> {
*
* @param clientId1
* @param clientId2
* @param isEncrypt 是否加密会话 1-是 0-否
* @return
*/
ImConversation getRepetitionConversationSingle(@Param("clientId1") Long clientId1, @Param("clientId2") Long clientId2);
ImConversation getRepetitionConversationSingle(@Param("clientId1") Long clientId1, @Param("clientId2") Long clientId2, @Param("isEncrypt") Integer isEncrypt);
/**
* 判断重复会话中的Attributes是否一样
......
......@@ -44,4 +44,7 @@ public class ImConversationCreate extends BaseEntity {
@ApiModelProperty("客户端平台: 1 web, 2 安卓, 3 ios, 4 pc-win, 5 pc-macOs, 需与生成sign时的值一致")
private Integer platform;
@ApiModelProperty("是否加密聊天: 1-是 0-否")
private Integer isEncrypt;
}
......@@ -168,6 +168,12 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
String name = imConversationCreate.getName();
Map<String, Object> attributes = imConversationCreate.getAttributes();
List<String> memberClientIds = imConversationCreate.getClientIds();
if (imConversationCreate.getIsEncrypt() != null && imConversationCreate.getIsEncrypt() == 1) {
ImConversation conversation = this.createEncryptedChat(createClient, memberClientIds.get(0), name,
attributes);
ImConversationCreateVo imConversationCreateVo = new ImConversationCreateVo();
imConversationCreateVo.setId(conversation.getId());
}
if (ChatTypeEnum.CHAT_ROOM.getCode().equals(chatType)) {
// 聊天室
return this.createChatRoom(imConversationCreate, createClient);
......@@ -1241,6 +1247,45 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
}
/**
* 创建加密会话
*
*/
private ImConversation createEncryptedChat(ImClient creator, String memberUserId, String name, Map<String, Object> attributes) {
Long appId = creator.getFkAppid();
ImClient memberClient = imClientService.getOne(Wrappers.<ImClient>lambdaQuery().eq(ImClient::getClientId,
memberUserId).eq(ImClient::getFkAppid, appId));
if (memberClient == null) {
log.info("成员不存在,不能创建加密会话 clientId:{}", memberUserId);
throw new BusinessException(ApiCode.CLIENT_NOT_FOUNT);
}
// 如果存在重复单聊类型会话,则不会为空
ImConversation existConversation = imConversationMapper.getRepetitionConversationSingle(creator.getId(), memberClient.getId(), 1);
if (existConversation != null) {
// 双方可见
List<ImConversationMembers> memberList =
imConversationMembersService.list(Wrappers.<ImConversationMembers>lambdaQuery().eq(ImConversationMembers::getFkConversationId, existConversation.getId()));
for (ImConversationMembers members : memberList) {
members.setDisplayStatus(1L);
}
imConversationMembersService.updateBatchById(memberList);
log.info("存在重复的单聊会话,返回已存在的单聊类型会话id: {}", existConversation.getId());
// 返回已存在的单聊类型会话id
return existConversation;
}
// 创建会话
ImConversation conversation = buildConversation(creator, ChatTypeEnum.SINGLE, name, 2, attributes);
conversation.setIsEncrypt(1);
// 创建成员
List<ImConversationMembers> conversationMemberList = buildPrivateChatMembers(conversation, creator,
memberClient);
this.save(conversation);
this.imConversationMembersService.saveBatch(conversationMemberList);
return conversation;
}
/**
* 创建私聊会话
* @Author luozh
* @Date 2022年05月20日 01:36:33
......@@ -1264,7 +1309,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
}
// 如果存在重复单聊类型会话,则不会为空
ImConversation existConversation = imConversationMapper.getRepetitionConversationSingle(creator.getId(), memberClient.getId());
ImConversation existConversation = imConversationMapper.getRepetitionConversationSingle(creator.getId(), memberClient.getId(), 0);
if (existConversation != null) {
// 双方可见
List<ImConversationMembers> memberList =
......@@ -1313,7 +1358,7 @@ public class ImConversationServiceImpl extends BaseServiceImpl<ImConversationMap
}
// 如果存在重复单聊类型会话,则不会为空
ImConversation existConversation = imConversationMapper.getRepetitionConversationSingle(creator.getId(), memberClient.getId());
ImConversation existConversation = imConversationMapper.getRepetitionConversationSingle(creator.getId(), memberClient.getId(), 0);
if (existConversation != null) {
// 双方可见
List<ImConversationMembers> memberList =
......
......@@ -16,6 +16,7 @@ import com.wecloud.utils.SnowflakeUtil;
import io.geekidea.springbootplus.framework.common.service.impl.BaseServiceImpl;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;
import java.util.Date;
......@@ -34,6 +35,7 @@ public class ImRtcRecordServiceImpl extends BaseServiceImpl<ImRtcRecordMapper, I
private ImClientService imClientService;
@Async
@Override
public void createRtcRecord(CreateRtcChannelParam param, Long channelId) {
try {
......@@ -59,6 +61,7 @@ public class ImRtcRecordServiceImpl extends BaseServiceImpl<ImRtcRecordMapper, I
* @param channelId
* @param type 1-同意进入频道 2-拒接进入频道 3-主动挂断(离开频道)
*/
@Async
@Override
public void updateRtcRecord(Long channelId, Integer type) {
try {
......
......@@ -89,6 +89,7 @@
on con.id = mem2.fk_conversation_id and mem2.fk_client_id = #{clientId2}
where con.chat_type in (1, 5, 6)
and con.member_count = 2
and con.is_encrypt = #{isEncrypt}
order by con.id asc
LIMIT 1
</select>
......
-- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本
-- 在feature-cluster 2021年12月22日之后,需要执行的的sql增量脚本
......@@ -185,4 +185,7 @@ CREATE TABLE `im_rtc_record`
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COMMENT='单人音视频聊天记录表';
ALTER TABLE im_conversation
ADD COLUMN `is_encrypt` tinyint(1) unsigned DEFAULT '0' COMMENT '是否加密聊天: 1-是 0-否';
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment