Changeset 3d37c67 in Klonkt for src/routes


Ignore:
Timestamp:
06/26/2026 11:38:25 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
2f42b60
Parents:
3289a64
Message:

feat(fedi): interact page like/boost are 2 icon+label toggle buttons

Replace the '★ Like this post' / '🔁 Boost this post' buttons with two pill buttons
(gold star + Like, green repeat + Boost) that are real toggles. New ap_my_reactions
table tracks your like/boost state on a REMOTE post; clicking again retracts (Undo
Like / Undo Announce). The like/boost POST now redirects back to the interact page so
the state shows in place (no more separate confirmation screen).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/posts.js

    r3289a64 r3d37c67  
    502502    liked: !!req.query.liked,
    503503    boosted: !!req.query.boosted,
     504    reacted: (site && uri) ? ActivityPubService.getMyReactions(site.slug, uri) : { liked: false, boosted: false },
    504505    siteTitle: site ? site.title : '',
    505506  });
    506507});
    507508
    508 // ⭐ Like a remote post from your own site (the star flow lands here).
     509// ⭐ Like / unlike a remote post from your own site (toggle on the interact page).
    509510router.post('/authorize_interaction/like', requireSiteManager, (req, res) => {
    510511  const site = res.locals.site;
    511512  const uri = (req.body.uri || '').toString();
    512513  if (site && uri) {
     514    const on = !ActivityPubService.getMyReactions(site.slug, uri).liked;
    513515    ActivityPubService.resolveRemoteNote(uri)
    514       .then((note) => note && ActivityPubService.sendInteraction(site, 'like', note.object_uri || uri, note.actor_uri))
     516      .then((note) => note && ActivityPubService.sendInteraction(site, on ? 'like' : 'unlike', note.object_uri || uri, note.actor_uri))
    515517      .catch((e) => console.warn('[AP] remote like failed:', e.message));
    516   }
    517   res.redirect('/authorize_interaction?liked=1&uri=' + encodeURIComponent(uri));
    518 });
    519 
    520 // 🔁 Boost a remote post from your own site. Also flags it for the Cirkel
    521 // (markBoosted is a no-op if the post isn't in your timeline).
     518    ActivityPubService.setMyReaction(site.slug, uri, 'like', on);
     519  }
     520  res.redirect('/authorize_interaction?uri=' + encodeURIComponent(uri));
     521});
     522
     523// 🔁 Boost / unboost a remote post from your own site (toggle on the interact page).
     524// Also flags it for the Cirkel (markBoosted is a no-op if the post isn't in your timeline).
    522525router.post('/authorize_interaction/boost', requireSiteManager, (req, res) => {
    523526  const site = res.locals.site;
    524527  const uri = (req.body.uri || '').toString();
    525528  if (site && uri) {
     529    const on = !ActivityPubService.getMyReactions(site.slug, uri).boosted;
    526530    ActivityPubService.resolveRemoteNote(uri)
    527531      .then((note) => {
    528532        if (!note) return;
    529533        const id = note.object_uri || uri;
    530         return Promise.resolve(ActivityPubService.sendInteraction(site, 'boost', id, note.actor_uri))
    531           .then(() => ActivityPubService.markBoosted(site.slug, id));
     534        return Promise.resolve(ActivityPubService.sendInteraction(site, on ? 'boost' : 'unboost', id, note.actor_uri))
     535          .then(() => on ? ActivityPubService.markBoosted(site.slug, id) : ActivityPubService.unmarkBoosted(site.slug, id));
    532536      })
    533537      .catch((e) => console.warn('[AP] remote boost failed:', e.message));
    534   }
    535   res.redirect('/authorize_interaction?boosted=1&uri=' + encodeURIComponent(uri));
     538    ActivityPubService.setMyReaction(site.slug, uri, 'boost', on);
     539  }
     540  res.redirect('/authorize_interaction?uri=' + encodeURIComponent(uri));
    536541});
    537542
Note: See TracChangeset for help on using the changeset viewer.