Changeset c7ecaf9 in Klonkt for src/routes/posts.js


Ignore:
Timestamp:
06/26/2026 11:45:53 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
9d34855
Parents:
2f42b60
Message:

feat(fedi): like/boost toggle in place on the interact page (no reload)

The Like/Boost forms now POST via fetch and flip the button + label client-side, so you
stay on the page instead of a full redirect+re-resolve. Route returns JSON {on} for a
fetch request (X-Requested-With), and still redirects for the no-JS fallback. Body sent
as urlencoded so the existing body parser reads it.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/posts.js

    r2f42b60 rc7ecaf9  
    511511  const site = res.locals.site;
    512512  const uri = (req.body.uri || '').toString();
     513  let on = false;
    513514  if (site && uri) {
    514     const on = !ActivityPubService.getMyReactions(site.slug, uri).liked;
     515    on = !ActivityPubService.getMyReactions(site.slug, uri).liked;
    515516    ActivityPubService.resolveRemoteNote(uri)
    516517      .then((note) => note && ActivityPubService.sendInteraction(site, on ? 'like' : 'unlike', note.object_uri || uri, note.actor_uri))
     
    518519    ActivityPubService.setMyReaction(site.slug, uri, 'like', on);
    519520  }
     521  if (req.get('X-Requested-With') === 'fetch') return res.json({ ok: true, on });
    520522  res.redirect('/authorize_interaction?uri=' + encodeURIComponent(uri));
    521523});
     
    526528  const site = res.locals.site;
    527529  const uri = (req.body.uri || '').toString();
     530  let on = false;
    528531  if (site && uri) {
    529     const on = !ActivityPubService.getMyReactions(site.slug, uri).boosted;
     532    on = !ActivityPubService.getMyReactions(site.slug, uri).boosted;
    530533    ActivityPubService.resolveRemoteNote(uri)
    531534      .then((note) => {
     
    538541    ActivityPubService.setMyReaction(site.slug, uri, 'boost', on);
    539542  }
     543  if (req.get('X-Requested-With') === 'fetch') return res.json({ ok: true, on });
    540544  res.redirect('/authorize_interaction?uri=' + encodeURIComponent(uri));
    541545});
Note: See TracChangeset for help on using the changeset viewer.