Skip to content

Commit

Permalink
feat: 채팅 알림에 모임 정보(사진 URL, 모임 이름) 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
takoyakimchi committed Oct 23, 2024
1 parent 67f76c0 commit ed0605b
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import com.happy.friendogly.chat.dto.response.ChatMessageSocketResponse;
import com.happy.friendogly.chat.repository.ChatMessageRepository;
import com.happy.friendogly.chat.repository.ChatRoomRepository;
import com.happy.friendogly.club.domain.Club;
import com.happy.friendogly.club.repository.ClubRepository;
import com.happy.friendogly.exception.FriendoglyException;
import com.happy.friendogly.member.domain.Member;
import com.happy.friendogly.member.repository.MemberRepository;
Expand All @@ -28,19 +30,22 @@ public class ChatCommandService {
private static final String EMPTY_CONTENT = "";

private final MemberRepository memberRepository;
private final ClubRepository clubRepository;
private final ChatRoomRepository chatRoomRepository;
private final ChatMessageRepository chatMessageRepository;
private final NotificationService notificationService;
private final SimpMessagingTemplate template;

public ChatCommandService(
MemberRepository memberRepository,
ClubRepository clubRepository,
ChatRoomRepository chatRoomRepository,
ChatMessageRepository chatMessageRepository,
NotificationService notificationService,
SimpMessagingTemplate template
) {
this.memberRepository = memberRepository;
this.clubRepository = clubRepository;
this.chatRoomRepository = chatRoomRepository;
this.chatMessageRepository = chatMessageRepository;
this.notificationService = notificationService;
Expand Down Expand Up @@ -71,8 +76,11 @@ public void sendLeave(Long senderMemberId, Long chatRoomId) {
}

private void sendAndSave(MessageType messageType, String content, ChatRoom chatRoom, Member senderMember) {
ChatMessageSocketResponse chat = new ChatMessageSocketResponse(messageType, content, senderMember, LocalDateTime.now());
notificationService.sendChatNotification(chatRoom.getId(), chat);
ChatMessageSocketResponse chat = new ChatMessageSocketResponse(
messageType, content, senderMember, LocalDateTime.now());
Club club = clubRepository.getByChatRoomId(chatRoom.getId());

notificationService.sendChatNotification(chatRoom.getId(), chat, club);
template.convertAndSend(TOPIC_CHAT_PREFIX + chatRoom.getId(), chat);
chatMessageRepository.save(new ChatMessage(chatRoom, messageType, senderMember, content));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.happy.friendogly.notification.service;

import com.happy.friendogly.chat.dto.response.ChatMessageSocketResponse;
import com.happy.friendogly.club.domain.Club;
import java.util.List;
import org.springframework.context.annotation.Profile;
import org.springframework.stereotype.Service;
Expand All @@ -20,7 +21,7 @@ public void sendFootprintNotification(String title, String content, List<String>
}

@Override
public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response) {
public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response, Club club) {

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.google.firebase.messaging.FirebaseMessagingException;
import com.google.firebase.messaging.MulticastMessage;
import com.happy.friendogly.chat.dto.response.ChatMessageSocketResponse;
import com.happy.friendogly.club.domain.Club;
import com.happy.friendogly.exception.FriendoglyException;
import com.happy.friendogly.notification.domain.NotificationType;
import com.happy.friendogly.notification.repository.DeviceTokenRepository;
Expand Down Expand Up @@ -55,7 +56,7 @@ public void sendFootprintNotification(String title, String content, List<String>
}

@Override
public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response) {
public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response, Club club) {
List<String> receiverTokens = deviceTokenRepository
.findAllByChatRoomIdWithoutMine(chatRoomId, response.senderMemberId());

Expand All @@ -66,7 +67,9 @@ public void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse resp
"senderName", response.senderName(),
"content", response.content(),
"createdAt", response.createdAt().toString(),
"profilePictureUrl", response.profilePictureUrl()
"profilePictureUrl", response.profilePictureUrl(),
"clubPictureUrl", club.getImageUrl(),
"clubTitle", club.getTitle().getValue()
);

sendNotificationWithType(CHAT, "채팅", data, receiverTokens);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.happy.friendogly.notification.service;

import com.happy.friendogly.chat.dto.response.ChatMessageSocketResponse;
import com.happy.friendogly.club.domain.Club;
import java.util.List;

public interface NotificationService {
Expand All @@ -9,7 +10,7 @@ public interface NotificationService {

void sendFootprintNotification(String title, String content, List<String> receiverTokens);

void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response);
void sendChatNotification(Long chatRoomId, ChatMessageSocketResponse response, Club club);

void sendPlaygroundJoinNotification(String title, String content, List<String> receiverTokens);
}

0 comments on commit ed0605b

Please sign in to comment.