- 创建信息记录文档,包含项目管理要求、产物范围、Git仓库、制品仓库信息 - 添加服务器部署信息,包括应用服务器、MySQL/Redis服务器、Jenkins服务配置 - 记录邮件服务、DNS/HTTPS证书配置及安全备注 - 创建API联调文档,包含线上入口、ID约定、初始化管理员账号信息 - 添加统一响应格式、常见错误码、鉴权规则说明 - 提供核心接口清单,涵盖tenant-service、im-service、push-service等服务 - 补充curl示例,包含运营平台登录、IM登录、会话管理等操作示例 - 实现会话控制器,支持置顶、免打扰、标记已读、草稿等功能 - 添加全局异常处理器,统一处理业务异常和参数校验错误 - 创建IM管理控制器,提供用户管理、好友请求、黑名单等管理功能
129 行
5.0 KiB
Java
129 行
5.0 KiB
Java
package com.xuqm.im.service;
|
|
|
|
import com.xuqm.im.entity.ImConversationStateEntity;
|
|
import com.xuqm.im.repository.ImConversationStateRepository;
|
|
import org.springframework.stereotype.Service;
|
|
import org.springframework.transaction.annotation.Transactional;
|
|
|
|
import java.time.LocalDateTime;
|
|
import java.util.Collection;
|
|
import java.util.List;
|
|
import java.util.UUID;
|
|
|
|
@Service
|
|
public class ConversationStateService {
|
|
|
|
private final ImConversationStateRepository repository;
|
|
|
|
public ConversationStateService(ImConversationStateRepository repository) {
|
|
this.repository = repository;
|
|
}
|
|
|
|
@Transactional
|
|
public ImConversationStateEntity setPinned(String appId, String userId, String targetId, String chatType, boolean pinned) {
|
|
ImConversationStateEntity state = getOrCreate(appId, userId, targetId, chatType);
|
|
state.setPinned(pinned);
|
|
touch(state);
|
|
return repository.save(state);
|
|
}
|
|
|
|
@Transactional
|
|
public ImConversationStateEntity setMuted(String appId, String userId, String targetId, String chatType, boolean muted) {
|
|
ImConversationStateEntity state = getOrCreate(appId, userId, targetId, chatType);
|
|
state.setMuted(muted);
|
|
touch(state);
|
|
return repository.save(state);
|
|
}
|
|
|
|
@Transactional
|
|
public ImConversationStateEntity markRead(String appId, String userId, String targetId, String chatType) {
|
|
ImConversationStateEntity state = getOrCreate(appId, userId, targetId, chatType);
|
|
state.setLastReadAt(LocalDateTime.now());
|
|
state.setHidden(false);
|
|
touch(state);
|
|
return repository.save(state);
|
|
}
|
|
|
|
@Transactional
|
|
public ImConversationStateEntity setDraft(String appId, String userId, String targetId, String chatType, String draft) {
|
|
ImConversationStateEntity state = getOrCreate(appId, userId, targetId, chatType);
|
|
state.setDraft(draft);
|
|
touch(state);
|
|
return repository.save(state);
|
|
}
|
|
|
|
@Transactional
|
|
public ImConversationStateEntity hideConversation(String appId, String userId, String targetId, String chatType) {
|
|
ImConversationStateEntity state = getOrCreate(appId, userId, targetId, chatType);
|
|
state.setHidden(true);
|
|
state.setDraft(null);
|
|
touch(state);
|
|
return repository.save(state);
|
|
}
|
|
|
|
@Transactional
|
|
public void deleteConversationState(String appId, String userId, String targetId, String chatType) {
|
|
repository.deleteByAppIdAndUserIdAndTargetIdAndChatType(appId, userId, targetId, chatType);
|
|
}
|
|
|
|
@Transactional
|
|
public void deleteConversation(String appId,
|
|
String userId,
|
|
String targetId,
|
|
String chatType,
|
|
boolean syncAcrossClients) {
|
|
if (syncAcrossClients) {
|
|
deleteConversationState(appId, userId, targetId, chatType);
|
|
return;
|
|
}
|
|
hideConversation(appId, userId, targetId, chatType);
|
|
}
|
|
|
|
@Transactional
|
|
public void clearHiddenForUsers(String appId, String targetId, String chatType, Collection<String> userIds) {
|
|
for (String userId : userIds) {
|
|
ImConversationStateEntity state = repository
|
|
.findByAppIdAndUserIdAndTargetIdAndChatType(appId, userId, targetId, chatType)
|
|
.orElse(null);
|
|
if (state != null && state.isHidden()) {
|
|
state.setHidden(false);
|
|
touch(state);
|
|
repository.save(state);
|
|
}
|
|
}
|
|
}
|
|
|
|
public ImConversationStateEntity getOrCreate(String appId, String userId, String targetId, String chatType) {
|
|
return repository.findByAppIdAndUserIdAndTargetIdAndChatType(appId, userId, targetId, chatType)
|
|
.orElseGet(() -> {
|
|
ImConversationStateEntity entity = new ImConversationStateEntity();
|
|
entity.setId(UUID.randomUUID().toString());
|
|
entity.setAppId(appId);
|
|
entity.setUserId(userId);
|
|
entity.setTargetId(targetId);
|
|
entity.setChatType(chatType);
|
|
entity.setPinned(false);
|
|
entity.setMuted(false);
|
|
entity.setHidden(false);
|
|
entity.setDraft(null);
|
|
entity.setLastReadAt(null);
|
|
entity.setCreatedAt(LocalDateTime.now());
|
|
entity.setUpdatedAt(LocalDateTime.now());
|
|
return entity;
|
|
});
|
|
}
|
|
|
|
public ImConversationStateEntity find(String appId, String userId, String targetId, String chatType) {
|
|
return repository.findByAppIdAndUserIdAndTargetIdAndChatType(appId, userId, targetId, chatType)
|
|
.orElse(null);
|
|
}
|
|
|
|
public List<ImConversationStateEntity> listVisible(String appId, String userId) {
|
|
return repository.findByAppIdAndUserIdAndHiddenFalse(appId, userId);
|
|
}
|
|
|
|
private void touch(ImConversationStateEntity entity) {
|
|
entity.setUpdatedAt(LocalDateTime.now());
|
|
}
|
|
}
|