feat: B2B contact button auto-fills context message
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions

When clicking "Skontaktuj się" on a classified ad, the conversation
now starts with a pre-filled message: "Hej, piszę w sprawie ogłoszenia
na tablicy B2B: „<tytuł>"". If conversation already exists, the
context is pre-filled in the editor for the user to send.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Maciej Pienczyn 2026-04-09 23:35:08 +02:00
parent cf2fce35be
commit b81f80168e
3 changed files with 28 additions and 5 deletions

View File

@ -3161,11 +3161,19 @@
}
}
// If URL has ?new_to=<user_id>, open new message modal with pre-selected recipient
// If URL has ?new_to=<user_id>, 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 = '<p>' + contextMessage + '</p>';
} 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;

View File

@ -727,7 +727,7 @@
</svg>
<span id="interestBtnText">{% if user_interested %}Zainteresowany{% else %}Jestem zainteresowany{% endif %}</span>
</button>
<a href="{{ url_for('messages.conversations_page') }}?new_to={{ classified.author_id }}" class="btn btn-primary">Skontaktuj sie</a>
<a href="{{ url_for('messages.conversations_page') }}?new_to={{ classified.author_id }}&ctx=classified&ctx_title={{ classified.title|urlencode }}" class="btn btn-primary">Skontaktuj sie</a>
</div>
{% endif %}
</div>

View File

@ -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 %}