Confirmaton on send, banner when 'unverified'
Not yet using the new APIs, but ready to. Still to do: - Send sync messages on trust decisions - Respond to received trust decision sync messages - Show trust decisions in the conversation history - In that rare situation where a sent message ends up with a key error make it easy to retry the send. FREEBIE
This commit is contained in:
parent
bedf10056b
commit
243cbd8123
12 changed files with 442 additions and 62 deletions
36
js/views/banner_view.js
Normal file
36
js/views/banner_view.js
Normal file
|
@ -0,0 +1,36 @@
|
|||
/*
|
||||
* vim: ts=4:sw=4:expandtab
|
||||
*/
|
||||
(function () {
|
||||
'use strict';
|
||||
window.Whisper = window.Whisper || {};
|
||||
|
||||
Whisper.BannerView = Whisper.View.extend({
|
||||
className: 'banner',
|
||||
templateName: 'banner',
|
||||
events: {
|
||||
'click .dismiss': 'onDismiss',
|
||||
'click .body': 'onClick',
|
||||
},
|
||||
initialize: function(options) {
|
||||
this.message = options.message;
|
||||
this.callbacks = {
|
||||
onDismiss: options.onDismiss,
|
||||
onClick: options.onClick
|
||||
};
|
||||
this.render();
|
||||
},
|
||||
render_attributes: function() {
|
||||
return {
|
||||
message: this.message
|
||||
};
|
||||
},
|
||||
onDismiss: function(e) {
|
||||
this.callbacks.onDismiss();
|
||||
e.stopPropagation();
|
||||
},
|
||||
onClick: function() {
|
||||
this.callbacks.onClick();
|
||||
}
|
||||
});
|
||||
})();
|
|
@ -10,8 +10,13 @@
|
|||
templateName: 'confirmation-dialog',
|
||||
initialize: function(options) {
|
||||
this.message = options.message;
|
||||
|
||||
this.resolve = options.resolve;
|
||||
this.okText = options.okText || i18n('ok');
|
||||
|
||||
this.reject = options.reject;
|
||||
this.cancelText = options.cancelText || i18n('cancel');
|
||||
|
||||
this.render();
|
||||
},
|
||||
events: {
|
||||
|
@ -21,8 +26,8 @@
|
|||
render_attributes: function() {
|
||||
return {
|
||||
message: this.message,
|
||||
cancel: i18n('cancel'),
|
||||
ok: i18n('ok')
|
||||
cancel: this.cancelText,
|
||||
ok: this.okText
|
||||
};
|
||||
},
|
||||
ok: function() {
|
||||
|
|
|
@ -59,6 +59,9 @@
|
|||
|
||||
Whisper.ConversationTitleView = Whisper.View.extend({
|
||||
templateName: 'conversation-title',
|
||||
initialize: function() {
|
||||
this.listenTo(this.model, 'change', this.render);
|
||||
},
|
||||
render_attributes: function() {
|
||||
return {
|
||||
verified: this.model.isVerified(),
|
||||
|
@ -93,9 +96,8 @@
|
|||
},
|
||||
initialize: function(options) {
|
||||
this.listenTo(this.model, 'destroy', this.stopListening);
|
||||
this.listenTo(this.model, 'change', this.updateTitle);
|
||||
this.listenTo(this.model, 'change:verified', this.onVerifiedChange);
|
||||
this.listenTo(this.model, 'change:color', this.updateColor);
|
||||
this.listenTo(this.model, 'change:name', this.updateTitle);
|
||||
this.listenTo(this.model, 'newmessage', this.addMessage);
|
||||
this.listenTo(this.model, 'delivered', this.updateMessage);
|
||||
this.listenTo(this.model, 'opened', this.onOpened);
|
||||
|
@ -154,14 +156,14 @@
|
|||
},
|
||||
|
||||
events: {
|
||||
'submit .send': 'sendMessage',
|
||||
'submit .send': 'checkUnverifiedSendMessage',
|
||||
'input .send-message': 'updateMessageFieldSize',
|
||||
'keydown .send-message': 'updateMessageFieldSize',
|
||||
'click .destroy': 'destroyMessages',
|
||||
'click .end-session': 'endSession',
|
||||
'click .leave-group': 'leaveGroup',
|
||||
'click .update-group': 'newGroupUpdate',
|
||||
'click .show-identity': 'showIdentity',
|
||||
'click .show-identity': 'showSafetyNumber',
|
||||
'click .show-members': 'showMembers',
|
||||
'click .conversation-menu .hamburger': 'toggleMenu',
|
||||
'click .openInbox' : 'openInbox',
|
||||
|
@ -185,9 +187,59 @@
|
|||
'show-identity': 'showIdentity'
|
||||
},
|
||||
|
||||
updateTitle: function() {
|
||||
this.titleView.render();
|
||||
|
||||
markAllAsVerifiedDefault: function(unverified) {
|
||||
return Promise.all(unverified.map(function(contact) {
|
||||
return contact.setVerifiedDefault();
|
||||
}));
|
||||
},
|
||||
|
||||
openSafetyNumberScreens: function(unverified) {
|
||||
if (unverified.length === 1) {
|
||||
this.showSafetyNumber(null, unverified.at(0));
|
||||
return;
|
||||
}
|
||||
|
||||
// TODO: need to be able to specify string to override group list header
|
||||
this.showMembers(null, unverified);
|
||||
},
|
||||
|
||||
onVerifiedChange: function() {
|
||||
if (this.model.isUnverified()) {
|
||||
var unverified = this.model.getUnverified();
|
||||
var message;
|
||||
if (unverified.length > 1) {
|
||||
message = i18n('multipleNoLongerVerified');
|
||||
} else {
|
||||
message = i18n('noLongerVerified', unverified.at(0).getTitle());
|
||||
}
|
||||
|
||||
// Need to re-add, since unverified set may have changed
|
||||
if (this.banner) {
|
||||
this.banner.remove();
|
||||
this.banner = null;
|
||||
}
|
||||
|
||||
this.banner = new Whisper.BannerView({
|
||||
message: message,
|
||||
onDismiss: function() {
|
||||
this.markAllAsVerifiedDefault(unverified);
|
||||
}.bind(this),
|
||||
onClick: function() {
|
||||
this.openSafetyNumberScreens(unverified);
|
||||
}.bind(this)
|
||||
});
|
||||
|
||||
var container = this.$('.discussion-container');
|
||||
container.append(this.banner.el);
|
||||
} else if (this.banner) {
|
||||
this.banner.remove();
|
||||
this.banner = null;
|
||||
|
||||
// TODO: Is there anything else we should do here? make messages re-send-able?
|
||||
}
|
||||
},
|
||||
|
||||
enableDisappearingMessages: function() {
|
||||
if (!this.model.get('expireTimer')) {
|
||||
this.model.updateExpirationTimer(
|
||||
|
@ -257,6 +309,15 @@
|
|||
this.$el.trigger('force-resize');
|
||||
this.focusMessageField();
|
||||
|
||||
// TODO: do a fetch of all profiles to get the latest identity keys, then:
|
||||
// We have a number of async things happening here:
|
||||
// 1. we need to get contacts before we do anything with groups
|
||||
// 2. we need to get profile information for each contact
|
||||
// 3. we need to get all messages for conversation
|
||||
// 4. we need to get updated verified information for each contact
|
||||
// 5. we perhaps need to throw up the banner if in unverified state
|
||||
this.model.updateVerified().then(this.onVerifiedChange.bind(this));
|
||||
|
||||
if (this.inProgressFetch) {
|
||||
this.inProgressFetch.then(this.updateUnread.bind(this));
|
||||
} else {
|
||||
|
@ -437,16 +498,6 @@
|
|||
this.model.messageCollection.add(message, {merge: true});
|
||||
},
|
||||
|
||||
showMembers: function() {
|
||||
return this.model.fetchContacts().then(function() {
|
||||
var view = new Whisper.GroupMemberList({
|
||||
model: this.model,
|
||||
listenBack: this.listenBack.bind(this)
|
||||
});
|
||||
this.listenBack(view);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
openInbox: function() {
|
||||
openInbox();
|
||||
},
|
||||
|
@ -517,7 +568,19 @@
|
|||
}
|
||||
},
|
||||
|
||||
showIdentity: function(ev, model) {
|
||||
showMembers: function(e, members) {
|
||||
members = members || this.model.contactCollection;
|
||||
|
||||
var view = new Whisper.GroupMemberList({
|
||||
model: members,
|
||||
// we pass this in to allow nexted panels
|
||||
listenBack: this.listenBack.bind(this)
|
||||
});
|
||||
|
||||
this.listenBack(view);
|
||||
},
|
||||
|
||||
showSafetyNumber: function(e, model) {
|
||||
if (!model && this.model.isPrivate()) {
|
||||
model = this.model;
|
||||
}
|
||||
|
@ -601,6 +664,68 @@
|
|||
this.$('.menu-list').hide();
|
||||
},
|
||||
|
||||
showSendConfirmationDialog: function(e, contacts) {
|
||||
var message;
|
||||
var isUnverified = this.model.isUnverified();
|
||||
|
||||
if (contacts.length > 1) {
|
||||
if (isUnverified) {
|
||||
message = i18n('changedSinceVerifiedMultiple');
|
||||
} else {
|
||||
message = i18n('changedRecentlyMultiple');
|
||||
}
|
||||
} else {
|
||||
if (isUnverified) {
|
||||
message = i18n('changedSinceVerified', this.model.getTitle());
|
||||
} else {
|
||||
message = i18n('changedRecently', this.model.getTitle());
|
||||
}
|
||||
}
|
||||
|
||||
var dialog = new Whisper.ConfirmationDialogView({
|
||||
message: message,
|
||||
okText: i18n('sendAnyway'),
|
||||
resolve: function() {
|
||||
this.checkUnverifiedSendMessage(e, {force: true});
|
||||
}.bind(this),
|
||||
reject: function() {
|
||||
// do nothing
|
||||
}
|
||||
});
|
||||
this.$el.prepend(dialog.el);
|
||||
},
|
||||
|
||||
checkUnverifiedSendMessage: function(e, options) {
|
||||
options = options || {};
|
||||
_.defaults(options, {force: false});
|
||||
|
||||
var contacts = this.model.getUnverified();
|
||||
if (!contacts.length) {
|
||||
return this.checkUntrustedSendMessage(e, options);
|
||||
}
|
||||
|
||||
if (options.force) {
|
||||
return this.markAllAsVerifiedDefault(contacts).then(function() {
|
||||
this.checkUnverifiedSendMessage(e, options);
|
||||
}.bind(this));
|
||||
}
|
||||
|
||||
this.showSendConfirmationDialog(e, contacts);
|
||||
},
|
||||
|
||||
checkUntrustedSendMessage: function(e, options) {
|
||||
options = options || {};
|
||||
_.defaults(options, {force: false});
|
||||
|
||||
this.model.getUntrusted().then(function(contacts) {
|
||||
if (!contacts.length || options.force) {
|
||||
return this.sendMessage(e);
|
||||
}
|
||||
|
||||
this.showSendConfirmationDialog(e, contacts);
|
||||
}.bind(this));
|
||||
},
|
||||
|
||||
sendMessage: function(e) {
|
||||
this.removeLastSeenIndicator();
|
||||
|
||||
|
|
|
@ -15,16 +15,16 @@
|
|||
templateName: 'group-member-list',
|
||||
initialize: function(options) {
|
||||
this.render();
|
||||
console.log('GroupMemberList', options);
|
||||
|
||||
this.member_list_view = new Whisper.ContactListView({
|
||||
collection: this.model.contactCollection,
|
||||
collection: this.model,
|
||||
className: 'members',
|
||||
toInclude: {
|
||||
listenBack: options.listenBack
|
||||
}
|
||||
});
|
||||
this.member_list_view.render();
|
||||
|
||||
this.$('.container').append(this.member_list_view.el);
|
||||
},
|
||||
render_attributes: {
|
||||
|
|
|
@ -75,7 +75,6 @@
|
|||
var yourSafetyNumberWith = i18n(
|
||||
'yourSafetyNumberWith', this.model.getTitle()
|
||||
);
|
||||
console.log('this.model',this.model);
|
||||
var verifyButton = this.model.isVerified() ? i18n('markAsNotVerified') : i18n('verify');
|
||||
|
||||
return {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue