Last active
September 1, 2024 21:21
-
-
Save teivah/8b5466ef29c6984881852ff4dca44699 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if ((((notification.orderID == orderID) | |
|| (notification.customerID == customerID) | |
|| (eventIDs.contains(notification.eventID)) && (notification.type.toAllStaff || notification.type.toAllOrders)) | |
|| (isAdmin && eventIDs.contains(notification.eventID)) | |
&& (userID != notification.senderID || notification.senderID == null))) { | |
send(notification); | |
} | |
// | |
boolean orderMatches = notification.orderID == orderID; | |
boolean customerMatches = notification.customerID == customerID; | |
boolean eventMatches = eventIDs.contains(notification.eventID); | |
boolean addressedToAll = notification.type.toAllStaff || notification.type.toAllOrders; | |
boolean shouldSendByEvent = eventMatches && (addressedToAll || isAdmin); | |
boolean senderIsNotReceiver = userID != notification.senderID || notification.senderID == null; | |
boolean notificationMatchesUser = senderIsNotReceiver && (orderMatches || customerMatches || shouldSendByEvent); | |
if (notificationMatchesUser) { | |
send(notification); | |
} | |
// | |
if (notificationMatchesUser(notification, isAdmin, orderID, customerID, eventIDs, userID)) { | |
send(notification); | |
} | |
// ... | |
boolean notificationMatchesUser(Notification notification, String orderID, String customerID, List<String> eventIDs, boolean isAdmin, String userID) { | |
boolean orderMatches = notification.orderID == orderID; | |
boolean customerMatches = notification.customerID == customerID; | |
boolean eventMatches = eventIDs.contains(notification.eventID); | |
boolean addressedToAll = notification.type.toAllStaff || notification.type.toAllOrders; | |
boolean shouldSendByEvent = eventMatches && (addressedToAll || isAdmin); | |
boolean senderIsNotReceiver = userID != notification.senderID || notification.senderID == null; | |
return senderIsNotReceiver && (orderMatches || customerMatches || shouldSendByEvent); | |
} | |
// | |
if (notificationMatchesUser(notification, context)) { | |
send(notification); | |
} | |
// ... | |
public class NotificationContext { | |
private String orderID; | |
private String customerID; | |
private List<String> eventIDs; | |
private String userID; | |
private boolean isAdmin; | |
// ... | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment