Skip to content

Commit

Permalink
Show members: Pull conversation from group table
Browse files Browse the repository at this point in the history
  • Loading branch information
scottnonnenberg-signal committed Feb 12, 2019
1 parent 12739ac commit 462fa71
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 14 deletions.
2 changes: 1 addition & 1 deletion app/sql.js
Original file line number Diff line number Diff line change
Expand Up @@ -636,7 +636,7 @@ async function getAllGroupIds() {
return map(rows, row => row.id);
}
async function getAllGroups() {
const rows = await db.all('SELECT id FROM groups ORDER BY id ASC;');
const rows = await db.all('SELECT json FROM groups ORDER BY id ASC;');
return map(rows, row => jsonToObject(row.json));
}
async function bulkAddGroups(array) {
Expand Down
19 changes: 12 additions & 7 deletions js/models/conversations.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,17 @@
this.trigger('messageError', message, errors);
},

getContactCollection() {
const collection = new Backbone.Collection();
const collator = new Intl.Collator();
collection.comparator = (left, right) => {
const leftLower = left.getTitle().toLowerCase();
const rightLower = right.getTitle().toLowerCase();
return collator.compare(leftLower, rightLower);
};
return collection;
},

initialize() {
this.ourNumber = textsecure.storage.user.getNumber();
this.verifiedEnum = textsecure.storage.protocol.VerifiedStatus;
Expand All @@ -82,13 +93,7 @@
// our first save to the database. Or first fetch from the database.
this.initialPromise = Promise.resolve();

this.contactCollection = new Backbone.Collection();
const collator = new Intl.Collator();
this.contactCollection.comparator = (left, right) => {
const leftLower = left.getTitle().toLowerCase();
const rightLower = right.getTitle().toLowerCase();
return collator.compare(leftLower, rightLower);
};
this.contactCollection = this.getContactCollection();
this.messageCollection = new Whisper.MessageCollection([], {
conversation: this,
});
Expand Down
2 changes: 1 addition & 1 deletion js/models/messages.js
Original file line number Diff line number Diff line change
Expand Up @@ -633,7 +633,7 @@
// back to the conversation's current recipients
const phoneNumbers = this.isIncoming()
? [this.get('source')]
: this.get('recipients') || this.conversation.getRecipients();
: this.get('sent_to') || this.conversation.getRecipients();

// This will make the error message for outgoing key errors a bit nicer
const allErrors = (this.get('errors') || []).map(error => {
Expand Down
18 changes: 13 additions & 5 deletions js/views/conversation_view.js
Original file line number Diff line number Diff line change
Expand Up @@ -209,8 +209,8 @@
await this.showAllMedia();
this.updateHeader();
},
onShowGroupMembers: () => {
this.showMembers();
onShowGroupMembers: async () => {
await this.showMembers();
this.updateHeader();
},
onGoBack: () => {
Expand Down Expand Up @@ -1127,13 +1127,21 @@
}
},

showMembers(e, providedMembers, options = {}) {
async showMembers(e, providedMembers, options = {}) {
_.defaults(options, { needVerify: false });

const members = providedMembers || this.model.contactCollection;
const fromConversation = this.model.isPrivate()
? [this.model.id]
: await textsecure.storage.groups.getNumbers(this.model.id);
const members =
providedMembers ||
fromConversation.map(id => ConversationController.get(id));

const model = this.model.getContactCollection();
model.reset(members);

const view = new Whisper.GroupMemberList({
model: members,
model,
// we pass this in to allow nested panels
listenBack: this.listenBack.bind(this),
needVerify: options.needVerify,
Expand Down

0 comments on commit 462fa71

Please sign in to comment.