| 1 | <div class="prutter-conv-page" data-conversation-id="<%= conversation.id %>" data-me="<%= user.id %>">
|
|---|
| 2 | <header class="prutter-conv-header">
|
|---|
| 3 | <a class="prutter-back" href="<%= siteUrlBase %>/prutter" aria-label="Terug naar inbox" title="Inbox">
|
|---|
| 4 | <svg viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" aria-hidden="true"><line x1="19" y1="12" x2="5" y2="12"/><polyline points="12 19 5 12 12 5"/></svg>
|
|---|
| 5 | </a>
|
|---|
| 6 | <div class="prutter-conv-avatar">
|
|---|
| 7 | <% if (other && other.avatar_url) { %>
|
|---|
| 8 | <img src="<%= other.avatar_url %>" alt="">
|
|---|
| 9 | <% } else { %>
|
|---|
| 10 | <span><%= (other && other.username || '?').charAt(0).toUpperCase() %></span>
|
|---|
| 11 | <% } %>
|
|---|
| 12 | </div>
|
|---|
| 13 | <div class="prutter-conv-id">
|
|---|
| 14 | <span class="prutter-conv-name"><%= other ? other.username : 'Onbekend' %></span>
|
|---|
| 15 | <% if (other) { %>
|
|---|
| 16 | <a class="prutter-conv-sub" href="/users/<%= encodeURIComponent(other.username) %>">Bekijk profiel</a>
|
|---|
| 17 | <% } %>
|
|---|
| 18 | </div>
|
|---|
| 19 | </header>
|
|---|
| 20 |
|
|---|
| 21 | <ol class="prutter-thread" id="prutter-thread">
|
|---|
| 22 | <% messages.forEach(function(m) { %>
|
|---|
| 23 | <li class="prutter-msg <%= m.author_id === user.id ? 'prutter-msg--mine' : 'prutter-msg--theirs' %>" data-msg-id="<%= m.id %>">
|
|---|
| 24 | <div class="prutter-msg-bubble"><%= m.content %></div>
|
|---|
| 25 | <div class="prutter-msg-time" title="<%= m.created_at %>"><%= formatDateTime(m.created_at) %></div>
|
|---|
| 26 | </li>
|
|---|
| 27 | <% }); %>
|
|---|
| 28 | </ol>
|
|---|
| 29 |
|
|---|
| 30 | <form class="prutter-composer"
|
|---|
| 31 | method="post"
|
|---|
| 32 | action="<%= siteUrlBase %>/prutter/<%= conversation.id %>/send"
|
|---|
| 33 | hx-post="<%= siteUrlBase %>/prutter/<%= conversation.id %>/send"
|
|---|
| 34 | hx-target="#prutter-thread"
|
|---|
| 35 | hx-swap="beforeend"
|
|---|
| 36 | hx-on::after-request="this.querySelector('textarea').value=''; window.__prutterScroll && window.__prutterScroll();">
|
|---|
| 37 | <textarea name="content" rows="1" maxlength="2000" placeholder="Bericht…" required></textarea>
|
|---|
| 38 | <button type="submit" class="btn btn-primary">Stuur</button>
|
|---|
| 39 | </form>
|
|---|
| 40 | </div>
|
|---|
| 41 |
|
|---|
| 42 | <script>
|
|---|
| 43 | (function() {
|
|---|
| 44 | // Auto-scroll to bottom on load and after appends.
|
|---|
| 45 | var thread = document.getElementById('prutter-thread');
|
|---|
| 46 | function scrollToBottom() { thread.scrollTop = thread.scrollHeight; }
|
|---|
| 47 | scrollToBottom();
|
|---|
| 48 | window.__prutterScroll = scrollToBottom;
|
|---|
| 49 |
|
|---|
| 50 | // Live updates via WebSocket.
|
|---|
| 51 | // Browser auto-resolves protocol/host; same origin as the page.
|
|---|
| 52 | try {
|
|---|
| 53 | var page = document.querySelector('.prutter-conv-page');
|
|---|
| 54 | var convId = page.dataset.conversationId;
|
|---|
| 55 | var me = page.dataset.me;
|
|---|
| 56 | var proto = location.protocol === 'https:' ? 'wss:' : 'ws:';
|
|---|
| 57 | var ws = new WebSocket(proto + '//' + location.host + '/ws/prutter');
|
|---|
| 58 |
|
|---|
| 59 | ws.addEventListener('message', function(ev) {
|
|---|
| 60 | try {
|
|---|
| 61 | var data = JSON.parse(ev.data);
|
|---|
| 62 | if (data.type !== 'new_message' || data.conversationId !== convId) return;
|
|---|
| 63 | var m = data.message;
|
|---|
| 64 | // Don't double-render our own messages (already added via HTMX response)
|
|---|
| 65 | if (m.author_id === me) return;
|
|---|
| 66 |
|
|---|
| 67 | var li = document.createElement('li');
|
|---|
| 68 | li.className = 'prutter-msg prutter-msg--theirs';
|
|---|
| 69 | li.dataset.msgId = m.id;
|
|---|
| 70 | var bubble = document.createElement('div');
|
|---|
| 71 | bubble.className = 'prutter-msg-bubble';
|
|---|
| 72 | bubble.textContent = m.content; // text content = automatic escaping
|
|---|
| 73 | var time = document.createElement('div');
|
|---|
| 74 | time.className = 'prutter-msg-time';
|
|---|
| 75 | time.textContent = new Date(m.created_at).toLocaleString();
|
|---|
| 76 | li.appendChild(bubble);
|
|---|
| 77 | li.appendChild(time);
|
|---|
| 78 | thread.appendChild(li);
|
|---|
| 79 | scrollToBottom();
|
|---|
| 80 | } catch (e) { /* ignore malformed */ }
|
|---|
| 81 | });
|
|---|
| 82 | } catch (e) {
|
|---|
| 83 | console.warn('Prutter WS unavailable:', e);
|
|---|
| 84 | }
|
|---|
| 85 | })();
|
|---|
| 86 | </script>
|
|---|
| 87 |
|
|---|
| 88 | <style>
|
|---|
| 89 | /* De chat is position:fixed (los uit de flow) → de site-footer (met copyright,
|
|---|
| 90 | versie én de "Installeer app"-knop) schemerde erdoorheen in het lege
|
|---|
| 91 | berichtgebied. In de chat hoort die footer niet thuis: verbergen. */
|
|---|
| 92 | body:has(.prutter-conv-page) .site-footer { display: none; }
|
|---|
| 93 |
|
|---|
| 94 | /* ── Full-height chat-layout (mobile-first) ──────────────────────────────
|
|---|
| 95 | De pagina is FIXED gepind tussen de topnav (desktop) en de onderste balken
|
|---|
| 96 | (bottom-tab + audiospeler), zodat ALLEEN de thread scrollt — niet de hele
|
|---|
| 97 | pagina. De offsets volgen de body-classes has-bottom-tab/has-audio-player,
|
|---|
| 98 | dus de composer valt nooit achter een balk. */
|
|---|
| 99 | .prutter-conv-page {
|
|---|
| 100 | position: fixed;
|
|---|
| 101 | left: 0; right: 0;
|
|---|
| 102 | top: 0; /* mobiel: masthead is verborgen → vanaf de top */
|
|---|
| 103 | bottom: 0;
|
|---|
| 104 | max-width: 760px; margin: 0 auto;
|
|---|
| 105 | display: flex; flex-direction: column;
|
|---|
| 106 | padding: 0.5rem 0.75rem;
|
|---|
| 107 | z-index: 1;
|
|---|
| 108 | }
|
|---|
| 109 | /* Desktop: de sticky masthead staat erboven → begin eronder. */
|
|---|
| 110 | @media (min-width: 768px) {
|
|---|
| 111 | .prutter-conv-page { top: 64px; padding: 0.75rem 1rem; }
|
|---|
| 112 | }
|
|---|
| 113 | /* Onderste vrije ruimte = de balken die de viewport-bodem overlappen. */
|
|---|
| 114 | @media (max-width: 767px) {
|
|---|
| 115 | body.has-bottom-tab .prutter-conv-page { bottom: calc(56px + env(safe-area-inset-bottom, 0)); }
|
|---|
| 116 | }
|
|---|
| 117 | body.has-audio-player .prutter-conv-page { bottom: calc(76px + env(safe-area-inset-bottom, 0)); }
|
|---|
| 118 | @media (max-width: 767px) {
|
|---|
| 119 | body.has-bottom-tab.has-audio-player .prutter-conv-page { bottom: calc(56px + 76px + env(safe-area-inset-bottom, 0)); }
|
|---|
| 120 | }
|
|---|
| 121 |
|
|---|
| 122 | /* Compacte chat-kop: terug-pijl + avatar + naam op één regel. */
|
|---|
| 123 | .prutter-conv-header {
|
|---|
| 124 | flex: 0 0 auto;
|
|---|
| 125 | display: flex; align-items: center; gap: 0.65rem;
|
|---|
| 126 | padding-bottom: 0.6rem; margin-bottom: 0.5rem;
|
|---|
| 127 | border-bottom: 1px solid var(--rule);
|
|---|
| 128 | }
|
|---|
| 129 | .prutter-back {
|
|---|
| 130 | flex: 0 0 auto;
|
|---|
| 131 | display: inline-flex; align-items: center; justify-content: center;
|
|---|
| 132 | width: 40px; height: 40px; border-radius: 8px;
|
|---|
| 133 | color: var(--ink); text-decoration: none;
|
|---|
| 134 | }
|
|---|
| 135 | .prutter-back:hover { color: var(--accent); background: var(--paper-2); }
|
|---|
| 136 | .prutter-back svg { width: 20px; height: 20px; }
|
|---|
| 137 | .prutter-conv-avatar {
|
|---|
| 138 | flex: 0 0 auto;
|
|---|
| 139 | width: 40px; height: 40px; border-radius: 50%;
|
|---|
| 140 | overflow: hidden; background: var(--paper-2);
|
|---|
| 141 | display: inline-flex; align-items: center; justify-content: center;
|
|---|
| 142 | color: var(--accent); font-weight: 700;
|
|---|
| 143 | }
|
|---|
| 144 | .prutter-conv-avatar img { width: 100%; height: 100%; object-fit: cover; }
|
|---|
| 145 | .prutter-conv-id { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
|
|---|
| 146 | .prutter-conv-name {
|
|---|
| 147 | font-family: var(--font-display, serif); font-size: 1.15rem; color: var(--ink);
|
|---|
| 148 | white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
|
|---|
| 149 | }
|
|---|
| 150 | .prutter-conv-sub { font-size: 0.78rem; color: var(--ink-muted, var(--ink-soft)); text-decoration: none; }
|
|---|
| 151 | .prutter-conv-sub:hover { color: var(--accent); }
|
|---|
| 152 |
|
|---|
| 153 | /* De ENIGE scroller. min-height:0 is cruciaal in een flex-kolom, anders
|
|---|
| 154 | groeit de lijst i.p.v. te scrollen. */
|
|---|
| 155 | .prutter-thread {
|
|---|
| 156 | flex: 1 1 auto; min-height: 0;
|
|---|
| 157 | list-style: none; margin: 0;
|
|---|
| 158 | display: flex; flex-direction: column; gap: 0.4rem;
|
|---|
| 159 | padding: 0.25rem 0.1rem 0.5rem;
|
|---|
| 160 | overflow-y: auto; overscroll-behavior: contain;
|
|---|
| 161 | -webkit-overflow-scrolling: touch;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | .prutter-msg { display: flex; flex-direction: column; max-width: 82%; }
|
|---|
| 165 | .prutter-msg-bubble {
|
|---|
| 166 | padding: 0.55rem 0.85rem;
|
|---|
| 167 | border-radius: 14px;
|
|---|
| 168 | white-space: pre-wrap;
|
|---|
| 169 | word-wrap: break-word;
|
|---|
| 170 | line-height: 1.4;
|
|---|
| 171 | font-size: 0.95rem;
|
|---|
| 172 | }
|
|---|
| 173 | .prutter-msg-time {
|
|---|
| 174 | font-size: 0.7rem;
|
|---|
| 175 | color: var(--ink-muted, var(--ink-soft));
|
|---|
| 176 | margin-top: 0.15rem;
|
|---|
| 177 | }
|
|---|
| 178 |
|
|---|
| 179 | .prutter-msg--theirs { align-self: flex-start; }
|
|---|
| 180 | .prutter-msg--theirs .prutter-msg-bubble {
|
|---|
| 181 | background: var(--paper);
|
|---|
| 182 | border: 1px solid var(--rule);
|
|---|
| 183 | border-bottom-left-radius: 4px;
|
|---|
| 184 | }
|
|---|
| 185 | .prutter-msg--theirs .prutter-msg-time { padding-left: 0.5rem; }
|
|---|
| 186 |
|
|---|
| 187 | .prutter-msg--mine { align-self: flex-end; align-items: flex-end; }
|
|---|
| 188 | .prutter-msg--mine .prutter-msg-bubble {
|
|---|
| 189 | background: var(--accent);
|
|---|
| 190 | color: white;
|
|---|
| 191 | border-bottom-right-radius: 4px;
|
|---|
| 192 | }
|
|---|
| 193 | .prutter-msg--mine .prutter-msg-time { padding-right: 0.5rem; }
|
|---|
| 194 |
|
|---|
| 195 | .prutter-composer {
|
|---|
| 196 | flex: 0 0 auto;
|
|---|
| 197 | display: flex; gap: 0.5rem; align-items: flex-end;
|
|---|
| 198 | padding-top: 0.6rem; margin-top: 0.25rem;
|
|---|
| 199 | border-top: 1px solid var(--rule);
|
|---|
| 200 | }
|
|---|
| 201 | .prutter-composer textarea {
|
|---|
| 202 | flex: 1;
|
|---|
| 203 | padding: 0.65rem 0.85rem;
|
|---|
| 204 | border: 1px solid var(--rule);
|
|---|
| 205 | border-radius: 12px;
|
|---|
| 206 | background: var(--paper);
|
|---|
| 207 | color: var(--ink);
|
|---|
| 208 | font-family: inherit;
|
|---|
| 209 | font-size: 1rem; /* ≥16px → iOS zoomt niet in bij focus */
|
|---|
| 210 | line-height: 1.35;
|
|---|
| 211 | resize: none;
|
|---|
| 212 | min-height: 44px; max-height: 40vh;
|
|---|
| 213 | }
|
|---|
| 214 | .prutter-composer .btn { flex: 0 0 auto; min-height: 44px; }
|
|---|
| 215 | </style>
|
|---|