Commit 7087dcd1e18217e31fadd895965abe9f1325bbab

Authored by OpenWapp Developer
1 parent a7b792c975

Making id attribute for messages to be _id

Showing 5 changed files with 13 additions and 7 deletions

app/scripts/models/conversation.js View file @ 7087dcd
... ... @@ -163,8 +163,14 @@
163 163  
164 164 updateParticipantList: function () {
165 165 this.trigger('dirty:participants');
166   - }
  166 + },
167 167  
  168 + removeMessage: function (messageId) {
  169 + messageId = parseInt(messageId, 10);
  170 + var messages = this.get('messages');
  171 + var message = messages.get(messageId);
  172 + messages.remove(message);
  173 + }
168 174 });
169 175  
170 176 return Conversation;
app/scripts/models/message.js View file @ 7087dcd
... ... @@ -6,6 +6,8 @@
6 6 'use strict';
7 7  
8 8 var Message = Backbone.Model.extend({
  9 + idAttribute: '_id',
  10 +
9 11 defaults: function () {
10 12 return {
11 13 type: 'text',
app/scripts/templates/multimedia-message.hbs View file @ 7087dcd
1   -<li class="{{messageOwnerClass from.msisdn}} image {{status}}" data-messageId="{{_id}}">
  1 +<li class="{{messageOwnerClass from.msisdn}} image {{status}}" data-message-id="{{_id}}">
2 2 <span class="author">{{author}}</span>
3 3 <span class="content">{{translate type}}<br/>{{content.caption}}</span>
4 4 <aside>
app/scripts/templates/text-message.hbs View file @ 7087dcd
1   -<li class="{{messageOwnerClass from.msisdn}} text {{status}}" data-messageId={{_id}}>
  1 +<li class="{{messageOwnerClass from.msisdn}} text {{status}}" data-message-id={{_id}}>
2 2 <span class="author">{{author}}</span>
3 3 <span class="content">{{contents}}</span>
4 4 <time>{{formattedMessageDate meta.date}}</time>
app/scripts/views/conversation.js View file @ 7087dcd
... ... @@ -127,15 +127,13 @@
127 127 var l10n = global.localisation[global.language];
128 128  
129 129 var listitem = $(evt.target).closest('li')[0];
130   - console.log(listitem);
131   - var messageId = listitem.dataset.messageid;
  130 + var messageId = listitem.dataset.messageId;
132 131  
133 132 var stringId = 'removeMessage';
134 133 var msg = l10n[stringId];
135 134 if (window.confirm(msg)) {
136 135 console.log('Going to remove messageId', messageId);
137   - global.historyCollection
138   - .removeMessage(this.model.get('id'), messageId);
  136 + this.model.removeMessage(messageId);
139 137 listitem.parentNode.removeChild(listitem);
140 138 }
141 139 },