Commits

Anonymous committed 1f5516e

add message to warn when paste is updated or deleted.

  • Participants
  • Parent commits 78ba97a

Comments (0)

Files changed (2)

friendpaste/views.py

 
         # move reviews for unchanged lines
         Review.update_positions(local.db, s.pasteid, s.nb_revision, old_revision, unchanged)
+       
+        # warn users that paste has been updated
+        message = json.dumps({
+            'nb_revision': s.nb_revision,
+            'type': 'update'
+        })
+        send_stomp_msg(' ' + message, destination='/paste/%s' % (
+                    s.pasteid))
 
         return redirect ('/%s' % s.pasteid)
     return render_response('paste/edit.html', form=form, snippet=s)
             return send_json({'ok': False, 'reason': 'you should provide snippet code'})
         if s.revid == old_revid:
             return send_json({'ok': False, 'reason': 'no changes detected'})
+
+        # warn users that paste has been updated
+        message = json.dumps({
+            'nb_revision': s.nb_revision,
+            'type': 'update'
+        })
+        send_stomp_msg(' ' + message, destination='/paste/%s' % (
+                    s.pasteid))
+
         return send_json({
             'ok': True,
             'id': s.pasteid,
         edit_code = request.form.get('edit_code', '')
         if edit_code and make_hash(edit_code) == s.edit_code:
             del local.db[s.id]
+            message = json.dumps({
+                'type': 'delete'
+            })
+            send_stomp_msg(' ' + message, destination='/paste/%s' % (
+                    id))
             if request.is_xhr:
                 return send_json({ "ok": True })
             return redirect('/')

static/js/src/review.js

         stomp.onconnectedframe = function() {
             stomp.subscribe('/paste/' + snippet_id + '/' + revid, 
                     { exchange: '' });
+            stomp.subscribe('/paste/' + snippet_id, { exchange: '' });
         };
 
         stomp.onmessageframe = function(frame) {
             notification_zone.classList.remove('hidden');
         setTimeout(function() {
             notification_zone.classList.add('hidden');
-        }, 10000);
+        }, 30000);
     },
 
     handle_messages: function(frame) {
                     message.nb_line+'">#'+message.nb_line+'</a>.';
                 this._notify(txt);
             }
+        } else if (message.type == 'update') {
+             if (message.nb_revision == revid) 
+                return;
+             var txt = 'Past has been updated to <a href="/'+snippet_id+
+                 '?rev='+message.nb_revision+'">revision '+
+                 message.nb_revision + '</a>';
+            this._notify(txt);
+        } else if (message.type == 'delete') { 
+            var txt = 'Paste has been deleted.';
+            this._notify(txt);
         }
-
     },
-
     
     _sourceRow: function(lineNumber) {
         var rows = document.querySelector('td.lines table').rows