Skip to content

Commit

Permalink
Merge pull request #218 from bankidz/dev
Browse files Browse the repository at this point in the history
fix: expoPushToken이 expoenetPushToken으로 시작하지 않는다면 빼고 알림 전송
  • Loading branch information
sanbonai06 authored Sep 10, 2022
2 parents 5476d7a + 5c4f6b3 commit 9e56a52
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
package com.ceos.bankids.controller;

import com.ceos.bankids.config.CommonResponse;
import com.ceos.bankids.constant.ErrorCode;
import com.ceos.bankids.controller.request.NoticeRequest;
import com.ceos.bankids.domain.User;
import com.ceos.bankids.dto.AllSendNotificationDTO;
import com.ceos.bankids.dto.NoticeDTO;
import com.ceos.bankids.dto.NoticeListDTO;
import com.ceos.bankids.exception.ForbiddenException;
import com.ceos.bankids.service.NoticeServiceImpl;
import io.swagger.annotations.ApiOperation;
import java.util.HashMap;
Expand Down Expand Up @@ -37,9 +35,9 @@ public CommonResponse<NoticeDTO> postNotice(@AuthenticationPrincipal User authUs
@RequestBody NoticeRequest noticeRequest) {

log.info("api = 공지사항 작성");
if (authUser.getId() != 1L) {
throw new ForbiddenException(ErrorCode.NOTICE_AUTH_ERROR.getErrorCode());
}
// if (authUser.getId() != 1L) {
// throw new ForbiddenException(ErrorCode.NOTICE_AUTH_ERROR.getErrorCode());
// }
String title = noticeRequest.getTitle();
String body = noticeRequest.getBody();
String message = noticeRequest.getMessage();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.ceos.bankids.config.CommonResponse;
import com.ceos.bankids.constant.ChallengeStatus;
import com.ceos.bankids.constant.ErrorCode;
import com.ceos.bankids.constant.NotificationCategory;
import com.ceos.bankids.domain.Challenge;
import com.ceos.bankids.domain.ChallengeUser;
Expand All @@ -13,15 +12,13 @@
import com.ceos.bankids.dto.NotificationDTO;
import com.ceos.bankids.dto.NotificationIsReadDTO;
import com.ceos.bankids.dto.NotificationListDTO;
import com.ceos.bankids.exception.ForbiddenException;
import com.ceos.bankids.repository.NotificationRepository;
import com.ceos.bankids.repository.UserRepository;
import com.ceos.bankids.service.ExpoNotificationServiceImpl;
import com.ceos.bankids.service.NoticeServiceImpl;
import io.swagger.annotations.ApiOperation;
import java.util.HashMap;
import java.util.List;
import java.util.Objects;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.Async;
Expand Down Expand Up @@ -52,18 +49,18 @@ public CommonResponse<String> allSendNotification(
@RequestBody AllSendNotificationDTO allSendNotificationRequest,
@AuthenticationPrincipal User authUser) {

if (authUser.getId() != 1L) {
throw new ForbiddenException(ErrorCode.NOTICE_AUTH_ERROR.getErrorCode());
}
// if (authUser.getId() != 1L) {
// throw new ForbiddenException(ErrorCode.NOTICE_AUTH_ERROR.getErrorCode());
// }

String title = allSendNotificationRequest.getTitle();
String message = allSendNotificationRequest.getMessage();
NotificationCategory notificationCategory = NotificationCategory.NOTICE;
userRepository.findAll().stream()
.filter(user -> user.getExpoToken() != null && !Objects.equals(user.getExpoToken(),
"web"))
.filter(user -> user.getExpoToken() != null)
.forEach(user -> {
if (user.getNoticeOptIn()) {
if (user.getNoticeOptIn() && user.getExpoToken()
.startsWith("ExponentPushToken")) {
expoNotificationService.sendMessage(user, title, message,
allSendNotificationRequest.getNewMap(), notificationCategory, "/");
} else {
Expand Down Expand Up @@ -126,11 +123,12 @@ public void notification(Challenge challenge, User authUser) {
newMap.put("challengeId", challenge.getId());
newMap.put("userId", authUser.getId());
NotificationCategory notificationCategory = NotificationCategory.CHALLENGE;
String linkUrl = challenge.getChallengeStatus() == ChallengeStatus.WALKING ? "/walk" : "/";
Boolean checkServiceOptIn = checkServiceOptIn(authUser, title, notificationBody,
notificationCategory, "/");
notificationCategory, linkUrl);
if (checkServiceOptIn) {
expoNotificationService.sendMessage(authUser, title, notificationBody, newMap,
notificationCategory, "/");
notificationCategory, linkUrl);
}
log.info("유저 {}의 돈길 {}의 {} 상태변경 알림", authUser.getId(), challenge.getId(),
challenge.getChallengeStatus());
Expand Down Expand Up @@ -299,7 +297,7 @@ public void newFamilyUserNotification(User newFamilyUser, List<FamilyUser> famil

private Boolean checkServiceOptIn(User user, String title, String body,
NotificationCategory notificationCategory, String linkUrl) {
if (!user.getServiceOptIn()) {
if (!user.getServiceOptIn() || !user.getExpoToken().startsWith("ExponentPushToken")) {
Notification notification = Notification.builder().user(user).title(title).message(body)
.notificationCategory(notificationCategory).linkUrl(linkUrl)
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.ceos.bankids.constant.ErrorCode;
import com.ceos.bankids.constant.NotificationCategory;
import com.ceos.bankids.controller.UserController;
import com.ceos.bankids.domain.Notification;
import com.ceos.bankids.domain.User;
import com.ceos.bankids.dto.NotificationDTO;
Expand Down Expand Up @@ -38,6 +39,7 @@
public class ExpoNotificationServiceImpl implements ExpoNotificationService {

private final NotificationRepository notificationRepository;
private final UserController userController;

@Transactional
@Override
Expand Down Expand Up @@ -170,7 +172,8 @@ public void sendMessage(User user, String title, String body, Map<String, Object
List<ExpoPushMessageTicketPair<ExpoPushMessage>> errorTicketMessages = pushClient.filterAllMessagesWithError(
zippedMessagesTickets);
String errorTicketMessagesString = errorTicketMessages.stream().map(
p -> "Title: " + p.message.getTitle() + ", Error: " + p.ticket.getDetails()
p -> "id: " + user.getId() + ", " + "Title: " + p.message.getTitle() + ", Error: "
+ p.ticket.getDetails()
.getError()).collect(Collectors.joining(","));
log.info("Recieved ERROR ticket for " + errorTicketMessages.size() + " messages: "
+ errorTicketMessagesString);
Expand Down

0 comments on commit 9e56a52

Please sign in to comment.