Skip to content

Commit

Permalink
refactor(Refactored otp user to provide display name):
Browse files Browse the repository at this point in the history
  • Loading branch information
br648 committed Dec 13, 2024
1 parent 2638f04 commit 17363ac
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -213,9 +213,9 @@ public Optional<TripSurveyNotification> findLastTripSurveyNotificationSent() {
}

/**
* Use name if available, if not fallback on their email (which is a required field).
* Use name if available, if not fallback on email (which is a required field).
*/
public String getAddressee() {
return Strings.isBlank(name) ? email : name;
public String getDisplayedName() {
return Strings.isBlank(name) ? email.replace("@", " at ") : name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ public class TripMonitorNotification extends Model {
private static final Logger LOG = LoggerFactory.getLogger(TripMonitorNotification.class);
public static final String STOPWATCH_ICON = "⏱";

public final NotificationType type;
public final String body;
public NotificationType type;
public String body;

/** Getter functions are used by HTML template renderer */
public String getBody() {
Expand All @@ -29,6 +29,12 @@ public NotificationType getType() {
return type;
}

/**
* This no-arg constructor exists to make MongoDB happy.
*/
public TripMonitorNotification() {
}

public TripMonitorNotification(NotificationType type, String body) {
this.type = type;
this.body = body;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ private static boolean sendAcceptDependentEmail(OtpUser dependentUser, OtpUser r
"acceptDependentLinkLabelAndUrl", label(acceptDependentLinkLabel, acceptDependentUrl, locale),
"acceptDependentUrl", acceptDependentUrl,
"emailFooter", Message.ACCEPT_DEPENDENT_EMAIL_FOOTER.get(locale),
"emailGreeting", String.format(Message.ACCEPT_DEPENDENT_EMAIL_GREETING.get(locale), dependentUser.getAddressee()),
"emailGreeting", String.format(Message.ACCEPT_DEPENDENT_EMAIL_GREETING.get(locale), dependentUser.getDisplayedName()),
"manageLinkUrl", String.format("%s%s", OTP_UI_URL, SETTINGS_PATH),
"manageLinkText", Message.ACCEPT_DEPENDENT_EMAIL_MANAGE.get(locale)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ public void processLegTransition(NotificationType notificationType, TravelerPosi
if (observer != null) {
enqueueNotification(
new LegTransitionNotification(
tripOwner.getAddressee(),
tripOwner.getDisplayedName(),
notificationType,
travelerPosition,
I18nUtils.getOtpUserLocale(observer)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -498,8 +498,7 @@ public static String replaceUserNameInFromEmail(String fromEmail, OtpUser otpUse
int lastBracketIndex = fromEmail.indexOf('>');
// HACK: If falling back on email, replace the "@" sign so that the user's email does not override the
// application email in brackets.
String displayedName = Strings.isBlank(otpUser.name) ? otpUser.email.replace("@", " at ") : otpUser.name;
return String.format("%s %s", displayedName, fromEmail.substring(firstBracketIndex, lastBracketIndex + 1));
return String.format("%s %s", otpUser.getDisplayedName(), fromEmail.substring(firstBracketIndex, lastBracketIndex + 1));
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -807,4 +807,4 @@ private static Stream<Arguments> createCanUnsnoozeTripCases() {
Arguments.of(noonMonday8June2020, tuesday, true)
);
}
}
}

0 comments on commit 17363ac

Please sign in to comment.