Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.dfbf.soundlink.domain.alert.dto.AlertChatRequest;
import org.dfbf.soundlink.domain.alert.entity.Alert;
import org.dfbf.soundlink.domain.alert.service.AlertService;
import org.dfbf.soundlink.domain.blocklist.repository.BlockListRepository;
import org.dfbf.soundlink.domain.chat.dto.ChatRejectDto;
Expand Down Expand Up @@ -31,7 +30,6 @@
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.sql.Timestamp;
import java.time.Duration;
Expand Down Expand Up @@ -218,11 +216,11 @@ public ResponseResult createChatRoom(Long userId, Long recordId, String requestN
if (chatRoomId.isPresent()) {
Map<String, Object> map = new HashMap<>();
map.put("chatRoomId", chatRoomId.get());

// Alert alert = alertService.createAlert(requestUserId, "accept", map);
// kafkaProducer.send(TOPIC, alert);
alertService.send(requestUserId, "accept", map);

return new ResponseResult(map);
}

Expand All @@ -241,6 +239,10 @@ public ResponseResult createChatRoom(Long userId, Long recordId, String requestN

ChatReqDto chatReqDto = new ChatReqDto(userId, responseUserId);

// 채팅 오픈 상태 보내기
log.info("Setting chatting status to true for userId: {}", userId);
userStatusService.setChatting(userId, true);

// 레디스에 저장
redisTemplate.opsForValue().set("Room::" + chatRoom.getChatRoomId(), String.valueOf(chatReqDto));

Expand All @@ -253,9 +255,6 @@ public ResponseResult createChatRoom(Long userId, Long recordId, String requestN
// kafkaProducer.send(TOPIC, alert);
alertService.send(requestUserId, "accept", map);

// 채팅 오픈 상태 보내기
userStatusService.setChatting(userId, true);

return new ResponseResult(ErrorCode.SUCCESS, map);

} else {
Expand All @@ -282,12 +281,12 @@ public ResponseResult closeChatRoom(@AuthenticationPrincipal Long userId, Long c
throw new UnauthorizedAccessException(); // 권한이 없을 경우 예외 발생
}

// 채팅 완료 상태 보내기
userStatusService.setChatting(userId, false);

chatRoom.updateChatRoomStatus(RoomStatus.CLOSED); // 삳태 '닫기'로 변경
chatRoomRepository.save(chatRoom); // DB에 저장

// 채팅 종료 상태 보내기
log.info("Setting chatting status to false for userId: {}", userId);
userStatusService.setChatting(userId, false);

redisTemplate.delete("Room::"+chatRoomId); // 레디스에서 삭제

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public void saveUserStatus(UserStatusDto status) {
try {
String json = objectMapper.writeValueAsString(status);
redisTemplate.opsForValue().set(key, json);
log.info("User status updated: {}", status);

} catch (JsonProcessingException e) {
log.error("유저 상태 저장 중 JsonProcessingException 오류: {}", e.getMessage());
Expand Down Expand Up @@ -56,7 +57,6 @@ public void setOnline(Long userId) {
public void setOffline(Long userId) {
UserStatusDto current = getUserStatus(userId);
current.setOnline(false);
current.setChatting(false); // 로그아웃하면 당연히 채팅도 종료
current.setLastActive(System.currentTimeMillis());
saveUserStatus(current);
}
Expand Down