Commit f6a29e530ab91dbdda512e57b22906790c060689
1 parent
1269e626
📝 refactor(im): 移除后端的 conversation
Showing
9 changed files
with
0 additions
and
435 deletions
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/ImConversationController.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.conversation; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.pojo.CommonResult; | ||
| 4 | -import cn.iocoder.yudao.framework.common.util.object.BeanUtils; | ||
| 5 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationCreateReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdateLastReadTimeReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationRespVO; | ||
| 8 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdatePinnedReqVO; | ||
| 9 | -import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO; | ||
| 10 | -import cn.iocoder.yudao.module.im.service.conversation.ImConversationService; | ||
| 11 | -import io.swagger.v3.oas.annotations.Operation; | ||
| 12 | -import io.swagger.v3.oas.annotations.tags.Tag; | ||
| 13 | -import jakarta.annotation.Resource; | ||
| 14 | -import jakarta.validation.Valid; | ||
| 15 | -import org.springframework.validation.annotation.Validated; | ||
| 16 | -import org.springframework.web.bind.annotation.*; | ||
| 17 | - | ||
| 18 | -import java.util.List; | ||
| 19 | - | ||
| 20 | -import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success; | ||
| 21 | -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||
| 22 | - | ||
| 23 | -@Tag(name = "管理后台 - IM 会话") | ||
| 24 | -@RestController | ||
| 25 | -@RequestMapping("/im/conversation") | ||
| 26 | -@Validated | ||
| 27 | -public class ImConversationController { | ||
| 28 | - | ||
| 29 | - @Resource | ||
| 30 | - private ImConversationService imConversationService; | ||
| 31 | - | ||
| 32 | - // TODO @芋艿:头像和昵称的聚合应交给前端完成 | ||
| 33 | - @GetMapping("/list") | ||
| 34 | - @Operation(summary = "获得用户的会话列表") | ||
| 35 | - public CommonResult<List<ImConversationRespVO>> getConversationList() { | ||
| 36 | - List<ImConversationDO> conversationList = imConversationService.getConversationList(getLoginUserId()); | ||
| 37 | - List<ImConversationRespVO> imConversationRespVOList = BeanUtils.toBean(conversationList, ImConversationRespVO.class); | ||
| 38 | - return success(imConversationRespVOList); | ||
| 39 | - } | ||
| 40 | - | ||
| 41 | - @PostMapping("/update-pinned") | ||
| 42 | - @Operation(summary = "置顶会话") | ||
| 43 | - public CommonResult<Boolean> updatePinned(@Valid @RequestBody ImConversationUpdatePinnedReqVO updateReqVO) { | ||
| 44 | - imConversationService.updatePinned(getLoginUserId(),updateReqVO); | ||
| 45 | - return success(true); | ||
| 46 | - } | ||
| 47 | - | ||
| 48 | - @PostMapping("/update-last-read-time") | ||
| 49 | - @Operation(summary = "更新最后已读时间") | ||
| 50 | - public CommonResult<Boolean> updateLastReadTime(@Valid @RequestBody ImConversationUpdateLastReadTimeReqVO updateReqVO) { | ||
| 51 | - imConversationService.updateLastReadTime(getLoginUserId(),updateReqVO); | ||
| 52 | - return success(true); | ||
| 53 | - } | ||
| 54 | - | ||
| 55 | - @PostMapping("/create") | ||
| 56 | - @Operation(summary = "创建会话") | ||
| 57 | - public CommonResult<ImConversationDO> createConversation(@Valid @RequestBody ImConversationCreateReqVO createReqVO) { | ||
| 58 | - ImConversationDO conversation = imConversationService.createConversation(getLoginUserId(), createReqVO); | ||
| 59 | - return success(conversation); | ||
| 60 | - } | ||
| 61 | - | ||
| 62 | -} | ||
| 63 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/vo/ImConversationCreateReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.conversation.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 4 | -import cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum; | ||
| 5 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 6 | -import jakarta.validation.constraints.NotNull; | ||
| 7 | -import lombok.Data; | ||
| 8 | - | ||
| 9 | -import java.time.LocalDateTime; | ||
| 10 | - | ||
| 11 | -@Schema(description = "管理后台 - 会话最后已读时间 Request VO") | ||
| 12 | -@Data | ||
| 13 | -public class ImConversationCreateReqVO { | ||
| 14 | - | ||
| 15 | - @Schema(description = "聊天对象编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 16 | - private Long targetId; | ||
| 17 | - | ||
| 18 | - @Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 19 | - @InEnum(value = ImConversationTypeEnum.class, message = "会话类型必须是 {value}") | ||
| 20 | - private Integer type; | ||
| 21 | - | ||
| 22 | -} | ||
| 23 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/vo/ImConversationRespVO.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.conversation.vo; | ||
| 2 | - | ||
| 3 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 4 | -import lombok.Data; | ||
| 5 | - | ||
| 6 | -import java.time.LocalDateTime; | ||
| 7 | - | ||
| 8 | -@Schema(description = "管理后台 - 会话 Response VO") | ||
| 9 | -@Data | ||
| 10 | -public class ImConversationRespVO { | ||
| 11 | - | ||
| 12 | - @Schema(description = "编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "13905") | ||
| 13 | - private Long id; | ||
| 14 | - | ||
| 15 | - @Schema(description = "所属用户", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 16 | - private Long userId; | ||
| 17 | - | ||
| 18 | - @Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 19 | - private Integer type; | ||
| 20 | - | ||
| 21 | - @Schema(description = "聊天对象编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 22 | - private Long targetId; | ||
| 23 | - | ||
| 24 | - @Schema(description = "会话标志", requiredMode = Schema.RequiredMode.REQUIRED, example = "s_1_2") | ||
| 25 | - private String no; | ||
| 26 | - | ||
| 27 | - @Schema(description = "是否置顶", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 28 | - private Boolean pinned; | ||
| 29 | - | ||
| 30 | - @Schema(description = "最后已读时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-03-01 00:00:00") | ||
| 31 | - private LocalDateTime lastReadTime; | ||
| 32 | - | ||
| 33 | - @Schema(description = "创建时间", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 34 | - private LocalDateTime createTime; | ||
| 35 | - | ||
| 36 | - // TODO @dylan:这块,交给前端聚合哈。im 这块,我们重前端,后端更多解决消息的通信和存储。 | ||
| 37 | - // 1. 基础信息:根据会话类型,查询会话接受者的头像、昵称 | ||
| 38 | - // 2. 未读信息:前端自己增量拉取,基于本地 db 查看 | ||
| 39 | - | ||
| 40 | - @Schema(description = "会话接受者头像", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 41 | - private String avatar; | ||
| 42 | - | ||
| 43 | - @Schema(description = "会话接受者昵称", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 44 | - private String nickname; | ||
| 45 | - | ||
| 46 | - @Schema(description = "最后一条消息的描述", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 47 | - private String lastMessageDescription; | ||
| 48 | - | ||
| 49 | - @Schema(description = "未读消息条数", requiredMode = Schema.RequiredMode.REQUIRED) | ||
| 50 | - private String unreadMessagesCount; | ||
| 51 | - | ||
| 52 | -} | ||
| 53 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/vo/ImConversationUpdateLastReadTimeReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.conversation.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 4 | -import cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum; | ||
| 5 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 6 | -import jakarta.validation.constraints.NotNull; | ||
| 7 | -import lombok.Data; | ||
| 8 | - | ||
| 9 | -import java.time.LocalDateTime; | ||
| 10 | - | ||
| 11 | -@Schema(description = "管理后台 - 会话最后已读时间 Request VO") | ||
| 12 | -@Data | ||
| 13 | -public class ImConversationUpdateLastReadTimeReqVO { | ||
| 14 | - | ||
| 15 | - @Schema(description = "最后已读时间", requiredMode = Schema.RequiredMode.REQUIRED, example = "2024-03-01 00:00:00") | ||
| 16 | - @NotNull(message = "最后已读时间不能为空") | ||
| 17 | - private LocalDateTime lastReadTime; | ||
| 18 | - | ||
| 19 | - @Schema(description = "聊天对象编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 20 | - private Long targetId; | ||
| 21 | - | ||
| 22 | - @Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 23 | - @InEnum(value = ImConversationTypeEnum.class, message = "会话类型必须是 {value}") | ||
| 24 | - private Integer type; | ||
| 25 | - | ||
| 26 | -} | ||
| 27 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/controller/admin/conversation/vo/ImConversationUpdatePinnedReqVO.java deleted
| 1 | -package cn.iocoder.yudao.module.im.controller.admin.conversation.vo; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.validation.InEnum; | ||
| 4 | -import cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum; | ||
| 5 | -import io.swagger.v3.oas.annotations.media.Schema; | ||
| 6 | -import jakarta.validation.constraints.NotNull; | ||
| 7 | -import lombok.Data; | ||
| 8 | - | ||
| 9 | -@Schema(description = "管理后台 - 会话置顶 Request VO") | ||
| 10 | -@Data | ||
| 11 | -public class ImConversationUpdatePinnedReqVO { | ||
| 12 | - | ||
| 13 | - @Schema(description = "是否置顶", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 14 | - @NotNull(message = "是否置顶不能为空") | ||
| 15 | - private Boolean pinned; | ||
| 16 | - | ||
| 17 | - @Schema(description = "聊天对象编号", requiredMode = Schema.RequiredMode.REQUIRED, example = "2") | ||
| 18 | - private Long targetId; | ||
| 19 | - | ||
| 20 | - @Schema(description = "会话类型", requiredMode = Schema.RequiredMode.REQUIRED, example = "1") | ||
| 21 | - @InEnum(value = ImConversationTypeEnum.class, message = "会话类型必须是 {value}") | ||
| 22 | - private Integer type; | ||
| 23 | - | ||
| 24 | -} | ||
| 25 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/dal/dataobject/conversation/ImConversationDO.java deleted
| 1 | -package cn.iocoder.yudao.module.im.dal.dataobject.conversation; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.dataobject.BaseDO; | ||
| 4 | -import cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum; | ||
| 5 | -import com.baomidou.mybatisplus.annotation.KeySequence; | ||
| 6 | -import com.baomidou.mybatisplus.annotation.TableId; | ||
| 7 | -import com.baomidou.mybatisplus.annotation.TableName; | ||
| 8 | -import lombok.*; | ||
| 9 | - | ||
| 10 | -import java.time.LocalDateTime; | ||
| 11 | - | ||
| 12 | -/** | ||
| 13 | - * IM 会话 DO | ||
| 14 | - * | ||
| 15 | - * @author 芋道源码 | ||
| 16 | - */ | ||
| 17 | -@TableName("im_conversation") | ||
| 18 | -@KeySequence("im_conversation_seq") // 用于 Oracle、PostgreSQL、Kingbase、DB2、H2 数据库的主键自增。如果是 MySQL 等数据库,可不写。 | ||
| 19 | -@Data | ||
| 20 | -@EqualsAndHashCode(callSuper = true) | ||
| 21 | -@ToString(callSuper = true) | ||
| 22 | -@Builder | ||
| 23 | -@NoArgsConstructor | ||
| 24 | -@AllArgsConstructor | ||
| 25 | -public class ImConversationDO extends BaseDO { | ||
| 26 | - | ||
| 27 | - /** | ||
| 28 | - * 编号 | ||
| 29 | - */ | ||
| 30 | - @TableId | ||
| 31 | - private Long id; | ||
| 32 | - | ||
| 33 | - /** | ||
| 34 | - * 所属用户 | ||
| 35 | - */ | ||
| 36 | - private Long userId; | ||
| 37 | - | ||
| 38 | - /** | ||
| 39 | - * 会话类型 | ||
| 40 | - * <p> | ||
| 41 | - * 枚举 {@link ImConversationTypeEnum} | ||
| 42 | - */ | ||
| 43 | - private Integer type; | ||
| 44 | - /** | ||
| 45 | - * 聊天对象编号 | ||
| 46 | - * <p> | ||
| 47 | - * 1. 单聊时,用户编号; | ||
| 48 | - * 2. 群聊时,群编号 | ||
| 49 | - */ | ||
| 50 | - private Long targetId; | ||
| 51 | - /** | ||
| 52 | - * 会话标志 | ||
| 53 | - * | ||
| 54 | - * 1. 单聊:s_{userId}_{targetId},需要排序 userId 和 targetId | ||
| 55 | - * 2. 群聊:g_groupId | ||
| 56 | - */ | ||
| 57 | - private String no; | ||
| 58 | - /** | ||
| 59 | - * 是否置顶 | ||
| 60 | - */ | ||
| 61 | - private Boolean pinned; | ||
| 62 | - /** | ||
| 63 | - * 最后已读时间 | ||
| 64 | - */ | ||
| 65 | - private LocalDateTime lastReadTime; | ||
| 66 | - | ||
| 67 | -} | ||
| 68 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/dal/mysql/conversation/ImConversationMapper.java deleted
| 1 | -package cn.iocoder.yudao.module.im.dal.mysql.conversation; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX; | ||
| 4 | -import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO; | ||
| 5 | -import org.apache.ibatis.annotations.Mapper; | ||
| 6 | - | ||
| 7 | -/** | ||
| 8 | - * IM 会话 Mapper | ||
| 9 | - * | ||
| 10 | - * @author 芋道源码 | ||
| 11 | - */ | ||
| 12 | -@Mapper | ||
| 13 | -public interface ImConversationMapper extends BaseMapperX<ImConversationDO> { | ||
| 14 | - | ||
| 15 | - default ImConversationDO selectByNo(String no){ | ||
| 16 | - return selectOne(ImConversationDO::getNo, no); | ||
| 17 | - } | ||
| 18 | -} | ||
| 19 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/conversation/ImConversationService.java deleted
| 1 | -package cn.iocoder.yudao.module.im.service.conversation; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationCreateReqVO; | ||
| 4 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdateLastReadTimeReqVO; | ||
| 5 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdatePinnedReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO; | ||
| 7 | - | ||
| 8 | -import java.util.List; | ||
| 9 | - | ||
| 10 | -/** | ||
| 11 | - * IM 会话 Service 接口 | ||
| 12 | - * | ||
| 13 | - * @author 芋道源码 | ||
| 14 | - */ | ||
| 15 | -public interface ImConversationService { | ||
| 16 | - | ||
| 17 | - /** | ||
| 18 | - * 获得用户的会话列表 | ||
| 19 | - * | ||
| 20 | - * @return 会话列表 | ||
| 21 | - */ | ||
| 22 | - List<ImConversationDO> getConversationList(Long loginUserId); | ||
| 23 | - | ||
| 24 | - /** | ||
| 25 | - * 置顶会话 | ||
| 26 | - * | ||
| 27 | - * @param loginUserId 登录用户编号 | ||
| 28 | - * @param updateReqVO 更新信息 | ||
| 29 | - */ | ||
| 30 | - void updatePinned(Long loginUserId, ImConversationUpdatePinnedReqVO updateReqVO); | ||
| 31 | - | ||
| 32 | - /** | ||
| 33 | - * 更新最后已读时间 | ||
| 34 | - * | ||
| 35 | - * @param loginUserId 登录用户编号 | ||
| 36 | - * @param updateReqVO 更新信息 | ||
| 37 | - */ | ||
| 38 | - void updateLastReadTime(Long loginUserId, ImConversationUpdateLastReadTimeReqVO updateReqVO); | ||
| 39 | - | ||
| 40 | - ImConversationDO createConversation(Long loginUserId, ImConversationCreateReqVO createReqVO); | ||
| 41 | - | ||
| 42 | -} | ||
| 43 | \ No newline at end of file | 0 | \ No newline at end of file |
yudao-module-im/yudao-module-im-biz/src/main/java/cn/iocoder/yudao/module/im/service/conversation/ImConversationServiceImpl.java deleted
| 1 | -package cn.iocoder.yudao.module.im.service.conversation; | ||
| 2 | - | ||
| 3 | -import cn.iocoder.yudao.framework.common.enums.UserTypeEnum; | ||
| 4 | -import cn.iocoder.yudao.framework.websocket.core.sender.WebSocketMessageSender; | ||
| 5 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationCreateReqVO; | ||
| 6 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdateLastReadTimeReqVO; | ||
| 7 | -import cn.iocoder.yudao.module.im.controller.admin.conversation.vo.ImConversationUpdatePinnedReqVO; | ||
| 8 | -import cn.iocoder.yudao.module.im.dal.dataobject.conversation.ImConversationDO; | ||
| 9 | -import cn.iocoder.yudao.module.im.dal.mysql.conversation.ImConversationMapper; | ||
| 10 | -import cn.iocoder.yudao.module.im.enums.conversation.ImConversationTypeEnum; | ||
| 11 | -import jakarta.annotation.Resource; | ||
| 12 | -import org.springframework.stereotype.Service; | ||
| 13 | -import org.springframework.validation.annotation.Validated; | ||
| 14 | - | ||
| 15 | -import java.util.List; | ||
| 16 | - | ||
| 17 | -import static cn.iocoder.yudao.framework.security.core.util.SecurityFrameworkUtils.getLoginUserId; | ||
| 18 | - | ||
| 19 | -/** | ||
| 20 | - * IM 会话 Service 实现类 | ||
| 21 | - * | ||
| 22 | - * @author 芋道源码 | ||
| 23 | - */ | ||
| 24 | -@Service | ||
| 25 | -@Validated | ||
| 26 | -public class ImConversationServiceImpl implements ImConversationService { | ||
| 27 | - | ||
| 28 | - private final String IM_CONVERSATION_ADD = "im-conversation-add"; | ||
| 29 | - | ||
| 30 | - @Resource | ||
| 31 | - private ImConversationMapper imConversationMapper; | ||
| 32 | - | ||
| 33 | - @Resource | ||
| 34 | - WebSocketMessageSender webSocketMessageSender; | ||
| 35 | - | ||
| 36 | - @Override | ||
| 37 | - public List<ImConversationDO> getConversationList(Long loginUserId) { | ||
| 38 | - // 根据loginUserId判断targetId, 自己不能做targetId | ||
| 39 | - // 如果loginUserId和targetId相同,则需要调换userId和targetId | ||
| 40 | - List<ImConversationDO> conversationList = imConversationMapper.selectList(); | ||
| 41 | - | ||
| 42 | - // 过滤和自己无关的会话 | ||
| 43 | - List<ImConversationDO> conversationFilteredList = conversationList.stream().filter(item -> loginUserId.equals(item.getUserId()) || loginUserId.equals(item.getTargetId())).toList(); | ||
| 44 | - // 遍历判断loginUserId和targetId相同,相同则将userId设置为targetId, targetId设置为userId | ||
| 45 | - conversationFilteredList.forEach(item -> { | ||
| 46 | - if (item.getTargetId().equals(loginUserId)) { | ||
| 47 | - Long targetId = item.getTargetId(); | ||
| 48 | - Long userId = item.getUserId(); | ||
| 49 | - item.setTargetId(userId); | ||
| 50 | - item.setUserId(targetId); | ||
| 51 | - } | ||
| 52 | - }); | ||
| 53 | - return conversationFilteredList; | ||
| 54 | - } | ||
| 55 | - | ||
| 56 | - @Override | ||
| 57 | - public void updatePinned(Long loginUserId, ImConversationUpdatePinnedReqVO updateReqVO) { | ||
| 58 | - // 1. 获得会话编号 | ||
| 59 | - String no = ImConversationTypeEnum.generateConversationNo(loginUserId, updateReqVO.getTargetId(), updateReqVO.getType()); | ||
| 60 | - // 2. 查询会话 | ||
| 61 | - ImConversationDO conversation = imConversationMapper.selectByNo(no); | ||
| 62 | - if (conversation == null) { | ||
| 63 | - // 2.1. 不存在,则插入 | ||
| 64 | - conversation = insertConversation(no, loginUserId, updateReqVO.getTargetId(), updateReqVO.getType()); | ||
| 65 | - } | ||
| 66 | - // 3. 更新会话 | ||
| 67 | - conversation.setPinned(updateReqVO.getPinned()); | ||
| 68 | - imConversationMapper.updateById(conversation); | ||
| 69 | - // 4. 做对应更新的 notify 推送 | ||
| 70 | - } | ||
| 71 | - | ||
| 72 | - private ImConversationDO insertConversation(String no, Long userId, Long targetId, Integer type) { | ||
| 73 | - ImConversationDO imConversationDO = new ImConversationDO(); | ||
| 74 | - imConversationDO.setNo(no); | ||
| 75 | - imConversationDO.setUserId(userId); | ||
| 76 | - imConversationDO.setTargetId(targetId); | ||
| 77 | - imConversationDO.setType(type); | ||
| 78 | - imConversationMapper.insert(imConversationDO); | ||
| 79 | - return imConversationDO; | ||
| 80 | - } | ||
| 81 | - | ||
| 82 | - @Override | ||
| 83 | - public void updateLastReadTime(Long loginUserId, ImConversationUpdateLastReadTimeReqVO updateReqVO) { | ||
| 84 | - // 1. 获得会话编号 | ||
| 85 | - String no = ImConversationTypeEnum.generateConversationNo(loginUserId, updateReqVO.getTargetId(), updateReqVO.getType()); | ||
| 86 | - // 2. 查询会话 | ||
| 87 | - ImConversationDO conversation = imConversationMapper.selectByNo(no); | ||
| 88 | - if (conversation == null) { | ||
| 89 | - // 2.1. 不存在,则插入 | ||
| 90 | - conversation = insertConversation(no, loginUserId, updateReqVO.getTargetId(), updateReqVO.getType()); | ||
| 91 | - } | ||
| 92 | - // 3. 更新会话 | ||
| 93 | - conversation.setLastReadTime(updateReqVO.getLastReadTime()); | ||
| 94 | - imConversationMapper.updateById(conversation); | ||
| 95 | - // 4. 做对应更新的 notify 推送 | ||
| 96 | - } | ||
| 97 | - | ||
| 98 | - @Override | ||
| 99 | - public ImConversationDO createConversation(Long loginUserId, ImConversationCreateReqVO createReqVO) { | ||
| 100 | - // 1. 获得会话编号 | ||
| 101 | - String no = ImConversationTypeEnum.generateConversationNo(loginUserId, createReqVO.getTargetId(), createReqVO.getType()); | ||
| 102 | - // 2. 查询会话 | ||
| 103 | - ImConversationDO conversation = imConversationMapper.selectByNo(no); | ||
| 104 | - | ||
| 105 | - if (conversation == null) { | ||
| 106 | - // 2.1. 不存在,则插入 | ||
| 107 | - conversation = insertConversation(no, loginUserId, createReqVO.getTargetId(), createReqVO.getType()); | ||
| 108 | - } | ||
| 109 | - | ||
| 110 | - // 发送打开会话的通知,并推送会话实体 | ||
| 111 | - // 给自己发送创建会话成功的通知, 方便多端登录的时候保持会话同时更新 | ||
| 112 | - webSocketMessageSender.sendObject(UserTypeEnum.ADMIN.getValue(), getLoginUserId(), | ||
| 113 | - IM_CONVERSATION_ADD, conversation); | ||
| 114 | - | ||
| 115 | - // 给接受者发送创建会话的通知 | ||
| 116 | - // TODO:[dylan] 接受者,在接收到消息的时候本地发现没有回话,就按照会话编号创建一个,因此可以不需要发送这个通知 | ||
| 117 | - webSocketMessageSender.sendObject(UserTypeEnum.ADMIN.getValue(), createReqVO.getTargetId(), | ||
| 118 | - IM_CONVERSATION_ADD, conversation); | ||
| 119 | - return conversation; | ||
| 120 | - } | ||
| 121 | - | ||
| 122 | -} | ||
| 123 | \ No newline at end of file | 0 | \ No newline at end of file |