diff --git a/pagure/static/request_ev.js b/pagure/static/request_ev.js index 50d1e1e..062c5c6 100644 --- a/pagure/static/request_ev.js +++ b/pagure/static/request_ev.js @@ -113,6 +113,7 @@ update_comment = function(data) { field.find('.comment_body').html(data.comment_updated); field.find('.issue_actions').show(); field.find('.issue_comment').show(); + field.find('.edit_comment').remove(); } process_event = function(data, requestid, username){ diff --git a/pagure/templates/issue.html b/pagure/templates/issue.html index 666cae7..55f135d 100644 --- a/pagure/templates/issue.html +++ b/pagure/templates/issue.html @@ -936,7 +936,14 @@ function try_async_comment(form) { /* Keep some variable in memory before sending them in case the SSE is down */ var _url = form.action; + var _update = false; var _comment = $(form).find('#comment').val(); + var _comment_id = null; + if (!_comment && form.update_comment) { + _update = true; + _comment_id = $(form.edit_comment).val(); + _comment = $(form).find('#update_comment').val(); + } var _commit_id = null; var _line = null; var _token = "{{ form.csrf_token.current_token }}"; @@ -969,11 +976,21 @@ function try_async_comment(form) { dataType: 'html', success: function(res) { var _comment = emojione.toImage(res); - var data = { + if (_update) { + var data = { + comment_updated: _comment, + comment_user: "{{ g.fas_user.username }}", + comment_date: Date.now(), + comment_id: _comment_id, + avatar_url: "{{ g.fas_user.email | avatar_url(16) }}", + } + } else { + var data = { comment_added: _comment, comment_user: "{{ g.fas_user.username }}", comment_date: Date.now(), avatar_url: "{{ g.fas_user.email | avatar_url(16) }}", + } } process_event( data, diff --git a/pagure/templates/repo_pull_request.html b/pagure/templates/repo_pull_request.html index d42a502..65648a1 100644 --- a/pagure/templates/repo_pull_request.html +++ b/pagure/templates/repo_pull_request.html @@ -1058,7 +1058,14 @@ function try_async_comment(form, inline) { } /* Keep some variable in memory before sending them in case the SSE is down */ + var _update = false; var _comment = $(form).find('#comment').val(); + var _comment_id = null; + if (!_comment && form.update_comment) { + _update = true; + _comment_id = $(form.edit_comment).val(); + _comment = $(form).find('#update_comment').val(); + } var _commit_id = null; var _line = null; var _token = "{{ mergeform.csrf_token.current_token }}"; @@ -1087,6 +1094,10 @@ function try_async_comment(form, inline) { } item.remove(); if (!sse) { + if (!_comment){ + // Make the browser submit the form sync + form.submit(); + } console.log('no sse, adding the comment manually'); $.ajax({ url: "{{ url_for('ui_ns.markdown_preview') }}" , @@ -1098,13 +1109,23 @@ function try_async_comment(form, inline) { dataType: 'html', success: function(res) { var _comment = emojione.toImage(res); - var data = { + if (_update) { + var data = { + comment_updated: _comment, + comment_user: "{{ g.fas_user.username }}", + comment_date: Date.now(), + comment_id: _comment_id, + avatar_url: "{{ g.fas_user.email | avatar_url(16) }}", + } + } else { + var data = { comment_added: _comment, comment_user: "{{ g.fas_user.username }}", comment_date: Date.now(), avatar_url: "{{ g.fas_user.email | avatar_url(16) }}", commit_id: _commit_id, line: _line, + } } process_event( data,