simplificaiton

pull/1129/head
Vincent 5 years ago
parent c22ba999e7
commit 2b0ea5bcc5

@ -20,6 +20,7 @@
"start-multi2": "cross-env NODE_APP_INSTANCE=2 electron .",
"start-prod": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod electron .",
"start-prod-multi": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod1 electron .",
"start-prod-multi1": "cross-env NODE_ENV=production NODE_APP_INSTANCE=devprod2 electron .",
"start-swarm-test": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=1 electron .",
"start-swarm-test-2": "cross-env NODE_ENV=swarm-testing NODE_APP_INSTANCE=2 electron .",
"grunt": "grunt",

@ -25,6 +25,7 @@ export type PropsData = {
isPublic?: boolean;
isRss?: boolean;
isClosable?: boolean;
primaryDevice?: string;
lastUpdated: number;
unreadCount: number;

@ -326,7 +326,7 @@ export class LeftPaneContactSection extends React.Component<Props, State> {
const length = Number(sentFriendsRequest.length) + Number(friends.length);
// Prevent where friends and send FR showing two entries
const combined = [...new Set([...sentFriendsRequest, ...friends])];
const combined = [...sentFriendsRequest, ...friends];
const list = (
<div className="module-left-pane__list" key={0}>

@ -102,6 +102,7 @@ export const _getLeftPaneLists = (
sentFriendsRequest: Array<ConversationListItemPropsType>;
unreadCount: number;
} => {
const _ = window.Lodash;
const values = Object.values(lookup);
const sorted = values.sort(comparator);
@ -138,7 +139,9 @@ export const _getLeftPaneLists = (
unreadCount += conversation.unreadCount;
}
if (conversation.hasSentFriendRequest) {
allSentFriendsRequest.push(conversation);
if (!conversation.isFriend) {
allSentFriendsRequest.push(conversation);
}
}
if (!conversation.activeAt) {
@ -152,31 +155,45 @@ export const _getLeftPaneLists = (
}
}
const filterToPrimary = (
const filterToPrimary = <T extends Array<ConversationType | ConversationListItemPropsType>>(
group: Array<ConversationType | ConversationListItemPropsType>
) => {
// Used to ensure that only the primary device gets added to LeftPane filtered groups
) : T => {
const secondariesToRemove: Array<string> = [];
group.forEach(device => {
if (!device.isSecondary) {
return;
}
const devicePrimary = group.find(c => c.id === device.primaryDevice);
// Remove secondary where primary already exists in group
if (_.includes(group, devicePrimary)) {
secondariesToRemove.push(device.id);
}
});
const constructedGroup = conversations.filter(c =>
group.some(g => c.id === g.id)
);
// tslint:disable-next-line: no-unnecessary-local-variable
const filteredGroup = constructedGroup.filter(
(c, idx) =>
!(
c.isSecondary &&
constructedGroup.some(
g => !g.isSecondary && g.id === constructedGroup[idx].primaryDevice
)
)
);
return filteredGroup;
const filteredGroup = group.filter(c => !(secondariesToRemove.find(s => s === c.id)));
return (filteredGroup as T);
};
const friends = filterToPrimary(allFriends);
const receivedFriendsRequest = filterToPrimary(allReceivedFriendsRequest);
const sentFriendsRequest = filterToPrimary(allSentFriendsRequest);
const friends: Array<ConversationType> =
filterToPrimary(allFriends);
const receivedFriendsRequest: Array<ConversationListItemPropsType> =
filterToPrimary(allReceivedFriendsRequest);
const sentFriendsRequest: Array<ConversationListItemPropsType> =
filterToPrimary(allSentFriendsRequest);
console.log('[vince] allFriends:', allFriends);
console.log('[vince] friends:', friends);
console.log('[vince] allReceivedFriendsRequest:', allReceivedFriendsRequest);
console.log('[vince] receivedFriendsRequest:', receivedFriendsRequest);
console.log('[vince] allSentFriendsRequest:', allSentFriendsRequest);
console.log('[vince] sentFriendsRequest:', sentFriendsRequest);
console.log('[vince] conversations:', conversations);
return {
conversations,

Loading…
Cancel
Save