Page MenuHomePhorge

D7877.1765103119.diff
No OneTemporary

Size
5 KB
Referenced Files
None
Subscribers
None

D7877.1765103119.diff

diff --git a/lib/reducers/invite-links-reducer.js b/lib/reducers/invite-links-reducer.js
new file mode 100644
--- /dev/null
+++ b/lib/reducers/invite-links-reducer.js
@@ -0,0 +1,26 @@
+// @flow
+
+import { fetchPrimaryInviteLinkActionTypes } from '../actions/link-actions.js';
+import type { InviteLinksStore } from '../types/link-types.js';
+import type { BaseAction } from '../types/redux-types.js';
+
+function reduceInviteLinks(
+ state: InviteLinksStore,
+ action: BaseAction,
+): InviteLinksStore {
+ if (action.type === fetchPrimaryInviteLinkActionTypes.success) {
+ const links = {};
+ for (const link of action.payload.links) {
+ links[link.communityID] = {
+ primaryLink: link,
+ ...state.links[link.communityID],
+ };
+ }
+ return {
+ links,
+ };
+ }
+ return state;
+}
+
+export default reduceInviteLinks;
diff --git a/lib/reducers/master-reducer.js b/lib/reducers/master-reducer.js
--- a/lib/reducers/master-reducer.js
+++ b/lib/reducers/master-reducer.js
@@ -7,6 +7,7 @@
import { reduceDraftStore } from './draft-reducer.js';
import reduceEnabledApps from './enabled-apps-reducer.js';
import { reduceEntryInfos } from './entry-reducer.js';
+import reduceInviteLinks from './invite-links-reducer.js';
import reduceLifecycleState from './lifecycle-state-reducer.js';
import { reduceLoadingStatuses } from './loading-reducer.js';
import reduceNextLocalID from './local-id-reducer.js';
@@ -119,6 +120,7 @@
state.commServicesAccessToken,
action,
),
+ inviteLinksStore: reduceInviteLinks(state.inviteLinksStore, action),
},
storeOperations: {
draftStoreOperations,
diff --git a/lib/selectors/invite-links-selectors.js b/lib/selectors/invite-links-selectors.js
new file mode 100644
--- /dev/null
+++ b/lib/selectors/invite-links-selectors.js
@@ -0,0 +1,24 @@
+// @flow
+
+import { createSelector } from 'reselect';
+
+import type { InviteLink, CommunityLinks } from '../types/link-types.js';
+import type { AppState } from '../types/redux-types.js';
+
+const primaryInviteLinksSelector: (state: AppState) => {
+ [communityID: string]: InviteLink,
+} = createSelector(
+ (state: AppState) => state.inviteLinksStore.links,
+ (links: { +[communityID: string]: CommunityLinks }) => {
+ const primaryLinks = {};
+ for (const communityID in links) {
+ const communityLinks = links[communityID];
+ if (communityLinks.primaryLink) {
+ primaryLinks[communityID] = communityLinks.primaryLink;
+ }
+ }
+ return primaryLinks;
+ },
+);
+
+export { primaryInviteLinksSelector };
diff --git a/lib/types/link-types.js b/lib/types/link-types.js
--- a/lib/types/link-types.js
+++ b/lib/types/link-types.js
@@ -29,3 +29,13 @@
export type FetchInviteLinksResponse = {
+links: $ReadOnlyArray<InviteLink>,
};
+
+export type CommunityLinks = {
+ +primaryLink: ?InviteLink,
+};
+
+export type InviteLinksStore = {
+ +links: {
+ +[communityID: string]: CommunityLinks,
+ },
+};
diff --git a/lib/types/redux-types.js b/lib/types/redux-types.js
--- a/lib/types/redux-types.js
+++ b/lib/types/redux-types.js
@@ -38,6 +38,7 @@
import type { LifecycleState } from './lifecycle-state-types.js';
import type {
FetchInviteLinksResponse,
+ InviteLinksStore,
InviteLinkVerificationResponse,
} from './link-types.js';
import type { LoadingStatus, LoadingInfo } from './loading-types.js';
@@ -121,6 +122,7 @@
userPolicies: UserPolicies,
deviceToken: ?string,
+commServicesAccessToken: ?string,
+ +inviteLinksStore: InviteLinksStore,
...
};
diff --git a/native/redux/persist.js b/native/redux/persist.js
--- a/native/redux/persist.js
+++ b/native/redux/persist.js
@@ -533,6 +533,12 @@
[38]: state =>
updateClientDBThreadStoreThreadInfos(state, updateRolesAndPermissions),
[39]: (state: AppState) => unshimClientDB(state, [messageTypes.EDIT_MESSAGE]),
+ [40]: (state: AppState) => ({
+ ...state,
+ inviteLinksStore: {
+ links: {},
+ },
+ }),
};
// After migration 31, we'll no longer want to persist `messageStore.messages`
diff --git a/native/redux/redux-setup.js b/native/redux/redux-setup.js
--- a/native/redux/redux-setup.js
+++ b/native/redux/redux-setup.js
@@ -118,6 +118,9 @@
frozen: false,
userPolicies: {},
commServicesAccessToken: null,
+ inviteLinksStore: {
+ links: {},
+ },
}: AppState);
function reducer(state: AppState = defaultState, action: Action) {
diff --git a/native/redux/state-types.js b/native/redux/state-types.js
--- a/native/redux/state-types.js
+++ b/native/redux/state-types.js
@@ -8,6 +8,7 @@
import type { EntryStore } from 'lib/types/entry-types.js';
import type { CalendarFilter } from 'lib/types/filter-types.js';
import type { LifecycleState } from 'lib/types/lifecycle-state-types.js';
+import type { InviteLinksStore } from 'lib/types/link-types.js';
import type { LoadingStatus } from 'lib/types/loading-types.js';
import type { MessageStore } from 'lib/types/message-types.js';
import type { UserPolicies } from 'lib/types/policy-types.js';
@@ -57,4 +58,5 @@
frozen: boolean,
userPolicies: UserPolicies,
+commServicesAccessToken: ?string,
+ +inviteLinksStore: InviteLinksStore,
};
diff --git a/web/redux/redux-setup.js b/web/redux/redux-setup.js
--- a/web/redux/redux-setup.js
+++ b/web/redux/redux-setup.js
@@ -26,6 +26,7 @@
calendarThreadFilterTypes,
} from 'lib/types/filter-types.js';
import type { LifecycleState } from 'lib/types/lifecycle-state-types.js';
+import type { InviteLinksStore } from 'lib/types/link-types.js';
import type { LoadingStatus } from 'lib/types/loading-types.js';
import type { MessageStore } from 'lib/types/message-types.js';
import type { UserPolicies } from 'lib/types/policy-types.js';
@@ -96,6 +97,7 @@
pushApiPublicKey: ?string,
_persist: ?PersistState,
+commServicesAccessToken: ?string,
+ +inviteLinksStore: InviteLinksStore,
};
export type Action =

File Metadata

Mime Type
text/plain
Expires
Sun, Dec 7, 10:25 AM (20 h, 10 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
5843506
Default Alt Text
D7877.1765103119.diff (5 KB)

Event Timeline