Show friends in inbox.

pull/64/head
Mikunj 7 years ago
parent d1d906cfc0
commit fbc3832cfb

@ -58,6 +58,7 @@
</div> </div>
<div class='content'> <div class='content'>
<div class='conversations inbox'></div> <div class='conversations inbox'></div>
<div class='conversations friends'></div>
<div class='conversations search-results hide'> <div class='conversations search-results hide'>
<div class='new-contact contact hide'></div> <div class='new-contact contact hide'></div>
</div> </div>

@ -11,7 +11,7 @@
const conversations = new Whisper.ConversationCollection(); const conversations = new Whisper.ConversationCollection();
const inboxCollection = new (Backbone.Collection.extend({ const inboxCollection = new (Backbone.Collection.extend({
initialize() { initialize() {
this.on('change:timestamp change:name change:number', this.sort); this.on('change:timestamp change:name change:number change:profileName', this.sort);
this.listenTo(conversations, 'add change:active_at', this.addActive); this.listenTo(conversations, 'add change:active_at', this.addActive);
this.listenTo(conversations, 'reset', () => this.reset([])); this.listenTo(conversations, 'reset', () => this.reset([]));
@ -77,6 +77,34 @@
window.getInboxCollection = () => inboxCollection; window.getInboxCollection = () => inboxCollection;
const friendCollection = new (Backbone.Collection.extend({
initialize() {
this.on('change:timestamp change:name change:number change:profileName', this.sort);
this.listenTo(conversations, 'add change:active_at', this.addActive);
this.listenTo(conversations, 'reset', () => this.reset([]));
this.collator = new Intl.Collator();
},
comparator(m1, m2) {
const title1 = m1.getTitle().toLowerCase();
const title2 = m2.getTitle().toLowerCase();
return this.collator.compare(title1, title2);
},
addActive(model) {
// We only want models which are not shown in the inbox
// And that we are friends with
const inboxHasModel = inboxCollection.contains(model);
if (!inboxHasModel) {
this.add(model);
} else {
this.remove(model);
}
},
}))();
window.getFriendCollection = () => friendCollection;
window.ConversationController = { window.ConversationController = {
markAsSelected(toSelect) { markAsSelected(toSelect) {
conversations.each(conversation => { conversations.each(conversation => {

@ -1,6 +1,7 @@
/* global ConversationController: false */ /* global ConversationController: false */
/* global extension: false */ /* global extension: false */
/* global getInboxCollection: false */ /* global getInboxCollection: false */
/* global getFriendCollection: false */
/* global i18n: false */ /* global i18n: false */
/* global Whisper: false */ /* global Whisper: false */
/* global textsecure: false */ /* global textsecure: false */
@ -136,6 +137,7 @@
this.startConnectionListener(); this.startConnectionListener();
} }
// Inbox
const inboxCollection = getInboxCollection(); const inboxCollection = getInboxCollection();
this.listenTo(inboxCollection, 'messageError', () => { this.listenTo(inboxCollection, 'messageError', () => {
@ -152,7 +154,7 @@
this.inboxListView.listenTo( this.inboxListView.listenTo(
inboxCollection, inboxCollection,
'add change:timestamp change:name change:number', 'add change:timestamp change:name change:number change:profileName',
this.inboxListView.updateLocation this.inboxListView.updateLocation
); );
@ -160,9 +162,32 @@
this.listenTo( this.listenTo(
inboxCollection, inboxCollection,
'remove', 'remove',
this.closeConversation, this.closeConversation
); );
// Friends
const friendCollection = getFriendCollection();
this.listenTo(friendCollection, 'select', this.openConversation);
this.friendListView = new Whisper.ConversationListView({
el: this.$('.friends'),
collection: friendCollection,
}).render();
this.friendListView.listenTo(
friendCollection,
'add change:timestamp change:name change:number change:profileName',
this.friendListView.updateLocation
);
this.listenTo(
friendCollection,
'remove',
this.closeConversation
);
// Search
this.searchView = new Whisper.ConversationSearchView({ this.searchView = new Whisper.ConversationSearchView({
el: this.$('.search-results'), el: this.$('.search-results'),
input: this.$('input.search'), input: this.$('input.search'),
@ -173,10 +198,12 @@
this.listenTo(this.searchView, 'hide', function toggleVisibility() { this.listenTo(this.searchView, 'hide', function toggleVisibility() {
this.searchView.$el.hide(); this.searchView.$el.hide();
this.inboxListView.$el.show(); this.inboxListView.$el.show();
this.friendListView.$el.show();
}); });
this.listenTo(this.searchView, 'show', function toggleVisibility() { this.listenTo(this.searchView, 'show', function toggleVisibility() {
this.searchView.$el.show(); this.searchView.$el.show();
this.inboxListView.$el.hide(); this.inboxListView.$el.hide();
this.friendListView.$el.hide();
}); });
this.listenTo(this.searchView, 'open', this.openConversation); this.listenTo(this.searchView, 'open', this.openConversation);
@ -187,6 +214,7 @@
extension.windows.onClosed(() => { extension.windows.onClosed(() => {
this.inboxListView.stopListening(); this.inboxListView.stopListening();
this.friendListView.stopListening();
}); });
if (extension.expired()) { if (extension.expired()) {
@ -308,6 +336,7 @@
closeConversation(conversation) { closeConversation(conversation) {
if (conversation) { if (conversation) {
this.inboxListView.removeItem(conversation); this.inboxListView.removeItem(conversation);
this.friendListView.removeItem(conversation);
this.conversation_stack.close(conversation); this.conversation_stack.close(conversation);
} }
}, },

Loading…
Cancel
Save