diff --git a/static/js/conversations.js b/static/js/conversations.js index af47203..d5fc442 100644 --- a/static/js/conversations.js +++ b/static/js/conversations.js @@ -3161,11 +3161,19 @@ } } - // If URL has ?new_to=, open new message modal with pre-selected recipient + // If URL has ?new_to=, open or create conversation with that user var newToParam = urlParams.get('new_to'); if (newToParam) { var targetUserId = parseInt(newToParam); if (targetUserId) { + // Build context message if coming from classified/B2B + var ctxType = urlParams.get('ctx'); + var ctxTitle = urlParams.get('ctx_title'); + var contextMessage = ''; + if (ctxType === 'classified' && ctxTitle) { + contextMessage = 'Hej, piszę w sprawie ogłoszenia na tablicy B2B: „' + decodeURIComponent(ctxTitle) + '"'; + } + // Check if conversation with this user already exists (1:1) var existingConv = state.conversations.find(function (c) { return !c.is_group && c.members && c.members.some(function (m) { @@ -3174,12 +3182,27 @@ }); if (existingConv) { ConversationList.selectConversation(existingConv.id); + // Pre-fill editor with context message + if (contextMessage) { + setTimeout(function () { + var editor = document.querySelector('#chatInput .ql-editor, #chatInput'); + if (editor) { + if (editor.classList && editor.classList.contains('ql-editor')) { + editor.innerHTML = '

' + contextMessage + '

'; + } else if (editor.value !== undefined) { + editor.value = contextMessage; + } + } + }, 800); + } } else { - // Open new message modal — create conversation via API, then open it + // Create conversation via API with optional first message + var payload = { member_ids: [targetUserId] }; + if (contextMessage) payload.message = contextMessage; fetch('/api/conversations', { method: 'POST', headers: { 'Content-Type': 'application/json', 'X-CSRFToken': window.__CSRF_TOKEN__ }, - body: JSON.stringify({ member_ids: [targetUserId] }) + body: JSON.stringify(payload) }).then(function (r) { return r.json(); }).then(function (data) { if (data.id) { window.location.href = '/wiadomosci?conv=' + data.id; diff --git a/templates/classifieds/view.html b/templates/classifieds/view.html index 60de527..60b5603 100755 --- a/templates/classifieds/view.html +++ b/templates/classifieds/view.html @@ -727,7 +727,7 @@ {% if user_interested %}Zainteresowany{% else %}Jestem zainteresowany{% endif %} - Skontaktuj sie + Skontaktuj sie {% endif %} diff --git a/templates/messages/conversations.html b/templates/messages/conversations.html index a715a18..48449b2 100644 --- a/templates/messages/conversations.html +++ b/templates/messages/conversations.html @@ -326,7 +326,7 @@ window.__CSRF_TOKEN__ = '{{ csrf_token() }}'; // Load conversations.js after data is set (function() { var s = document.createElement('script'); - s.src = '{{ url_for("static", filename="js/conversations.js") }}?v=26'; + s.src = '{{ url_for("static", filename="js/conversations.js") }}?v=27'; document.body.appendChild(s); })(); {% endblock %}