tight filtering

pull/1118/head
Vincent 6 years ago
parent 7d803280e8
commit 10ccea5ec8

@ -119,7 +119,7 @@ export const _getLeftPaneLists = (
// Map pubkeys to their primary pubkey so you don't need to call getPrimaryDeviceFor // Map pubkeys to their primary pubkey so you don't need to call getPrimaryDeviceFor
// every time. // every time.
const filterToPrimary = (conversation: ConversationType, group: Array<ConversationType | ConversationListItemPropsType>) => { const filterToPrimary = (group: Array<ConversationType | ConversationListItemPropsType>) => {
// Used to ensure that only the primary device gets added to LeftPane filtered groups // Used to ensure that only the primary device gets added to LeftPane filtered groups
// Get one result per user. Dont just ignore secondaries, in case // Get one result per user. Dont just ignore secondaries, in case
// a user hasn't synced with primary but FR or contact is duplicated. // a user hasn't synced with primary but FR or contact is duplicated.
@ -127,69 +127,15 @@ export const _getLeftPaneLists = (
// You can't just get the primary device for each conversation, as different // You can't just get the primary device for each conversation, as different
// devices might have seperate FR and contacts status, etc. // devices might have seperate FR and contacts status, etc.
const primaryPubkey = conversation.primaryDevice; // Build up propsData into ConversationType
const groupHasPrimary = group.some(c => c.id === primaryPubkey); const constructedGroup = conversations.filter(c => group.some(g => c.id === g.id));
const filteredGroup = constructedGroup.filter(c => !(c.isSecondary && group.some(g => g.id === c.primaryDevice)));
if (!groupHasPrimary) {
group.push(conversation);
}
const constructedGroup = conversations.filter(c => _.includes(group, c.id));
const newGroup = constructedGroup.filter(c => {
if (
c.isSecondary &&
group.some(g => g.id === c.primaryDevice)
) {
return false;
}
return true;
});
console.log('[group] primaryPubkey:', primaryPubkey);
console.log('[group] groupHasPrimary:', groupHasPrimary);
console.log('[group] conversations:', conversations);
console.log('[group] group:', group); console.log('[group] group:', group);
console.log('[vince] newGroup:', newGroup); console.log('[group] filteredGroup:', filteredGroup);
// const isPrimary = !conversation.isSecondary;
// // If no secondary or primary currently in group, add
// if (!groupHasPrimary) {
// group.push(conversation);
// }
// if (clg) {
// console.log('[group] conversation:', conversation);
// console.log('[group] primaryPubkey:', primaryPubkey);
// console.log('[group] group:', group);
// console.log('[group] groupHasPrimary:', groupHasPrimary);
// const qwer = conversations.filter(c => _.includes(group, c.id));
// console.log('[group] constructedGroup:', qwer);
// }
// // If primary, but secondary already added to group, remove secondary
// if (isPrimary) {
// // Build up propsData into ConversationType
// const constructedGroup = conversations.filter(c => _.includes(group, c.id));
// console.log('[group] primary, but secondary already added to group, remove secondary:');
// constructedGroup.every(c => {
// if (c.primaryDevice === primaryPubkey) {
// const secondaryIndex = group.indexOf(c);
// group.splice(secondaryIndex, 1);
// // Early break; removed redundant secondary
// return false;
// }
// return true;
// });
// }
return filteredGroup;
}; };
for (let i = 0; i < max; i += 1) { for (let i = 0; i < max; i += 1) {
@ -203,11 +149,11 @@ export const _getLeftPaneLists = (
} }
if (conversation.isFriend && conversation.activeAt !== undefined) { if (conversation.isFriend && conversation.activeAt !== undefined) {
filterToPrimary(true, conversation, friends); friends.push(conversation)
} }
if (conversation.hasReceivedFriendRequest) { if (conversation.hasReceivedFriendRequest) {
filterToPrimary(false, conversation, receivedFriendsRequest); receivedFriendsRequest.push(conversation)
} else if ( } else if (
unreadCount < 9 && unreadCount < 9 &&
conversation.isFriend && conversation.isFriend &&
@ -216,7 +162,7 @@ export const _getLeftPaneLists = (
unreadCount += conversation.unreadCount; unreadCount += conversation.unreadCount;
} }
if (conversation.hasSentFriendRequest) { if (conversation.hasSentFriendRequest) {
filterToPrimary(false, conversation, sentFriendsRequest); sentFriendsRequest.push(conversation);
} }
if (!conversation.activeAt) { if (!conversation.activeAt) {
@ -230,6 +176,9 @@ export const _getLeftPaneLists = (
} }
} }
const vFriends = filterToPrimary(friends);
console.log('[group] vFriends:', vFriends);
return { return {
conversations, conversations,
archivedConversations, archivedConversations,

Loading…
Cancel
Save