- (data as? Iterable<Part>)
- ?.filterIsInstance<FreenetLinkPart>()
- ?.map { elementLoader.loadElement(it.link) }
- ?: listOf<LinkedElement>()
+ if (showLinkedImages(templateContext?.get("currentSone") as Sone?, parameters?.get("sone") as Sone?)) {
+ (data as? Iterable<Part>)
+ ?.filterIsInstance<FreenetLinkPart>()
+ ?.map { elementLoader.loadElement(it.link) }
+ ?.filter { !it.failed }
+ ?: listOf()
+ } else {
+ listOf()
+ }
+
+ private fun showLinkedImages(currentSone: Sone?, sone: Sone?): Boolean {
+ return (currentSone != null) && (sone != null) && ((currentSone == sone) || currentSoneAllowsImagesFromSone(currentSone, sone))
+ }
+
+ private fun currentSoneAllowsImagesFromSone(currentSone: Sone, externalSone: Sone) =
+ when (currentSone.options.loadLinkedImages) {
+ NEVER -> false
+ MANUALLY_TRUSTED -> externalSone.isLocal || currentSone.explicitelyTrusts(externalSone)
+ FOLLOWED -> externalSone.isLocal || currentSone.hasFriend(externalSone.id)
+ TRUSTED -> externalSone.isLocal || currentSone.implicitelyTrusts(externalSone)
+ ALWAYS -> true
+ }
+
+ private fun Sone.implicitelyTrusts(other: Sone): Boolean {
+ val explicitTrust = other.identity.getTrust(this.identity as OwnIdentity)?.explicit
+ val implicitTrust = other.identity.getTrust(this.identity as OwnIdentity)?.implicit
+ return ((explicitTrust != null) && (explicitTrust > 0)) || ((explicitTrust == null) && (implicitTrust != null) && (implicitTrust > 0))
+ }
+
+ private fun Sone.explicitelyTrusts(other: Sone) =
+ other.identity.getTrust(this.identity as OwnIdentity)?.explicit ?: -1 > 0