mirror of
https://github.com/signalapp/Signal-Server
synced 2026-04-20 14:58:07 +01:00
Add current entitlements to whoami response
This commit is contained in:
committed by
ravi-signal
parent
d5b39cd496
commit
33c0a27b85
@@ -4,7 +4,11 @@
|
||||
*/
|
||||
package org.whispersystems.textsecuregcm.controllers;
|
||||
|
||||
import java.time.Clock;
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import org.whispersystems.textsecuregcm.entities.AccountIdentityResponse;
|
||||
import org.whispersystems.textsecuregcm.entities.Entitlements;
|
||||
import org.whispersystems.textsecuregcm.storage.Account;
|
||||
import org.whispersystems.textsecuregcm.storage.DeviceCapability;
|
||||
|
||||
@@ -12,10 +16,12 @@ public class AccountIdentityResponseBuilder {
|
||||
|
||||
private final Account account;
|
||||
private boolean storageCapable;
|
||||
private Clock clock;
|
||||
|
||||
public AccountIdentityResponseBuilder(Account account) {
|
||||
this.account = account;
|
||||
this.storageCapable = account.hasCapability(DeviceCapability.STORAGE);
|
||||
this.clock = Clock.systemUTC();
|
||||
}
|
||||
|
||||
public AccountIdentityResponseBuilder storageCapable(boolean storageCapable) {
|
||||
@@ -23,13 +29,31 @@ public class AccountIdentityResponseBuilder {
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountIdentityResponseBuilder clock(Clock clock) {
|
||||
this.clock = clock;
|
||||
return this;
|
||||
}
|
||||
|
||||
public AccountIdentityResponse build() {
|
||||
final List<Entitlements.BadgeEntitlement> badges = account.getBadges()
|
||||
.stream()
|
||||
.filter(bv -> bv.expiration().isAfter(clock.instant()))
|
||||
.map(badge -> new Entitlements.BadgeEntitlement(badge.id(), badge.expiration(), badge.visible()))
|
||||
.toList();
|
||||
|
||||
final Entitlements.BackupEntitlement backupEntitlement = Optional
|
||||
.ofNullable(account.getBackupVoucher())
|
||||
.filter(bv -> bv.expiration().isAfter(clock.instant()))
|
||||
.map(bv -> new Entitlements.BackupEntitlement(bv.receiptLevel(), bv.expiration()))
|
||||
.orElse(null);
|
||||
|
||||
return new AccountIdentityResponse(account.getUuid(),
|
||||
account.getNumber(),
|
||||
account.getPhoneNumberIdentifier(),
|
||||
account.getUsernameHash().filter(h -> h.length > 0).orElse(null),
|
||||
account.getUsernameLinkHandle(),
|
||||
storageCapable);
|
||||
storageCapable,
|
||||
new Entitlements(badges, backupEntitlement));
|
||||
}
|
||||
|
||||
public static AccountIdentityResponse fromAccount(final Account account) {
|
||||
|
||||
Reference in New Issue
Block a user