/*
- * Sone - ProfileAccessor.java - Copyright © 2011 David Roden
+ * Sone - ProfileAccessor.java - Copyright © 2011–2013 David Roden
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
import net.pterodactylus.sone.data.Profile;
import net.pterodactylus.sone.data.Sone;
import net.pterodactylus.sone.data.Sone.ShowCustomAvatars;
+import net.pterodactylus.sone.freenet.wot.OwnIdentity;
import net.pterodactylus.sone.freenet.wot.Trust;
import net.pterodactylus.util.template.Accessor;
import net.pterodactylus.util.template.ReflectionAccessor;
this.core = core;
}
- /**
- * {@inheritDoc}
- */
@Override
public Object get(TemplateContext templateContext, Object object, String member) {
Profile profile = (Profile) object;
/* not logged in? don’t show custom avatars, then. */
return null;
}
+ String avatarId = profile.getAvatar();
+ if (avatarId == null) {
+ return null;
+ }
+ if (!core.getImage(avatarId).isPresent()) {
+ /* avatar ID but no matching image? show nothing. */
+ return null;
+ }
+ if (!avatarImageBelongsToTheSameSoneAsTheProfile(profile, avatarId)) {
+ return null;
+ }
Sone remoteSone = profile.getSone();
- if (core.isLocalSone(remoteSone)) {
+ if (remoteSone.isLocal()) {
/* always show your own avatars. */
- return profile.getAvatar();
+ return avatarId;
}
ShowCustomAvatars showCustomAvatars = currentSone.getOptions().<ShowCustomAvatars> getEnumOption("ShowCustomAvatars").get();
if (showCustomAvatars == ShowCustomAvatars.NEVER) {
return null;
}
- String avatarId = profile.getAvatar();
- if ((showCustomAvatars == ShowCustomAvatars.ALWAYS) || (avatarId == null)) {
+ if (showCustomAvatars == ShowCustomAvatars.ALWAYS) {
return avatarId;
}
- if ((showCustomAvatars == ShowCustomAvatars.FOLLOWED) && currentSone.hasFriend(remoteSone.getId())) {
- return avatarId;
+ if (showCustomAvatars == ShowCustomAvatars.FOLLOWED) {
+ return currentSone.hasFriend(remoteSone.getId()) ? avatarId : null;
}
- Trust trust = core.getTrust(currentSone, remoteSone);
+ Trust trust = remoteSone.getIdentity().getTrust((OwnIdentity) currentSone.getIdentity());
if (trust == null) {
return null;
}
if ((showCustomAvatars == ShowCustomAvatars.MANUALLY_TRUSTED) && (trust.getExplicit() != null) && (trust.getExplicit() > 0)) {
return avatarId;
}
- if ((showCustomAvatars == ShowCustomAvatars.TRUSTED) && ((trust.getExplicit() != null) && (trust.getExplicit() > 0)) || ((trust.getImplicit() != null) && (trust.getImplicit() > 0))) {
+ if ((showCustomAvatars == ShowCustomAvatars.TRUSTED) && (((trust.getExplicit() != null) && (trust.getExplicit() > 0)) || ((trust.getImplicit() != null) && (trust.getImplicit() > 0)))) {
return avatarId;
}
return null;
return super.get(templateContext, object, member);
}
+ private boolean avatarImageBelongsToTheSameSoneAsTheProfile(Profile profile, String avatarId) {
+ return core.getImage(avatarId).get().getSone().equals(profile.getSone());
+ }
+
}