Topic preview
-
I really like the preview feature where if you link to an existing topic, a preview is generated when you hover over that link. I would like to leverage this preview as an embed in external pages/websites in an iframe. Is there an existing route for the preview or would I need a plugin to expose it?
As a corollary to the above, how would I go about exposing the votes on a post to an external page? Is the socket API open for usage on a different site (same domain, but different subdomain) -
It is a socket call, the source is here https://github.com/NodeBB/NodeBB/blob/master/src/socket.io/posts.js#L61-L75. The same call returns the vote count as part of the post object. You can try it with
console.log(await socket.emit('posts.getPostSummaryByPid', { pid: 92373 }));
Not sure how you can call it from an external page, might be easier to make a GET route in a plugin and call that.
-
Hi guys, the plugin to return the embeddable post works great. However, I noticed that there appears to be caching of the results somewhere in the pipeline. If I make a change to the post, its not reflected in the
posts.getPostSummaryByPid
call until after a restart. Is there a way to force retrieval of the refreshed post content? -
One more question, how are events bound to template elements? As an example, lets say I want to include the
post/upvote
orpost/downvote
components in a custom template, how would these links get bound to an action that ultimately calls the appropriate upvote/downvote method? -
It happens here https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/postTools.js#L124-L130. The module that handles upvoting is https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/votes.js. When a click is detected on the vote buttons this function is called https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/votes.js#L73.
So if you want the upvoting on a different template you need to add the click handlers and call
votes.toggleVote
and pass the correct parameters like we do. -
@baris Thank you, that works perfectly. Now the only thing left is listening for the change to update the vote count. I aplogize for the many questions but I've been working so long in the react/vuejs ecosystem that I've forgotten how data bindings are handled in jquery.
-
That happens here https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/events.js#L43-L45,
when a vote happens (upvoted,downvote or unvote) an event is sent from the server. We listen to that withsocket.on(eventName, handler)
and update the UI in this function https://github.com/NodeBB/NodeBB/blob/master/public/src/client/topic/events.js#L224