Ignore:
Timestamp:
06/26/2026 11:30:21 PM (2 months ago)
Author:
Robin Genis <roboburr@…>
Branches:
main
Children:
3d37c67
Parents:
c745659
Message:

feat(fedi): comment like is a toggle too (Undo Like / un-favourite)

Symmetric to boost: ap_interactions.acted_like remembers a liked comment, the star
shows an 'on' state, and clicking again retracts it via Undo(Like) (Mastodon honours it).
sendInteraction gains an 'unlike' branch (author-only, no fanout).

File:
1 edited

Legend:

Unmodified
Added
Removed
  • src/services/ActivityPubService.js

    rc745659 r3289a64  
    352352    _delLA = db.prepare('DELETE FROM ap_interactions WHERE kind = ? AND post_id = ? AND actor_uri = ?');
    353353    _delReply = db.prepare("DELETE FROM ap_interactions WHERE kind = 'reply' AND object_uri = ?");
    354     _listI = db.prepare('SELECT id, kind, object_uri, parent_uri, actor_uri, actor_name, actor_handle, actor_url, actor_icon, content, published, created_at, acted_boost FROM ap_interactions WHERE post_id = ? ORDER BY created_at ASC');
     354    _listI = db.prepare('SELECT id, kind, object_uri, parent_uri, actor_uri, actor_name, actor_handle, actor_url, actor_icon, content, published, created_at, acted_boost, acted_like FROM ap_interactions WHERE post_id = ? ORDER BY created_at ASC');
    355355    _getI = db.prepare('SELECT * FROM ap_interactions WHERE id = ?');
    356356    _insO = db.prepare('INSERT INTO ap_outbox (id, site_slug, post_id, post_slug, in_reply_to, to_actor, to_handle, content, created_at) VALUES (?,?,?,?,?,?,?,?,CURRENT_TIMESTAMP)');
     
    364364export function setInteractionBoosted(id, on) {
    365365  db.prepare('UPDATE ap_interactions SET acted_boost = ? WHERE id = ?').run(on ? 1 : 0, id);
     366}
     367export function setInteractionLiked(id, on) {
     368  db.prepare('UPDATE ap_interactions SET acted_like = ? WHERE id = ?').run(on ? 1 : 0, id);
    366369}
    367370
     
    423426      actor_name: r.actor_name, actor_handle: r.actor_handle, actor_url: r.actor_url,
    424427      actor_icon: r.actor_icon, content: r.content, created_at: r.published || r.created_at,
    425       acted_boost: !!r.acted_boost,
     428      acted_boost: !!r.acted_boost, acted_like: !!r.acted_like,
    426429      children: [],
    427430    });
     
    12231226  const fanout = (kind === 'boost' || kind === 'unboost'); // also goes to our followers
    12241227  let act;
    1225   if (kind === 'unboost') {
     1228  if (kind === 'unboost' || kind === 'unlike') {
     1229    // Undo(Announce) retracts a boost; Undo(Like) un-favourites (matched on actor+object,
     1230    // no record of the original activity needed — Mastodon honours both).
     1231    const inner = kind === 'unboost' ? 'Announce' : 'Like';
    12261232    act = {
    12271233      '@context': 'https://www.w3.org/ns/activitystreams',
    12281234      id: `${me}#undo-${Date.now()}-${rid()}`, type: 'Undo', actor: me,
    1229       to: [PUBLIC], cc: [`${me}/followers`],
    1230       object: { id: `${me}#announce-${Date.now()}-${rid()}`, type: 'Announce', actor: me, object: targetNoteId },
     1235      object: { id: `${me}#${inner.toLowerCase()}-${Date.now()}-${rid()}`, type: inner, actor: me, object: targetNoteId },
    12311236    };
     1237    if (kind === 'unboost') { act.to = [PUBLIC]; act.cc = [`${me}/followers`]; }
    12321238  } else {
    12331239    const type = kind === 'boost' ? 'Announce' : 'Like';
     
    13311337  buildActor, buildNote, buildCreate, buildOutbox, buildFollowers, buildFeatured,
    13321338  followerCount, deliver, fetchActor, verifyRequest, handleInbox, deliverCreate, deliverDelete, deliverUpdate, deliverActorUpdate, resyncFeaturedPins,
    1333   getInteractions, getInteractionById, setInteractionBoosted, buildReplyNote, getOutboxNote, deliverReply, resolveRemoteNote,
     1339  getInteractions, getInteractionById, setInteractionBoosted, setInteractionLiked, buildReplyNote, getOutboxNote, deliverReply, resolveRemoteNote,
    13341340  listOutbox, deliverOutboxDelete,
    13351341  webfingerResolve, followActor, resolveRemoteActor, unfollowActor, listFollowing, setAutoBoost, getTimeline, sendInteraction,
Note: See TracChangeset for help on using the changeset viewer.