Regarding the page refresh when someone hits the like when using this awesome Add-On, I wanted to contribute, with my limited knowledge, providing a temporary solution which
should work fine for everyone.
My idea is to refresh the page after 5 seconds (enough time for the site/users to register the like function) so that the content will be unlocked without having users to refresh the page manually.
Before you proceed, please do a backup.
All you have to do is to edit the "post_macros" template.
Find
Code:
<a href="{{ link('posts/like', $post) }}" class="actionBar-action actionBar-action--like" data-xf-click="like" data-like-list="< .js-post | .js-likeList"><xf:if is="$post.isLiked()">{{ phrase('unlike') }}<xf:else />{{ phrase('like') }}</xf:if></a>
And
replace it with the following:
Code:
<xf:if is="{$post.position} == 0">
<a href="{{ link('posts/like', $post) }}" class="actionBar-action actionBar-action--like" data-xf-click="like" data-like-list="< .js-post | .js-likeList" <xf:if is="$post.isLiked()">>{{ phrase('unlike') }}<xf:else />id="xyz">{{ phrase('like') }}</xf:if></a>
<script>
jQuery("#xyz").on("click", function (e) {
setTimeout(function(){
location.reload();
}, 5000)
});
</script>
<xf:else />
<a href="{{ link('posts/like', $post) }}" class="actionBar-action actionBar-action--like" data-xf-click="like" data-like-list="< .js-post | .js-likeList"><xf:if is="$post.isLiked()">{{ phrase('unlike') }}<xf:else />{{ phrase('like') }}</xf:if></a>
</xf:if>
This modification will distinguish the first post of a thread with other posts, so that the refresh works only if people like the first post (if you set up a forum like mine, where hidden content is always and only in the first post, otherwise feel free to edit it). Also, it will prevent the refresh from happening if people are clicking Unlike rather than Like.
A similar approach could be done with replies, but it's up to you.
Known issues:
• If a user is having a very slow connection (or your site is very slow), 5 seconds (5000 milliseconds in the code above) might not be enough to register the like action, so he might have the page refreshed and the content still locked because the Like wasn't registered succesfully.
A good solution might be increasing the wait time before the refresh from 5000 to a higher value, if you think it's the case. A better approach would probably be injecting this javascript function AFTER the Like function so that it gets triggered without the need of adding a OnClick, but it would automatically refresh after the like is registered.
• Users might cheat and unlike the content after liking it, so that they unlock the content without having liked your post. To fix this, you should replace
with
as this will hide the "unlike" button from the first post.
I hope it helps.