Changeset 667fb41 in Klonkt for src/routes/posts.js


Ignore:
Timestamp:
07/01/2026 01:32:22 PM (2 months ago)
Author:
roboburr <roboburr@…>
Branches:
main
Children:
c45c187
Parents:
bb3f67c
Message:

feat(polls): vote on any fediverse poll from the interact page

The interact page (paste any post URL) now detects a Question and shows a ballot
(radio/checkbox + Vote) so you can vote on any fediverse poll by URL — not only
polls from accounts you follow (which vote via /news). Casts the Mastodon-standard
ballot straight to the poll's author, no timeline cache needed.

  • src/services/ActivityPubService.js — voteOnRemotePoll(site, url, choices) fetches the Question fresh, validates the choice(s) and delivers the ballot to the author; resolveRemoteNote now returns the parsed poll so the view can render options.
  • src/routes/posts.js — POST /authorize_interaction/vote; GET passes voted and skips re-resolving the target on the confirmation view.
  • src/views/pages/authorize-interaction.ejs — ballot (open) / results (closed) above the like/boost/reply actions, a "vote sent" confirmation, and scoped .auth-poll styles.
  • src/services/i18n.js — poll.voted_title/_done (nl/en/de).

Co-Authored-By: Claude <noreply@…>

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/routes/posts.js

    rbb3f67c r667fb41  
    580580  const sent = !!req.query.sent;
    581581  const followed = !!req.query.followed;
     582  const voted = !!req.query.voted;
    582583  let target = null, followTarget = null;
    583   if (!sent && !followed && uri) {
     584  if (!sent && !followed && !voted && uri) {
    584585    try { target = await ActivityPubService.resolveRemoteNote(uri); } catch { /* ignore */ }
    585586    // Not a post? Maybe the URI is a profile/actor → offer Follow, not reply.
     
    594595    sent,
    595596    followed,
     597    voted: !!req.query.voted,
    596598    liked: !!req.query.liked,
    597599    boosted: !!req.query.boosted,
     
    599601    siteTitle: site ? site.title : '',
    600602  });
     603});
     604
     605// 📊 Vote on a remote fediverse poll from the interact page (any poll by URL, not just
     606// followed ones). Casts the Mastodon-standard ballot straight to the poll's author.
     607router.post('/authorize_interaction/vote', requireSiteManager, async (req, res) => {
     608  const site = res.locals.site;
     609  const uri = (req.body.uri || '').toString();
     610  let choice = req.body.choice;
     611  if (choice == null) choice = [];
     612  if (!Array.isArray(choice)) choice = [choice];
     613  if (site && uri && choice.length) { try { await ActivityPubService.voteOnRemotePoll(site, uri, choice.map(String)); } catch { /* ignore */ } }
     614  res.redirect('/authorize_interaction?voted=1&uri=' + encodeURIComponent(uri));
    601615});
    602616
Note: See TracChangeset for help on using the changeset viewer.