diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java index 3aa14af37..720c3a6c5 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/controllers/ProfileController.java @@ -484,10 +484,7 @@ public class ProfileController { // reordering or making visible existing badges if (existingBadges.containsKey(badgeId)) { - AccountBadge accountBadge = existingBadges.get(badgeId); - if (!accountBadge.isVisible()) { - accountBadge = new AccountBadge(badgeId, accountBadge.getExpiration(), true); - } + AccountBadge accountBadge = existingBadges.get(badgeId).withVisibility(true); result.put(badgeId, accountBadge); } } @@ -495,10 +492,7 @@ public class ProfileController { // take any remaining account badges and make them invisible for (final Entry entry : existingBadges.entrySet()) { if (!result.containsKey(entry.getKey())) { - AccountBadge accountBadge = entry.getValue(); - if (accountBadge.isVisible()) { - accountBadge = new AccountBadge(accountBadge.getId(), accountBadge.getExpiration(), false); - } + AccountBadge accountBadge = entry.getValue().withVisibility(false); result.put(accountBadge.getId(), accountBadge); } } diff --git a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountBadge.java b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountBadge.java index 5aa459fde..c058ed742 100644 --- a/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountBadge.java +++ b/service/src/main/java/org/whispersystems/textsecuregcm/storage/AccountBadge.java @@ -52,6 +52,17 @@ public class AccountBadge { ); } + public AccountBadge withVisibility(boolean visible) { + if (this.visible == visible) { + return this; + } else { + return new AccountBadge( + this.id, + this.expiration, + visible); + } + } + public String getId() { return id; }