source: Klonkt/src/views/pages/messages.ejs@ ff3b8ce

main
Last change on this file since ff3b8ce was 5190152, checked in by Robin <roboburr@…>, 7 weeks ago

Feature: rich editor on the edit forms too (klonkt-demo-c7f, last slice)

Editing a sent reply (Messages + the interact page's manage list) now opens the
same shared editor as new replies, instead of a bare textarea. Prutter stays
plain on purpose (Robin: not part of this).

  • reply-editor partial: initialHtml/initialText prefill for edit mode, and a noAttach flag that omits the media UI (an edit never touches attachments). JS grew canAttach guards so the component runs without the attach elements; pasted files are still swallowed there rather than becoming base64 blobs.
  • deliverOutboxUpdate(site, id, text, {html, language}): rich path with the same sanitize + enrichment + mention-first-paragraph logic as deliverReply; language updated via COALESCE (bogus codes keep the old one); attachments survive untouched. Plain path unchanged.
  • /fediverse/:id/edit passes content + language; listOutbox and the Messages sent-projection carry language so the select preselects correctly.
  • The interact page's edit-toggle focuses the rich editor when present.

2 new tests (93 green). Browser-verified on /messages: prefilled editor
(mention-stripped HTML + plain fallback + language preselected, no paperclip),
edit saved -> content replaced with markup, mention re-attached inline,
language nl->en, no console errors.

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

  • Property mode set to 100644
File size: 14.1 KB
RevLine 
[f1a23b8]1<div class="msg-wrap">
2 <%- include('../partials/fedi-tabs', { active: 'berichten' }) %>
3 <h1 class="msg-title"><%= t('msg.title') %></h1>
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 <div class="msg-filters" role="tablist" aria-label="<%= t('msg.title') %>">
8 <button type="button" class="msg-chip is-on" data-show="all"><%= t('msg.filter_all') %></button>
9 <button type="button" class="msg-chip" data-show="conv"><%= t('msg.filter_conv') %></button>
10 <button type="button" class="msg-chip" data-show="act"><%= t('msg.filter_act') %></button>
11 <button type="button" class="msg-chip" data-show="sent"><%= t('msg.filter_sent') %></button>
12 </div>
13
14 <% var _seen = (typeof seenAt !== 'undefined' && seenAt) ? seenAt : 0; %>
15 <% if (!items || !items.length) { %>
16 <p class="msg-empty"><%= t('msg.empty') %></p>
17 <% } else { %>
18 <ul class="msg-list" data-show="all">
19 <% items.forEach(function(n){
20 var _t = n.type === 'announce' ? 'boost' : n.type; // reply|mention|report|like|boost|follow|sent
21 var _kind = (_t === 'like' || _t === 'boost' || _t === 'follow') ? 'act' : (_t === 'sent' ? 'sent' : 'conv');
22 var _new = _seen && n.created_at ? (Date.parse(n.created_at) > _seen) : false;
23 var _who = n.name || n.handle || '';
24 var _init = String(_who || '?').replace(/^@/, '').charAt(0).toUpperCase();
25 var _priv = (n.visibility === 'followers' || n.visibility === 'direct');
26 %>
27 <li class="msg-item msg-<%= _t %><%= _new ? ' is-new' : '' %>" data-kind="<%= _kind %>">
28 <span class="msg-av<%= _t === 'sent' ? ' msg-av-sent' : '' %>" aria-hidden="true">
29 <% if (_t === 'sent') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"><line x1="22" y1="2" x2="11" y2="13"/><polygon points="22 2 15 22 11 13 2 9 22 2"/></svg>
30 <% } else if (n.icon) { %><img src="<%= avatar(n.icon, 96) %>" alt="" loading="lazy">
31 <% } else { %><%= _init %><% } %>
32 <span class="msg-dot msg-dot-<%= _t %>">
33 <% if (_t === 'like') { %><svg viewBox="0 0 24 24" fill="currentColor"><path d="M12 2.6l2.9 5.88 6.49.95-4.7 4.58 1.11 6.46L12 17.96l-5.8 3.06 1.1-6.46-4.69-4.58 6.49-.95z"/></svg>
34 <% } else if (_t === 'boost') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><polyline points="17 1 21 5 17 9"/><path d="M3 11V9a4 4 0 0 1 4-4h14"/><polyline points="7 23 3 19 7 15"/><path d="M21 13v2a4 4 0 0 1-4 4H3"/></svg>
35 <% } else if (_t === 'follow') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2"/><circle cx="9" cy="7" r="4"/><line x1="19" y1="8" x2="19" y2="14"/><line x1="22" y1="11" x2="16" y2="11"/></svg>
36 <% } else if (_t === 'report') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M4 15s1-1 4-1 5 2 8 2 4-1 4-1V3s-1 1-4 1-5-2-8-2-4 1-4 1z"/><line x1="4" y1="22" x2="4" y2="15"/></svg>
37 <% } else if (_t === 'mention') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><circle cx="12" cy="12" r="4"/><path d="M16 8v5a3 3 0 0 0 6 0v-1a10 10 0 1 0-3.92 7.94"/></svg>
38 <% } else if (_t === 'sent') { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><polyline points="9 17 4 12 9 7"/><path d="M20 18v-2a4 4 0 0 0-4-4H4"/></svg>
39 <% } else { %><svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2.4" stroke-linecap="round" stroke-linejoin="round"><path d="M21 15a2 2 0 0 1-2 2H7l-4 4V5a2 2 0 0 1 2-2h14a2 2 0 0 1 2 2z"/></svg><% } %>
40 </span>
41 </span>
42
43 <div class="msg-body">
44 <div class="msg-line">
45 <% if (_t === 'sent') { %>
46 <span class="msg-who"><%= t('msg.you') %></span>
47 <% if (n.to_handle) { %><span class="msg-handle">→ <%= n.to_handle %></span><% } %>
48 <% } else { %>
49 <a class="msg-who" href="<%= n.url %>" target="_blank" rel="nofollow noopener"><%= _who %></a>
50 <% if (n.handle && n.name) { %><span class="msg-handle"><%= n.handle %></span><% } %>
51 <% } %>
52 <% if (_new) { %><span class="msg-new" title="<%= t('msg.new') %>"></span><% } %>
53 <% if (n.created_at) { %><span class="msg-time"><%= formatDateTime(n.created_at) %></span><% } %>
54 </div>
55
56 <div class="msg-what">
57 <% if (n.count && n.count > 1) { %>
58 <strong><%= t('msg.and_more', { n: n.count - 1 }) %></strong>
59 <%= _t === 'like' ? t('msg.liked_many') : t('msg.boosted_many') %>
60 <% } else if (_t === 'follow') { %><%= t('notif.followed') %>
61 <% } else if (_t === 'like') { %><%= t('notif.liked') %>
62 <% } else if (_t === 'boost') { %><%= t('notif.boosted') %>
63 <% } else if (_t === 'report') { %><%= t('notif.reported') %>
64 <% } else if (_t === 'mention') { %><%= t('notif.mentioned') %>
65 <% } else if (_t === 'sent') { %><%= t('msg.sent_reply') %>
66 <% } else { %><%= t('notif.replied') %><% } %>
67 <% if (_priv) { %><span class="msg-priv" title="<%= t('msg.private_hint') %>">🔒 <%= t('msg.private') %></span><% } %>
68 <% if (n.post_slug) { %><a class="msg-post" href="/<%= n.post_slug %>"><%= n.post_title || n.post_slug %></a><% } %>
69 <% if (_t === 'mention' && n.note_url) { %><a class="msg-post" href="<%= n.note_url %>" target="_blank" rel="nofollow noopener"><%= t('tl.view_original') %></a><% } %>
70 <% if (_t === 'sent' && n.in_reply_to) { %><a class="msg-post" href="<%= n.in_reply_to %>" target="_blank" rel="nofollow noopener"><%= t('tl.view_original') %></a><% } %>
71 </div>
72
73 <% if (_t === 'report' && n.content) { %><div class="msg-content"><%= n.content %></div>
74 <% } else if ((_t === 'reply' || _t === 'mention' || _t === 'sent') && n.content) { %><div class="msg-content"><%- n.content %></div><% } %>
75
76 <% if (_t === 'sent' && n.outboxId) { %>
77 <div class="msg-actions">
78 <details class="msg-edit">
79 <summary><%= t('fedi.edit') %></summary>
[5190152]80 <div class="msg-edit-form">
81 <%- include('../partials/reply-editor', {
82 action: '/fediverse/' + n.outboxId + '/edit',
83 placeholder: t('fedi.reply_ph'),
84 submitLabel: t('fedi.save_edit'),
85 rows: 2,
86 initialHtml: n.content,
87 initialText: n.editable,
88 defaultLang: n.language,
89 noAttach: true,
90 }) %>
91 </div>
[f1a23b8]92 </details>
93 <form method="post" action="/fediverse/<%= n.outboxId %>/delete" data-confirm="<%= t('fedi.delete_confirm') %>">
94 <button type="submit" class="msg-del"><%= t('comments.delete') %></button>
95 </form>
96 </div>
97 <% } %>
98 </div>
99 </li>
100 <% }); %>
101 </ul>
102 <% } %>
103
104 <%# Interact bookmarklet — moved here from the old Reacties page. %>
105 <details class="msg-bm">
106 <summary><%= t('fedi.bm_label') %></summary>
107 <p class="msg-bm-help"><%= t('fedi.bm_help') %></p>
108 <a class="fedi-bm-btn" id="fedi-bm-btn" href="#" draggable="true" title="<%= t('fedi.bm_help') %>">
109 <svg viewBox="0 0 24 24" width="15" height="15" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><path d="M19 21l-7-5-7 5V5a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2z"/></svg>
110 <%= t('fedi.bm_label') %>
111 </a>
112 </details>
113</div>
114
115<script>
116(function () {
117 if (window.__msgWired) return; window.__msgWired = true;
118 document.addEventListener('click', function (e) {
119 var chip = e.target.closest('.msg-chip'); if (!chip) return;
120 var list = document.querySelector('.msg-list'); if (!list) return;
121 list.setAttribute('data-show', chip.getAttribute('data-show'));
122 document.querySelectorAll('.msg-chip').forEach(function (c) { c.classList.toggle('is-on', c === chip); });
123 });
124 var a = document.getElementById('fedi-bm-btn');
125 if (a) {
126 a.setAttribute('href', "javascript:void(window.open('" + location.origin + "/authorize_interaction?uri='+encodeURIComponent(window.location.href)))");
127 a.addEventListener('click', function (e) { e.preventDefault(); a.classList.add('nudge'); setTimeout(function(){ a.classList.remove('nudge'); }, 600); });
128 }
129})();
130</script>
131
132<style>
133 .msg-wrap { max-width: 640px; margin: 1rem auto; padding: 0 1rem; }
134 .msg-title { margin: 0 0 .9rem; }
135 .msg-empty { color: var(--ink-soft, #888); }
136
137 .msg-filters { display: flex; gap: .4rem; margin: 0 0 1.1rem; flex-wrap: wrap; }
138 .msg-chip { border: 1px solid color-mix(in srgb, var(--ink, #000) 16%, transparent); background: none;
139 color: var(--ink-soft, #888); font: inherit; font-size: .84rem; font-weight: 600;
140 padding: .3rem .85rem; border-radius: 999px; cursor: pointer; }
141 .msg-chip.is-on { background: var(--accent, #06c); border-color: var(--accent, #06c); color: #fff; }
142
143 .msg-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .55rem; }
144 .msg-list[data-show="conv"] li:not([data-kind="conv"]) { display: none; }
145 .msg-list[data-show="act"] li:not([data-kind="act"]) { display: none; }
146 .msg-list[data-show="sent"] li:not([data-kind="sent"]) { display: none; }
147
148 .msg-item { display: flex; gap: .8rem; padding: .85rem .95rem; border-radius: 14px; align-items: flex-start;
149 background: color-mix(in srgb, var(--ink, #000) 3.5%, transparent);
150 border: 1px solid color-mix(in srgb, var(--ink, #000) 9%, transparent);
151 transition: border-color .15s ease, box-shadow .15s ease; }
152 .msg-item:hover { border-color: color-mix(in srgb, var(--accent, #888) 30%, transparent);
153 box-shadow: 0 2px 12px color-mix(in srgb, var(--ink, #000) 6%, transparent); }
154 .msg-item.is-new { border-color: color-mix(in srgb, var(--accent, #06c) 45%, transparent);
155 background: color-mix(in srgb, var(--accent, #06c) 4%, transparent); }
156 .msg-sent { border-left: 3px solid color-mix(in srgb, var(--accent, #06c) 55%, transparent); }
157
158 .msg-av { position: relative; flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
159 display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
160 background: color-mix(in srgb, var(--accent, #888) 16%, transparent); color: var(--accent, #06c); overflow: visible; }
161 .msg-av img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; background: #fff; }
162 .msg-av-sent svg { width: 17px; height: 17px; }
163 .msg-dot { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%;
164 display: inline-flex; align-items: center; justify-content: center;
165 border: 2px solid var(--paper, #fff); background: var(--accent, #06c); color: #fff; }
166 .msg-dot svg { width: 10px; height: 10px; }
167 .msg-dot-like { background: #e8b04b; } .msg-dot-boost { background: #2fa85a; }
168 .msg-dot-report { background: #c0392b; } .msg-dot-mention { background: #8e6cf0; }
169
170 .msg-body { flex: 1; min-width: 0; }
171 .msg-line { display: flex; align-items: baseline; gap: .4rem; }
172 .msg-who { font-weight: 700; color: var(--ink, inherit); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
173 a.msg-who:hover { text-decoration: underline; }
174 .msg-handle { color: var(--ink-soft, #888); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
175 .msg-new { width: 8px; height: 8px; border-radius: 50%; background: var(--accent, #06c); flex: 0 0 auto; align-self: center; }
176 .msg-time { color: var(--ink-soft, #999); font-size: .76rem; margin-left: auto; flex: 0 0 auto; white-space: nowrap; }
177 .msg-what { color: var(--ink-soft, #aaa); margin-top: .12rem; line-height: 1.4; }
178 .msg-what .msg-post { color: var(--accent, #06c); font-weight: 600; margin-left: .25rem; }
179 .msg-priv { display: inline-block; margin-left: .3rem; padding: .05rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700;
180 background: color-mix(in srgb, #8e6cf0 14%, transparent); color: #8e6cf0; }
181 .msg-content { margin: .45rem 0 0; padding: .55rem .75rem; border-radius: 10px; line-height: 1.5;
182 background: color-mix(in srgb, var(--ink, #000) 4%, transparent); color: var(--ink, inherit); overflow-wrap: anywhere; }
183 .msg-content p { margin: .2rem 0; } .msg-content p:first-child { margin-top: 0; } .msg-content p:last-child { margin-bottom: 0; }
184
185 .msg-actions { display: flex; gap: .7rem; align-items: center; margin-top: .45rem; }
186 .msg-edit summary { cursor: pointer; font-size: .8rem; color: var(--ink-soft, #888); font-weight: 600; }
187 .msg-edit-form { margin-top: .4rem; display: flex; flex-direction: column; gap: .4rem; }
188 .msg-edit-form textarea { width: 100%; font: inherit; padding: .5rem .65rem; border-radius: 8px;
189 border: 1px solid color-mix(in srgb, var(--ink, #000) 16%, transparent); background: transparent; color: var(--ink, inherit); }
190 .msg-del { background: none; border: none; padding: 0; font: inherit; font-size: .8rem; font-weight: 600;
191 color: var(--ink-soft, #888); cursor: pointer; }
192 .msg-del:hover { color: #c0392b; }
193
194 .msg-bm { margin: 1.4rem 0 0; border-top: 1px solid color-mix(in srgb, var(--ink, #000) 10%, transparent); padding-top: .8rem; }
195 .msg-bm summary { cursor: pointer; color: var(--ink-soft, #888); font-weight: 600; font-size: .88rem; }
196 .msg-bm-help { color: var(--ink-soft, #888); font-size: .82rem; line-height: 1.5; margin: .5rem 0 .6rem; }
197</style>
Note: See TracBrowser for help on using the repository browser.