/* load avatar. */
String avatarId = configuration.getStringValue(sonePrefix + "/Profile/Avatar").getValue(null);
if (avatarId != null) {
- profile.setAvatar(getImage(avatarId).orNull());
+ profile.setAvatar(getImage(avatarId).transform(GET_ID));
}
/* load options. */
}
/* process avatar. */
- if (avatarId != null) {
- profile.setAvatar(database.getImage(avatarId).orNull());
- }
+ profile.setAvatar(fromNullable(avatarId));
/* okay, apparently everything was parsed correctly. Now import. */
sone.setProfile(profile);
/**
* Sets the avatar image.
*
- * @param avatar
- * The new avatar image, or {@code null} to not select an avatar
- * image.
- * @return This Sone
+ * @param avatarId
+ * The ID of the new avatar image
+ * @return This profile
*/
- public Profile setAvatar(Image avatar) {
- if (avatar == null) {
- this.avatar = null;
- return this;
- }
- checkArgument(avatar.getSone().equals(sone), "avatar must belong to Sone");
- this.avatar = avatar.getId();
+ public Profile setAvatar(Optional<String> avatarId) {
+ this.avatar = avatarId.orNull();
return this;
}
/* avatar ID but no matching image? show nothing. */
return null;
}
+ if (!avatarImageBelongsToTheSameSoneAsTheProfile(profile, avatarId)) {
+ return null;
+ }
Sone remoteSone = profile.getSone();
if (remoteSone.isLocal()) {
/* always show your own avatars. */
return super.get(templateContext, object, member);
}
+ private boolean avatarImageBelongsToTheSameSoneAsTheProfile(Profile profile, String avatarId) {
+ return core.getImage(avatarId).get().getSone().equals(profile.getSone());
+ }
+
}
package net.pterodactylus.sone.web;
+import static net.pterodactylus.sone.data.Identified.GET_ID;
+
import java.util.List;
import net.pterodactylus.sone.data.Profile;
avatarId = request.getHttpRequest().getPartAsStringFailsafe("avatarId", 36);
profile.modify().setFirstName(getNameFromFormField(firstName)).setMiddleName(getNameFromFormField(middleName)).setLastName(getNameFromFormField(lastName)).update();
profile.modify().setBirthDay(birthDay).setBirthMonth(birthMonth).setBirthYear(birthYear).update();
- profile.setAvatar(webInterface.getCore().getImage(avatarId).orNull());
+ profile.setAvatar(webInterface.getCore().getImage(avatarId).transform(GET_ID));
for (Field field : fields) {
String value = request.getHttpRequest().getPartAsStringFailsafe("field-" + field.getId(), 400);
field.setValue(value);