Unload conversations and old messages every half-hour
FREEBIE
This commit is contained in:
parent
4ea457a01c
commit
65283d2794
5 changed files with 198 additions and 29 deletions
|
@ -43,6 +43,9 @@
|
|||
});
|
||||
var TimerView = Whisper.View.extend({
|
||||
templateName: 'hourglass',
|
||||
initialize: function() {
|
||||
this.listenTo(this.model, 'unload', this.remove);
|
||||
},
|
||||
update: function() {
|
||||
if (this.timeout) {
|
||||
clearTimeout(this.timeout);
|
||||
|
@ -74,6 +77,7 @@
|
|||
initialize: function() {
|
||||
this.conversation = this.model.getExpirationTimerUpdateSource();
|
||||
this.listenTo(this.conversation, 'change', this.render);
|
||||
this.listenTo(this.model, 'unload', this.remove);
|
||||
},
|
||||
render_attributes: function() {
|
||||
var seconds = this.model.get('expirationTimerUpdate').expireTimer;
|
||||
|
@ -100,6 +104,7 @@
|
|||
initialize: function() {
|
||||
this.conversation = this.model.getModelForKeyChange();
|
||||
this.listenTo(this.conversation, 'change', this.render);
|
||||
this.listenTo(this.model, 'unload', this.remove);
|
||||
},
|
||||
events: {
|
||||
'click .content': 'showIdentity'
|
||||
|
@ -124,6 +129,7 @@
|
|||
initialize: function() {
|
||||
this.conversation = this.model.getModelForVerifiedChange();
|
||||
this.listenTo(this.conversation, 'change', this.render);
|
||||
this.listenTo(this.model, 'unload', this.remove);
|
||||
},
|
||||
events: {
|
||||
'click .content': 'showIdentity'
|
||||
|
@ -173,6 +179,7 @@
|
|||
this.listenTo(this.model, 'change', this.renderSent);
|
||||
this.listenTo(this.model, 'change:flags change:group_update', this.renderControl);
|
||||
this.listenTo(this.model, 'destroy', this.onDestroy);
|
||||
this.listenTo(this.model, 'unload', this.onUnload);
|
||||
this.listenTo(this.model, 'expired', this.onExpired);
|
||||
this.listenTo(this.model, 'pending', this.renderPending);
|
||||
this.listenTo(this.model, 'done', this.renderDone);
|
||||
|
@ -209,11 +216,39 @@
|
|||
// Failsafe: if in the background, animation events don't fire
|
||||
setTimeout(this.remove.bind(this), 1000);
|
||||
},
|
||||
onUnload: function() {
|
||||
if (this.avatarView) {
|
||||
this.avatarView.remove();
|
||||
}
|
||||
if (this.errorIconView) {
|
||||
this.errorIconView.remove();
|
||||
}
|
||||
if (this.networkErrorView) {
|
||||
this.networkErrorView.remove();
|
||||
}
|
||||
if (this.someFailedView) {
|
||||
this.someFailedView.remove();
|
||||
}
|
||||
if (this.timeStampView) {
|
||||
this.timeStampView.remove();
|
||||
}
|
||||
if (this.loadedAttachments && this.loadedAttachments.length) {
|
||||
for (var i = 0, max = this.loadedAttachments.length; i < max; i += 1) {
|
||||
var view = this.loadedAttachments[i];
|
||||
view.unload();
|
||||
}
|
||||
}
|
||||
|
||||
// No need to handle this one, since it listens to 'unload' itself:
|
||||
// this.timerView
|
||||
|
||||
this.remove();
|
||||
},
|
||||
onDestroy: function() {
|
||||
if (this.$el.hasClass('expired')) {
|
||||
return;
|
||||
}
|
||||
this.remove();
|
||||
this.onUnload();
|
||||
},
|
||||
select: function(e) {
|
||||
this.$el.trigger('select', {message: this.model});
|
||||
|
@ -245,24 +280,41 @@
|
|||
},
|
||||
renderErrors: function() {
|
||||
var errors = this.model.get('errors');
|
||||
|
||||
if (_.size(errors) > 0) {
|
||||
if (this.model.isIncoming()) {
|
||||
this.$('.content').text(this.model.getDescription()).addClass('error-message');
|
||||
}
|
||||
var view = new ErrorIconView({ model: errors[0] });
|
||||
view.render().$el.appendTo(this.$('.bubble'));
|
||||
this.errorIconView = new ErrorIconView({ model: errors[0] });
|
||||
this.errorIconView.render().$el.appendTo(this.$('.bubble'));
|
||||
} else {
|
||||
this.$('.error-icon-container').remove();
|
||||
if (this.errorIconView) {
|
||||
this.errorIconView.remove();
|
||||
this.errorIconView = null;
|
||||
}
|
||||
}
|
||||
this.$('.meta .hasRetry').remove();
|
||||
|
||||
if (this.model.hasNetworkError()) {
|
||||
var networkErrorView = new NetworkErrorView({model: this.model});
|
||||
this.$('.meta').prepend(networkErrorView.render().el);
|
||||
this.networkErrorView = new NetworkErrorView({model: this.model});
|
||||
this.$('.meta').prepend(this.networkErrorView.render().el);
|
||||
} else {
|
||||
this.$('.meta .hasRetry').remove();
|
||||
if (this.networkErrorView) {
|
||||
this.networkErrorView.remove();
|
||||
this.networkErrorView = null;
|
||||
}
|
||||
}
|
||||
this.$('.meta .some-failed').remove();
|
||||
|
||||
if (this.model.someRecipientsFailed()) {
|
||||
var someFailedView = new SomeFailedView();
|
||||
this.$('.meta').prepend(someFailedView.render().el);
|
||||
this.someFailedView = new SomeFailedView();
|
||||
this.$('.meta').prepend(this.someFailedView.render().el);
|
||||
} else {
|
||||
this.$('.meta .some-failed').remove();
|
||||
if (this.someFailedView) {
|
||||
this.someFailedView.remove();
|
||||
this.someFailedView = null;
|
||||
}
|
||||
}
|
||||
},
|
||||
renderControl: function() {
|
||||
|
@ -321,11 +373,11 @@
|
|||
if (color) {
|
||||
bubble.addClass(color);
|
||||
}
|
||||
var avatarView = new (Whisper.View.extend({
|
||||
this.avatarView = new (Whisper.View.extend({
|
||||
templateName: 'avatar',
|
||||
render_attributes: { avatar: model.getAvatar() }
|
||||
}))();
|
||||
this.$('.avatar').replaceWith(avatarView.render().$('.avatar'));
|
||||
this.$('.avatar').replaceWith(this.avatarView.render().$('.avatar'));
|
||||
},
|
||||
appendAttachmentView: function(view) {
|
||||
// We check for a truthy 'updated' here to ensure that a race condition in a
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue