Send mute with log-in info

This commit is contained in:
Francisco Saldanha 2016-05-07 10:34:10 -03:00
parent da944508b4
commit 8444fa02f6

View File

@ -2,6 +2,7 @@ package net.frozenorb.apiv3.models;
import com.google.common.collect.ImmutableMap;
import com.google.common.collect.ImmutableSet;
import com.google.common.collect.Maps;
import lombok.Getter;
import lombok.Setter;
import net.frozenorb.apiv3.APIv3;
@ -217,6 +218,14 @@ public final class User {
accessDenialReason = punishment.getAccessDenialReason();
}
Punishment mute = null;
for (Punishment punishment : getPunishments(ImmutableSet.of(Punishment.PunishmentType.MUTE))) {
if (!punishment.isActive()) {
continue;
}
mute = punishment;
}
ServerGroup actorGroup = ServerGroup.byId(server.getGroup());
Rank highestRank = getHighestRank(actorGroup);
@ -226,16 +235,21 @@ public final class User {
actorGroup.calculatePermissions(highestRank)
);
return ImmutableMap.of(
"user", this,
"access", ImmutableMap.of(
"allowed", accessDenialReason == null,
"message", accessDenialReason == null ? "Public server" : accessDenialReason
),
"rank", highestRank.getId(),
"permissions", scopedPermissions,
"totpSetup", getTotpSecret() != null
);
Map<String, Object> loginInfo = Maps.newHashMap();
loginInfo.put("user", this);
loginInfo.put("access", ImmutableMap.of(
"allowed", accessDenialReason == null,
"message", accessDenialReason == null ? "Public server" : accessDenialReason
));
loginInfo.put("rank", highestRank.getId());
loginInfo.put("permissions", scopedPermissions);
loginInfo.put("totpSetup", getTotpSecret() != null);
if (mute != null) {
loginInfo.put("mute", mute);
}
return loginInfo;
}
}