Added missing checks for polycentric enabled.

This commit is contained in:
Koen J 2025-05-19 15:37:39 +02:00
commit af337b1874
4 changed files with 78 additions and 53 deletions

View file

@ -70,8 +70,8 @@ class ChannelContentsFragment(private val subType: String? = null) : Fragment(),
val lastPolycentricProfile = _lastPolycentricProfile; val lastPolycentricProfile = _lastPolycentricProfile;
var pager: IPager<IPlatformContent>? = null; var pager: IPager<IPlatformContent>? = null;
if (lastPolycentricProfile != null) if (lastPolycentricProfile != null && StatePolycentric.instance.enabled)
pager= StatePolycentric.instance.getChannelContent(lifecycleScope, lastPolycentricProfile); pager = StatePolycentric.instance.getChannelContent(lifecycleScope, lastPolycentricProfile);
if(pager == null) { if(pager == null) {
if(subType != null) if(subType != null)

View file

@ -47,6 +47,7 @@ import com.futo.platformplayer.selectHighestResolutionImage
import com.futo.platformplayer.states.StatePlatform import com.futo.platformplayer.states.StatePlatform
import com.futo.platformplayer.states.StatePlayer import com.futo.platformplayer.states.StatePlayer
import com.futo.platformplayer.states.StatePlaylists import com.futo.platformplayer.states.StatePlaylists
import com.futo.platformplayer.states.StatePolycentric
import com.futo.platformplayer.states.StateSubscriptions import com.futo.platformplayer.states.StateSubscriptions
import com.futo.platformplayer.toHumanNumber import com.futo.platformplayer.toHumanNumber
import com.futo.platformplayer.views.adapters.ChannelTab import com.futo.platformplayer.views.adapters.ChannelTab
@ -135,6 +136,8 @@ class ChannelFragment : MainFragment() {
inflater.inflate(R.layout.fragment_channel, this) inflater.inflate(R.layout.fragment_channel, this)
_taskLoadPolycentricProfile = TaskHandler<PlatformID, PolycentricProfile?>({ fragment.lifecycleScope }, _taskLoadPolycentricProfile = TaskHandler<PlatformID, PolycentricProfile?>({ fragment.lifecycleScope },
{ id -> { id ->
if (!StatePolycentric.instance.enabled)
return@TaskHandler null
return@TaskHandler ApiMethods.getPolycentricProfileByClaim(ApiMethods.SERVER, ApiMethods.FUTO_TRUST_ROOT, id.claimFieldType.toLong(), id.claimType.toLong(), id.value!!) return@TaskHandler ApiMethods.getPolycentricProfileByClaim(ApiMethods.SERVER, ApiMethods.FUTO_TRUST_ROOT, id.claimFieldType.toLong(), id.claimType.toLong(), id.value!!)
}).success { setPolycentricProfile(it, animate = true) }.exception<Throwable> { }).success { setPolycentricProfile(it, animate = true) }.exception<Throwable> {
Logger.w(TAG, "Failed to load polycentric profile.", it) Logger.w(TAG, "Failed to load polycentric profile.", it)

View file

@ -168,7 +168,12 @@ class PostDetailFragment : MainFragment {
UIDialogs.showGeneralRetryErrorDialog(context, context.getString(R.string.failed_to_load_post), it, ::fetchPost, null, _fragment); UIDialogs.showGeneralRetryErrorDialog(context, context.getString(R.string.failed_to_load_post), it, ::fetchPost, null, _fragment);
} else TaskHandler(IPlatformPostDetails::class.java) { _fragment.lifecycleScope }; } else TaskHandler(IPlatformPostDetails::class.java) { _fragment.lifecycleScope };
private val _taskLoadPolycentricProfile = TaskHandler<PlatformID, PolycentricProfile?>(StateApp.instance.scopeGetter, { ApiMethods.getPolycentricProfileByClaim(ApiMethods.SERVER, ApiMethods.FUTO_TRUST_ROOT, it.claimFieldType.toLong(), it.claimType.toLong(), it.value!!) }) private val _taskLoadPolycentricProfile = TaskHandler<PlatformID, PolycentricProfile?>(StateApp.instance.scopeGetter, {
if (!StatePolycentric.instance.enabled)
return@TaskHandler null
ApiMethods.getPolycentricProfileByClaim(ApiMethods.SERVER, ApiMethods.FUTO_TRUST_ROOT, it.claimFieldType.toLong(), it.claimType.toLong(), it.value!!)
})
.success { it -> setPolycentricProfile(it, animate = true) } .success { it -> setPolycentricProfile(it, animate = true) }
.exception<Throwable> { .exception<Throwable> {
Logger.w(TAG, "Failed to load claims.", it); Logger.w(TAG, "Failed to load claims.", it);
@ -327,6 +332,10 @@ class PostDetailFragment : MainFragment {
val version = _version; val version = _version;
_rating.onLikeDislikeUpdated.remove(this); _rating.onLikeDislikeUpdated.remove(this);
if (!StatePolycentric.instance.enabled)
return
_fragment.lifecycleScope.launch(Dispatchers.IO) { _fragment.lifecycleScope.launch(Dispatchers.IO) {
if (version != _version) { if (version != _version) {
return@launch; return@launch;

View file

@ -1525,60 +1525,68 @@ class VideoDetailView : ConstraintLayout {
_rating.visibility = View.GONE; _rating.visibility = View.GONE;
fragment.lifecycleScope.launch(Dispatchers.IO) { if (StatePolycentric.instance.enabled) {
try { fragment.lifecycleScope.launch(Dispatchers.IO) {
val queryReferencesResponse = ApiMethods.getQueryReferences( try {
ApiMethods.SERVER, ref, null, null, val queryReferencesResponse = ApiMethods.getQueryReferences(
arrayListOf( ApiMethods.SERVER, ref, null, null,
Protocol.QueryReferencesRequestCountLWWElementReferences.newBuilder() arrayListOf(
.setFromType(ContentType.OPINION.value).setValue( Protocol.QueryReferencesRequestCountLWWElementReferences.newBuilder()
ByteString.copyFrom(Opinion.like.data) .setFromType(ContentType.OPINION.value).setValue(
).build(), ByteString.copyFrom(Opinion.like.data)
Protocol.QueryReferencesRequestCountLWWElementReferences.newBuilder() ).build(),
.setFromType(ContentType.OPINION.value).setValue( Protocol.QueryReferencesRequestCountLWWElementReferences.newBuilder()
ByteString.copyFrom(Opinion.dislike.data) .setFromType(ContentType.OPINION.value).setValue(
).build() ByteString.copyFrom(Opinion.dislike.data)
), ).build()
extraByteReferences = listOfNotNull(extraBytesRef) ),
); extraByteReferences = listOfNotNull(extraBytesRef)
);
val likes = queryReferencesResponse.countsList[0]; val likes = queryReferencesResponse.countsList[0];
val dislikes = queryReferencesResponse.countsList[1]; val dislikes = queryReferencesResponse.countsList[1];
val hasLiked = StatePolycentric.instance.hasLiked(ref.toByteArray())/* || extraBytesRef?.let { StatePolycentric.instance.hasLiked(it) } ?: false*/; val hasLiked =
val hasDisliked = StatePolycentric.instance.hasDisliked(ref.toByteArray())/* || extraBytesRef?.let { StatePolycentric.instance.hasDisliked(it) } ?: false*/; StatePolycentric.instance.hasLiked(ref.toByteArray())/* || extraBytesRef?.let { StatePolycentric.instance.hasLiked(it) } ?: false*/;
val hasDisliked =
StatePolycentric.instance.hasDisliked(ref.toByteArray())/* || extraBytesRef?.let { StatePolycentric.instance.hasDisliked(it) } ?: false*/;
withContext(Dispatchers.Main) { withContext(Dispatchers.Main) {
_rating.visibility = View.VISIBLE; _rating.visibility = View.VISIBLE;
_rating.setRating(RatingLikeDislikes(likes, dislikes), hasLiked, hasDisliked); _rating.setRating(
_rating.onLikeDislikeUpdated.subscribe(this) { args -> RatingLikeDislikes(likes, dislikes),
if (args.hasLiked) { hasLiked,
args.processHandle.opinion(ref, Opinion.like); hasDisliked
} else if (args.hasDisliked) { );
args.processHandle.opinion(ref, Opinion.dislike); _rating.onLikeDislikeUpdated.subscribe(this) { args ->
} else { if (args.hasLiked) {
args.processHandle.opinion(ref, Opinion.neutral); args.processHandle.opinion(ref, Opinion.like);
} } else if (args.hasDisliked) {
args.processHandle.opinion(ref, Opinion.dislike);
fragment.lifecycleScope.launch(Dispatchers.IO) { } else {
try { args.processHandle.opinion(ref, Opinion.neutral);
Logger.i(TAG, "Started backfill");
args.processHandle.fullyBackfillServersAnnounceExceptions();
Logger.i(TAG, "Finished backfill");
} catch (e: Throwable) {
Logger.e(TAG, "Failed to backfill servers", e)
} }
}
StatePolycentric.instance.updateLikeMap( fragment.lifecycleScope.launch(Dispatchers.IO) {
ref, try {
args.hasLiked, Logger.i(TAG, "Started backfill");
args.hasDisliked args.processHandle.fullyBackfillServersAnnounceExceptions();
) Logger.i(TAG, "Finished backfill");
}; } catch (e: Throwable) {
Logger.e(TAG, "Failed to backfill servers", e)
}
}
StatePolycentric.instance.updateLikeMap(
ref,
args.hasLiked,
args.hasDisliked
)
};
}
} catch (e: Throwable) {
Logger.e(TAG, "Failed to get polycentric likes/dislikes.", e);
_rating.visibility = View.GONE;
} }
} catch (e: Throwable) {
Logger.e(TAG, "Failed to get polycentric likes/dislikes.", e);
_rating.visibility = View.GONE;
} }
} }
@ -3066,7 +3074,12 @@ class VideoDetailView : ConstraintLayout {
Logger.w(TAG, "Failed to load recommendations.", it); Logger.w(TAG, "Failed to load recommendations.", it);
}; };
private val _taskLoadPolycentricProfile = TaskHandler<PlatformID, PolycentricProfile?>(StateApp.instance.scopeGetter, { ApiMethods.getPolycentricProfileByClaim(ApiMethods.SERVER, ApiMethods.FUTO_TRUST_ROOT, it.claimFieldType.toLong(), it.claimType.toLong(), it.value!!) }) private val _taskLoadPolycentricProfile = TaskHandler<PlatformID, PolycentricProfile?>(StateApp.instance.scopeGetter, {
if (!StatePolycentric.instance.enabled)
return@TaskHandler null
ApiMethods.getPolycentricProfileByClaim(ApiMethods.SERVER, ApiMethods.FUTO_TRUST_ROOT, it.claimFieldType.toLong(), it.claimType.toLong(), it.value!!)
})
.success { it -> setPolycentricProfile(it, animate = true) } .success { it -> setPolycentricProfile(it, animate = true) }
.exception<Throwable> { .exception<Throwable> {
Logger.w(TAG, "Failed to load claims.", it); Logger.w(TAG, "Failed to load claims.", it);