source: Klonkt/src/views/pages/messages.ejs@ 8ed65a6

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

Feature: Messages filters regrouped + search (klonkt-demo-3jf)

The four coarse chips become meaningful buckets and gain a search box.

  • Buckets: Messages (@mentions + private/DM replies), Conversations (public replies), Activity (likes/boosts/follows), Moderation (reports), Sent, All. data-kind is computed from the item type and visibility (a followers/direct reply now lands under Messages, not Conversations).
  • Search box filters by sender + rendered message text + linked post title, indexed once per item; chip and search combine in JS (an item shows only when both match). A 'nothing found' line appears when the result set is empty.
  • Filtering moved from the old CSS data-show rules to JS so search can layer on; the search field matches the framed style used elsewhere.
  • i18n NL/EN/DE for the two new chips, the placeholder and the empty line.

97 tests green (view-only change). Browser-verified: DM + mention under
Messages (2), report under Moderation (1), public reply under Conversations (1);
search 'geheime dm' -> the DM only; a no-hit term -> empty with the message;
Messages chip + a Conversations-only term -> 0.

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

  • Property mode set to 100644
File size: 16.8 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>
[8ed65a6]9 <button type="button" class="msg-chip" data-show="msgs"><%= t('msg.filter_msgs') %></button>
[f1a23b8]10 <button type="button" class="msg-chip" data-show="conv"><%= t('msg.filter_conv') %></button>
11 <button type="button" class="msg-chip" data-show="act"><%= t('msg.filter_act') %></button>
[8ed65a6]12 <button type="button" class="msg-chip" data-show="mod"><%= t('msg.filter_mod') %></button>
[f1a23b8]13 <button type="button" class="msg-chip" data-show="sent"><%= t('msg.filter_sent') %></button>
14 </div>
[8ed65a6]15 <div class="msg-search">
16 <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><circle cx="11" cy="11" r="8"/><line x1="21" y1="21" x2="16.65" y2="16.65"/></svg>
17 <input type="search" id="msg-q" placeholder="<%= t('msg.search_ph') %>" autocomplete="off" spellcheck="false" aria-label="<%= t('msg.search_ph') %>">
18 </div>
[f1a23b8]19
20 <% var _seen = (typeof seenAt !== 'undefined' && seenAt) ? seenAt : 0; %>
21 <% if (!items || !items.length) { %>
22 <p class="msg-empty"><%= t('msg.empty') %></p>
23 <% } else { %>
24 <ul class="msg-list" data-show="all">
25 <% items.forEach(function(n){
26 var _t = n.type === 'announce' ? 'boost' : n.type; // reply|mention|report|like|boost|follow|sent
27 var _new = _seen && n.created_at ? (Date.parse(n.created_at) > _seen) : false;
28 var _who = n.name || n.handle || '';
[8ed65a6]29 var _priv0 = (n.visibility === 'followers' || n.visibility === 'direct');
30 // Buckets (klonkt-demo-3jf): Messages = @mentions + private (DM) replies;
31 // Activity = likes/boosts/follows; Moderation = reports; Sent = your
32 // replies; Conversations = every other (public) reply.
33 var _kind = _t === 'sent' ? 'sent'
34 : (_t === 'like' || _t === 'boost' || _t === 'follow') ? 'act'
35 : _t === 'report' ? 'mod'
36 : (_t === 'mention' || _priv0) ? 'msgs'
37 : 'conv';
[f1a23b8]38 var _init = String(_who || '?').replace(/^@/, '').charAt(0).toUpperCase();
39 var _priv = (n.visibility === 'followers' || n.visibility === 'direct');
40 %>
[8ed65a6]41 <li class="msg-item msg-<%= _t %><%= _new ? ' is-new' : '' %>" data-kind="<%= _kind %>" data-who="<%= String(_who).toLowerCase() %>">
[f1a23b8]42 <span class="msg-av<%= _t === 'sent' ? ' msg-av-sent' : '' %>" aria-hidden="true">
43 <% 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>
44 <% } else if (n.icon) { %><img src="<%= avatar(n.icon, 96) %>" alt="" loading="lazy">
45 <% } else { %><%= _init %><% } %>
46 <span class="msg-dot msg-dot-<%= _t %>">
47 <% 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>
48 <% } 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>
49 <% } 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>
50 <% } 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>
51 <% } 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>
52 <% } 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>
53 <% } 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><% } %>
54 </span>
55 </span>
56
57 <div class="msg-body">
58 <div class="msg-line">
59 <% if (_t === 'sent') { %>
60 <span class="msg-who"><%= t('msg.you') %></span>
61 <% if (n.to_handle) { %><span class="msg-handle">→ <%= n.to_handle %></span><% } %>
62 <% } else { %>
63 <a class="msg-who" href="<%= n.url %>" target="_blank" rel="nofollow noopener"><%= _who %></a>
64 <% if (n.handle && n.name) { %><span class="msg-handle"><%= n.handle %></span><% } %>
65 <% } %>
66 <% if (_new) { %><span class="msg-new" title="<%= t('msg.new') %>"></span><% } %>
67 <% if (n.created_at) { %><span class="msg-time"><%= formatDateTime(n.created_at) %></span><% } %>
68 </div>
69
70 <div class="msg-what">
71 <% if (n.count && n.count > 1) { %>
72 <strong><%= t('msg.and_more', { n: n.count - 1 }) %></strong>
73 <%= _t === 'like' ? t('msg.liked_many') : t('msg.boosted_many') %>
74 <% } else if (_t === 'follow') { %><%= t('notif.followed') %>
75 <% } else if (_t === 'like') { %><%= t('notif.liked') %>
76 <% } else if (_t === 'boost') { %><%= t('notif.boosted') %>
77 <% } else if (_t === 'report') { %><%= t('notif.reported') %>
78 <% } else if (_t === 'mention') { %><%= t('notif.mentioned') %>
79 <% } else if (_t === 'sent') { %><%= t('msg.sent_reply') %>
80 <% } else { %><%= t('notif.replied') %><% } %>
81 <% if (_priv) { %><span class="msg-priv" title="<%= t('msg.private_hint') %>">🔒 <%= t('msg.private') %></span><% } %>
82 <% if (n.post_slug) { %><a class="msg-post" href="/<%= n.post_slug %>"><%= n.post_title || n.post_slug %></a><% } %>
83 <% if (_t === 'mention' && n.note_url) { %><a class="msg-post" href="<%= n.note_url %>" target="_blank" rel="nofollow noopener"><%= t('tl.view_original') %></a><% } %>
84 <% 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><% } %>
85 </div>
86
87 <% if (_t === 'report' && n.content) { %><div class="msg-content"><%= n.content %></div>
88 <% } else if ((_t === 'reply' || _t === 'mention' || _t === 'sent') && n.content) { %><div class="msg-content"><%- n.content %></div><% } %>
89
90 <% if (_t === 'sent' && n.outboxId) { %>
91 <div class="msg-actions">
92 <details class="msg-edit">
93 <summary><%= t('fedi.edit') %></summary>
[5190152]94 <div class="msg-edit-form">
95 <%- include('../partials/reply-editor', {
96 action: '/fediverse/' + n.outboxId + '/edit',
97 placeholder: t('fedi.reply_ph'),
98 submitLabel: t('fedi.save_edit'),
99 rows: 2,
100 initialHtml: n.content,
101 initialText: n.editable,
102 defaultLang: n.language,
103 noAttach: true,
104 }) %>
105 </div>
[f1a23b8]106 </details>
107 <form method="post" action="/fediverse/<%= n.outboxId %>/delete" data-confirm="<%= t('fedi.delete_confirm') %>">
108 <button type="submit" class="msg-del"><%= t('comments.delete') %></button>
109 </form>
110 </div>
111 <% } %>
112 </div>
113 </li>
114 <% }); %>
115 </ul>
[8ed65a6]116 <p class="msg-nomatch" hidden><%= t('msg.no_match') %></p>
[f1a23b8]117 <% } %>
118
119 <%# Interact bookmarklet — moved here from the old Reacties page. %>
120 <details class="msg-bm">
121 <summary><%= t('fedi.bm_label') %></summary>
122 <p class="msg-bm-help"><%= t('fedi.bm_help') %></p>
123 <a class="fedi-bm-btn" id="fedi-bm-btn" href="#" draggable="true" title="<%= t('fedi.bm_help') %>">
124 <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>
125 <%= t('fedi.bm_label') %>
126 </a>
127 </details>
128</div>
129
130<script>
131(function () {
132 if (window.__msgWired) return; window.__msgWired = true;
[8ed65a6]133
134 // Filtering: kind chip AND free-text search, combined in JS (search over the
135 // sender and the rendered message text). Empty search + "all" = show all.
136 var list = document.querySelector('.msg-list');
137 var noMatch = document.querySelector('.msg-nomatch');
138 var q = document.getElementById('msg-q');
139 var kind = 'all';
140 var items = list ? Array.prototype.slice.call(list.querySelectorAll('.msg-item')) : [];
141 items.forEach(function (li) {
142 // Index once: sender + message body + linked post title.
143 var body = li.querySelector('.msg-content');
144 var post = li.querySelector('.msg-post');
145 li._search = ((li.getAttribute('data-who') || '') + ' ' +
146 (body ? body.textContent : '') + ' ' + (post ? post.textContent : '')).toLowerCase();
147 });
148 function apply() {
149 if (!list) return;
150 var term = (q && q.value || '').trim().toLowerCase();
151 var shown = 0;
152 items.forEach(function (li) {
153 var ok = (kind === 'all' || li.getAttribute('data-kind') === kind) &&
154 (!term || li._search.indexOf(term) !== -1);
155 li.style.display = ok ? '' : 'none';
156 if (ok) shown++;
157 });
158 if (noMatch) noMatch.hidden = shown !== 0;
159 }
[f1a23b8]160 document.addEventListener('click', function (e) {
161 var chip = e.target.closest('.msg-chip'); if (!chip) return;
[8ed65a6]162 kind = chip.getAttribute('data-show');
[f1a23b8]163 document.querySelectorAll('.msg-chip').forEach(function (c) { c.classList.toggle('is-on', c === chip); });
[8ed65a6]164 apply();
[f1a23b8]165 });
[8ed65a6]166 if (q) q.addEventListener('input', apply);
167
[f1a23b8]168 var a = document.getElementById('fedi-bm-btn');
169 if (a) {
170 a.setAttribute('href', "javascript:void(window.open('" + location.origin + "/authorize_interaction?uri='+encodeURIComponent(window.location.href)))");
171 a.addEventListener('click', function (e) { e.preventDefault(); a.classList.add('nudge'); setTimeout(function(){ a.classList.remove('nudge'); }, 600); });
172 }
173})();
174</script>
175
176<style>
177 .msg-wrap { max-width: 640px; margin: 1rem auto; padding: 0 1rem; }
178 .msg-title { margin: 0 0 .9rem; }
179 .msg-empty { color: var(--ink-soft, #888); }
180
181 .msg-filters { display: flex; gap: .4rem; margin: 0 0 1.1rem; flex-wrap: wrap; }
182 .msg-chip { border: 1px solid color-mix(in srgb, var(--ink, #000) 16%, transparent); background: none;
183 color: var(--ink-soft, #888); font: inherit; font-size: .84rem; font-weight: 600;
184 padding: .3rem .85rem; border-radius: 999px; cursor: pointer; }
185 .msg-chip.is-on { background: var(--accent, #06c); border-color: var(--accent, #06c); color: #fff; }
186
[8ed65a6]187 .msg-search { display: flex; align-items: center; gap: .5rem; margin: 0 0 1.1rem;
188 padding: .45rem .7rem; border-radius: 10px;
189 border: 1px solid color-mix(in srgb, var(--ink, #000) 16%, transparent); }
190 .msg-search:focus-within { border-color: var(--accent, #06c); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent, #06c) 18%, transparent); }
191 .msg-search svg { width: 16px; height: 16px; color: var(--ink-soft, #888); flex-shrink: 0; }
192 .msg-search input { flex: 1; border: none; background: none; color: inherit; font: inherit; outline: none; min-width: 0; }
193 .msg-nomatch { color: var(--ink-soft, #888); text-align: center; padding: 1.2rem 0; }
194
[f1a23b8]195 .msg-list { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: .55rem; }
196
197 .msg-item { display: flex; gap: .8rem; padding: .85rem .95rem; border-radius: 14px; align-items: flex-start;
198 background: color-mix(in srgb, var(--ink, #000) 3.5%, transparent);
199 border: 1px solid color-mix(in srgb, var(--ink, #000) 9%, transparent);
200 transition: border-color .15s ease, box-shadow .15s ease; }
201 .msg-item:hover { border-color: color-mix(in srgb, var(--accent, #888) 30%, transparent);
202 box-shadow: 0 2px 12px color-mix(in srgb, var(--ink, #000) 6%, transparent); }
203 .msg-item.is-new { border-color: color-mix(in srgb, var(--accent, #06c) 45%, transparent);
204 background: color-mix(in srgb, var(--accent, #06c) 4%, transparent); }
205 .msg-sent { border-left: 3px solid color-mix(in srgb, var(--accent, #06c) 55%, transparent); }
206
207 .msg-av { position: relative; flex: 0 0 40px; width: 40px; height: 40px; border-radius: 50%;
208 display: inline-flex; align-items: center; justify-content: center; font-weight: 700;
209 background: color-mix(in srgb, var(--accent, #888) 16%, transparent); color: var(--accent, #06c); overflow: visible; }
210 .msg-av img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; background: #fff; }
211 .msg-av-sent svg { width: 17px; height: 17px; }
212 .msg-dot { position: absolute; right: -3px; bottom: -3px; width: 18px; height: 18px; border-radius: 50%;
213 display: inline-flex; align-items: center; justify-content: center;
214 border: 2px solid var(--paper, #fff); background: var(--accent, #06c); color: #fff; }
215 .msg-dot svg { width: 10px; height: 10px; }
216 .msg-dot-like { background: #e8b04b; } .msg-dot-boost { background: #2fa85a; }
217 .msg-dot-report { background: #c0392b; } .msg-dot-mention { background: #8e6cf0; }
218
219 .msg-body { flex: 1; min-width: 0; }
220 .msg-line { display: flex; align-items: baseline; gap: .4rem; }
221 .msg-who { font-weight: 700; color: var(--ink, inherit); text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
222 a.msg-who:hover { text-decoration: underline; }
223 .msg-handle { color: var(--ink-soft, #888); font-size: .82rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
224 .msg-new { width: 8px; height: 8px; border-radius: 50%; background: var(--accent, #06c); flex: 0 0 auto; align-self: center; }
225 .msg-time { color: var(--ink-soft, #999); font-size: .76rem; margin-left: auto; flex: 0 0 auto; white-space: nowrap; }
226 .msg-what { color: var(--ink-soft, #aaa); margin-top: .12rem; line-height: 1.4; }
227 .msg-what .msg-post { color: var(--accent, #06c); font-weight: 600; margin-left: .25rem; }
228 .msg-priv { display: inline-block; margin-left: .3rem; padding: .05rem .5rem; border-radius: 999px; font-size: .72rem; font-weight: 700;
229 background: color-mix(in srgb, #8e6cf0 14%, transparent); color: #8e6cf0; }
230 .msg-content { margin: .45rem 0 0; padding: .55rem .75rem; border-radius: 10px; line-height: 1.5;
231 background: color-mix(in srgb, var(--ink, #000) 4%, transparent); color: var(--ink, inherit); overflow-wrap: anywhere; }
232 .msg-content p { margin: .2rem 0; } .msg-content p:first-child { margin-top: 0; } .msg-content p:last-child { margin-bottom: 0; }
233
234 .msg-actions { display: flex; gap: .7rem; align-items: center; margin-top: .45rem; }
235 .msg-edit summary { cursor: pointer; font-size: .8rem; color: var(--ink-soft, #888); font-weight: 600; }
236 .msg-edit-form { margin-top: .4rem; display: flex; flex-direction: column; gap: .4rem; }
237 .msg-edit-form textarea { width: 100%; font: inherit; padding: .5rem .65rem; border-radius: 8px;
238 border: 1px solid color-mix(in srgb, var(--ink, #000) 16%, transparent); background: transparent; color: var(--ink, inherit); }
239 .msg-del { background: none; border: none; padding: 0; font: inherit; font-size: .8rem; font-weight: 600;
240 color: var(--ink-soft, #888); cursor: pointer; }
241 .msg-del:hover { color: #c0392b; }
242
243 .msg-bm { margin: 1.4rem 0 0; border-top: 1px solid color-mix(in srgb, var(--ink, #000) 10%, transparent); padding-top: .8rem; }
244 .msg-bm summary { cursor: pointer; color: var(--ink-soft, #888); font-weight: 600; font-size: .88rem; }
245 .msg-bm-help { color: var(--ink-soft, #888); font-size: .82rem; line-height: 1.5; margin: .5rem 0 .6rem; }
246</style>
Note: See TracBrowser for help on using the repository browser.