Permalink
Browse files

Do not attempt to add duplicates.

  • Loading branch information...
1 parent c9d2b12 commit 8c575c23a942fe3536e200f67ffbbede74486fd0 @ringmaster committed Mar 20, 2012
Showing with 16 additions and 14 deletions.
  1. +1 −1 barchat.js
  2. +14 −12 htdocs/js/barchat.ui.js
  3. +1 −1 views/index.html
View
@@ -98,7 +98,7 @@ var cleanSessions = function() {
var options = { multi: true, safe: false };
var dt = moment().subtract('m', 1);
Users.update({}, {$pull: {'sessions': {'ping': {$lt: new Date(dt)}}}}, options, function(err, doc) {
- console.log(err);
+ // Do something useful here.
});
}
setInterval(cleanSessions, 60000);
View
@@ -9,22 +9,24 @@ BarchatUI.removeRoom = function(room_id) {
}
BarchatUI.msgRoom = function(msgdatas) {
_.each(msgdatas, function(msgdata){
- stage = $('.room[data-room="' + msgdata.room + '"]');
- msgdate = new Date(msgdata.timestamp);
- msgdata.msgdate = msgdate.toString('ddd h:mmtt');
+ if($('#msg_' + msgdata._id).length == 0) {
+ stage = $('.room[data-room="' + msgdata.room + '"]');
+ msgdate = new Date(msgdata.timestamp);
+ msgdata.msgdate = msgdate.toString('ddd h:mmtt');
- var ip = BarchatUI.getInsertionPoint(stage, msgdate.getTime());
+ var ip = BarchatUI.getInsertionPoint(stage, msgdate.getTime());
- if(ip) {
- ip.before(ich.message(msgdata));
- }
- else {
- lastuser = $('.message:last', stage).data('user');
- if(lastuser == msgdata.user.user_id) {
- $('.message:last .message_texts', stage).append(ich.message_text(msgdata));
+ if(ip) {
+ ip.before(ich.message(msgdata));
}
else {
- stage.append(ich.message(msgdata));
+ lastuser = $('.message:last', stage).data('user');
+ if(lastuser == msgdata.user.user_id) {
+ $('.message:last .message_texts', stage).append(ich.message_text(msgdata));
+ }
+ else {
+ stage.append(ich.message(msgdata));
+ }
}
}
})
View
@@ -60,7 +60,7 @@
</script>
<script id="message_text" type="text/html">
-<div class="message_text" data-timestamp="{{timestamp}}"><span class="timestamp">{{msgdate}}</span>{{msg}}</div>
+<div class="message_text" id="msg_{{_id}}" data-msgid="{{_id}}" data-timestamp="{{timestamp}}"><span class="timestamp">{{msgdate}}</span>{{msg}}</div>
</script>
<div id="wrap">

0 comments on commit 8c575c2

Please sign in to comment.