source: Klonkt/src/views/pages/timeline.ejs@ f0c3f83

main
Last change on this file since f0c3f83 was f6c414e, checked in by Robin Genis <roboburr@…>, 3 months ago

feat(fediverse): star = like via your own fediverse account (server-only input)

The post heart is now a star that lets any visitor like the post from their own
fediverse account: click -> enter just your server (e.g. mastodon.social) -> bounce
to your server's authorize_interaction. No full @handle needed (your server knows
who you are). Count shows incoming fediverse likes. Reuses the remote-interaction
popover; placeholder simplified to the server.

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

  • Property mode set to 100644
File size: 9.3 KB
Line 
1<div class="tl-wrap">
2 <h1 class="tl-title"><%= t('tl.title') %></h1>
3 <p class="tl-lead"><%= t('tl.lead') %></p>
4 <% if (typeof success !== 'undefined' && success) { %><div class="alert alert-success"><%= success %></div><% } %>
5 <% if (typeof error !== 'undefined' && error) { %><div class="alert alert-error"><%= error %></div><% } %>
6
7 <form method="post" action="/tijdlijn/follow" class="tl-follow">
8 <input type="text" name="handle" placeholder="@naam@server.social" autocomplete="off" spellcheck="false" required>
9 <button type="submit" class="btn btn-primary"><%= t('tl.follow_btn') %></button>
10 </form>
11
12 <% if (following && following.length) { %>
13 <h2 class="tl-sub"><%= t('tl.following') %> (<%= following.length %>)</h2>
14 <ul class="tl-foll-list">
15 <% following.forEach(function(f){ %>
16 <li class="tl-foll">
17 <span class="tl-foll-av"><% if (f.icon) { %><img src="<%= f.icon %>" alt=""><% } else { %><%= (f.name || '?').charAt(0).toUpperCase() %><% } %></span>
18 <span class="tl-foll-meta">
19 <a href="<%= f.url || f.actor_uri %>" target="_blank" rel="nofollow noopener"><%= f.name || f.handle %></a>
20 <span class="tl-foll-handle"><%= f.handle %></span>
21 <% if (f.status === 'pending') { %><span class="tl-pending"><%= t('tl.pending') %></span><% } %>
22 </span>
23 <form method="post" action="/tijdlijn/unfollow"><input type="hidden" name="actor_uri" value="<%= f.actor_uri %>"><button type="submit" class="tl-unfollow"><%= t('tl.unfollow') %></button></form>
24 </li>
25 <% }); %>
26 </ul>
27 <% } %>
28
29 <h2 class="tl-sub"><%= t('tl.feed') %></h2>
30 <% if (!timeline || !timeline.length) { %>
31 <p class="tl-empty"><%= t('tl.empty') %></p>
32 <% } else { %>
33 <ol class="tl-feed">
34 <% timeline.forEach(function(p){ %>
35 <li class="tl-item">
36 <span class="tl-avatar"><% if (p.author_icon) { %><img src="<%= p.author_icon %>" alt="" loading="lazy"><% } else { %><%= (p.author_name || '?').charAt(0).toUpperCase() %><% } %></span>
37 <div class="tl-itembody">
38 <div class="tl-meta">
39 <a class="tl-author" href="<%= p.author_url || p.author_uri %>" target="_blank" rel="nofollow noopener"><%= p.author_name %></a>
40 <span class="tl-handle"><%= p.author_handle %></span>
41 <% if (p.published || p.created_at) { %><span class="tl-time"><%= formatDateTime(p.published || p.created_at) %></span><% } %>
42 </div>
43 <div class="tl-content"><%- p.content %></div>
44 <% var media = []; try { media = JSON.parse(p.media_json || '[]'); } catch (e) { media = []; } %>
45 <% media.filter(function(m){ return !m.type || /^image\//.test(m.type); }).forEach(function(m){ %><img class="tl-media" src="<%= m.url %>" alt="" loading="lazy"><% }); %>
46 <% if (p.url) { %><p class="tl-orig"><a href="<%= p.url %>" target="_blank" rel="nofollow noopener"><%= t('tl.view_original') %></a></p><% } %>
47 <div class="tl-actions">
48 <form method="post" action="/tijdlijn/like" class="tl-act-form"><input type="hidden" name="note" value="<%= p.id %>"><input type="hidden" name="author" value="<%= p.author_uri %>"><button type="submit" class="tl-act" title="<%= t('fedi.likes') %>">⭐</button></form>
49 <form method="post" action="/tijdlijn/boost" class="tl-act-form"><input type="hidden" name="note" value="<%= p.id %>"><input type="hidden" name="author" value="<%= p.author_uri %>"><button type="submit" class="tl-act" title="<%= t('fedi.boosts') %>">🔁</button></form>
50 <button type="button" class="tl-act fedi-remote-reply-btn" data-fedi-uri="<%= p.id %>" data-fedi-ph="<%= t('fedi.remote_ph') %>" title="<%= t('fedi.remote_reply') %>">↩</button>
51 <form method="post" action="/blokkeren/add" class="tl-act-form" onsubmit="return confirm('<%= t('tl.block') %>?');"><input type="hidden" name="target" value="<%= p.author_uri %>"><button type="submit" class="tl-act" title="<%= t('tl.block') %>">🚫</button></form>
52 </div>
53 </div>
54 </li>
55 <% }); %>
56 </ol>
57 <% } %>
58</div>
59
60<style>
61 .tl-wrap { max-width: 640px; margin: 2rem auto; padding: 0 1rem; }
62 .tl-title { margin: 0 0 .25rem; }
63 .tl-lead { color: var(--ink-soft, #888); margin: 0 0 1.25rem; }
64 .tl-sub { font-size: 1.1rem; margin: 1.75rem 0 .75rem; }
65 .tl-follow { display: flex; gap: .5rem; margin: 0 0 1rem; flex-wrap: wrap; }
66 .tl-follow input { flex: 1; min-width: 200px; height: 2.4rem; padding: 0 .9rem; border-radius: 999px; font: inherit;
67 border: 1px solid color-mix(in srgb, var(--ink, #000) 18%, transparent); background: color-mix(in srgb, var(--ink, #000) 4%, transparent); color: var(--ink, #000); }
68 .tl-foll-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .4rem; }
69 .tl-foll { display: flex; align-items: center; gap: .6rem; padding: .45rem .6rem; border-radius: 12px; background: color-mix(in srgb, var(--ink, #000) 4%, transparent); }
70 .tl-foll-av, .tl-avatar { flex: 0 0 36px; width: 36px; height: 36px; border-radius: 50%; overflow: hidden; display: inline-flex; align-items: center; justify-content: center; font-weight: 700; background: color-mix(in srgb, var(--accent, #888) 20%, transparent); color: var(--accent, #555); }
71 .tl-foll-av img, .tl-avatar img { width: 100%; height: 100%; object-fit: cover; }
72 .tl-foll-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; line-height: 1.25; }
73 .tl-foll-handle, .tl-handle { color: var(--ink-soft, #888); font-size: .82rem; }
74 .tl-pending { font-size: .72rem; color: var(--ink-soft, #999); }
75 .tl-unfollow { background: none; border: 1px solid color-mix(in srgb, var(--ink, #000) 18%, transparent); border-radius: 8px; padding: .25rem .6rem; font-size: .8rem; color: var(--ink-soft, #888); cursor: pointer; }
76 .tl-unfollow:hover { color: var(--ink, #000); }
77 .tl-empty { color: var(--ink-soft, #888); }
78 .tl-feed { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .9rem; }
79 .tl-item { display: flex; gap: .75rem; padding: .9rem 1rem; border-radius: 14px; border: 1px solid color-mix(in srgb, var(--ink, #000) 9%, transparent); background: color-mix(in srgb, var(--ink, #000) 3%, transparent); }
80 .tl-itembody { flex: 1; min-width: 0; }
81 .tl-meta { display: flex; align-items: baseline; gap: .4rem; flex-wrap: wrap; }
82 .tl-author { font-weight: 600; color: var(--ink, inherit); text-decoration: none; }
83 .tl-author:hover { text-decoration: underline; }
84 .tl-time { color: var(--ink-soft, #999); font-size: .8rem; margin-left: auto; }
85 .tl-content { margin: .3rem 0 0; line-height: 1.5; overflow-wrap: anywhere; }
86 .tl-content p { margin: .25rem 0; } .tl-content p:first-child { margin-top: 0; }
87 .tl-media { max-width: 100%; height: auto; border-radius: 10px; margin: .5rem 0 0; display: block; }
88 .tl-orig { margin: .5rem 0 0; font-size: .82rem; }
89 .tl-orig a { color: var(--accent, #06c); }
90 .tl-actions { display: flex; gap: .35rem; margin-top: .55rem; }
91 .tl-act-form { margin: 0; }
92 .tl-act { background: none; border: 1px solid color-mix(in srgb, var(--ink, #000) 14%, transparent); border-radius: 999px; padding: .2rem .6rem; cursor: pointer; font-size: .9rem; color: var(--ink-soft, #888); }
93 .tl-act:hover { color: var(--ink, #000); border-color: color-mix(in srgb, var(--accent, #888) 50%, transparent); }
94</style>
95
96<script>
97(function(){
98 if (window.__fediRemoteWired) return; window.__fediRemoteWired = true;
99 var current = null, currentBtn = null;
100 function close(){ if (current) { current.remove(); current = null; currentBtn = null; } }
101 function go(raw, uri){ var d=(raw||'').trim().replace(/^@?[^@\s]*@/,'').replace(/^https?:\/\//i,'').replace(/\/.*$/,'').trim(); if(d) location.href='https://'+d+'/authorize_interaction?uri='+encodeURIComponent(uri||''); }
102 function place(f, b){ var r=b.getBoundingClientRect(); f.style.top=(r.bottom+window.scrollY+6)+'px'; f.style.left=Math.max(8, Math.min(r.left+window.scrollX, window.scrollX+window.innerWidth-340))+'px'; }
103 document.addEventListener('click', function(e){
104 if (e.target.closest && e.target.closest('.fedi-remote-cancel')) { close(); return; }
105 if (current && e.target.closest && e.target.closest('.fedi-remote-form')) return;
106 var b = e.target.closest && e.target.closest('.fedi-remote-reply-btn');
107 if (b) {
108 e.preventDefault();
109 if (currentBtn === b) { close(); return; }
110 close();
111 var f = document.createElement('form'); f.className='fedi-remote-form'; f.dataset.uri = b.getAttribute('data-fedi-uri')||'';
112 f.innerHTML = '<input type="text" autocomplete="off" spellcheck="false"><button type="submit" class="btn btn-primary fedi-remote-go" aria-label="ok">&rarr;</button><button type="button" class="fedi-remote-cancel" aria-label="x">&times;</button>';
113 f.querySelector('input').placeholder = b.getAttribute('data-fedi-ph') || 'mastodon.social';
114 document.body.appendChild(f); place(f, b); current=f; currentBtn=b; f.querySelector('input').focus();
115 return;
116 }
117 if (current) close();
118 });
119 document.addEventListener('submit', function(e){ var f=e.target.closest && e.target.closest('.fedi-remote-form'); if(!f) return; e.preventDefault(); go(f.querySelector('input').value, f.dataset.uri); });
120 document.addEventListener('keydown', function(e){ if (e.key === 'Escape') close(); });
121 window.addEventListener('scroll', close, true);
122})();
123</script>
Note: See TracBrowser for help on using the repository browser.