diff --git a/keyserver/src/creators/account-creator.js b/keyserver/src/creators/account-creator.js --- a/keyserver/src/creators/account-creator.js +++ b/keyserver/src/creators/account-creator.js @@ -138,7 +138,7 @@ updateThread( createScriptViewer(ashoat.id), { - threadID: genesis.id, + threadID: genesis().id, changes: { newMemberIDs: [id] }, }, { forceAddMembers: true, silenceMessages: true, ignorePermissions: true }, @@ -312,7 +312,7 @@ updateThread( createScriptViewer(ashoat.id), { - threadID: genesis.id, + threadID: genesis().id, changes: { newMemberIDs: [viewer.userID] }, }, { forceAddMembers: true, silenceMessages: true, ignorePermissions: true }, diff --git a/keyserver/src/creators/thread-creator.js b/keyserver/src/creators/thread-creator.js --- a/keyserver/src/creators/thread-creator.js +++ b/keyserver/src/creators/thread-creator.js @@ -147,7 +147,7 @@ // keyserver, so we set them to the have the Genesis community as their // parent thread. if (!parentThreadID && !threadTypeIsCommunityRoot(threadType)) { - parentThreadID = genesis.id; + parentThreadID = genesis().id; } const determineThreadAncestryPromise = determineThreadAncestry( @@ -464,7 +464,7 @@ if ( parentThreadID && threadType !== threadTypes.SIDEBAR && - (parentThreadID !== genesis.id || + (parentThreadID !== genesis().id || threadType === threadTypes.COMMUNITY_OPEN_SUBTHREAD || threadType === threadTypes.COMMUNITY_OPEN_ANNOUNCEMENT_SUBTHREAD) ) { diff --git a/keyserver/src/database/migration-config.js b/keyserver/src/database/migration-config.js --- a/keyserver/src/database/migration-config.js +++ b/keyserver/src/database/migration-config.js @@ -597,15 +597,17 @@ LEFT JOIN ( SELECT m.thread, MAX(m.id) AS message FROM messages m WHERE m.type != ${messageTypes.CREATE_SUB_THREAD} - AND m.thread = ${genesis.id} + AND m.thread = ${genesis().id} GROUP BY m.thread ) all_users_query ON mm.thread = all_users_query.thread LEFT JOIN ( SELECT m.thread, stm.user, MAX(m.id) AS message FROM messages m - LEFT JOIN memberships stm ON m.type = ${messageTypes.CREATE_SUB_THREAD} + LEFT JOIN memberships stm ON m.type = ${ + messageTypes.CREATE_SUB_THREAD + } AND stm.thread = m.content WHERE JSON_EXTRACT(stm.permissions, ${visibleExtractString}) IS TRUE - AND m.thread = ${genesis.id} + AND m.thread = ${genesis().id} GROUP BY m.thread, stm.user ) last_subthread_message_for_user_query ON mm.thread = last_subthread_message_for_user_query.thread @@ -613,7 +615,7 @@ SET mm.last_message = GREATEST(COALESCE(all_users_query.message, 0), COALESCE(last_subthread_message_for_user_query.message, 0)) - WHERE mm.thread = ${genesis.id}; + WHERE mm.thread = ${genesis().id}; `; await dbQuery(query); }, diff --git a/keyserver/src/database/setup-db.js b/keyserver/src/database/setup-db.js --- a/keyserver/src/database/setup-db.js +++ b/keyserver/src/database/setup-db.js @@ -447,7 +447,7 @@ const insertIDsPromise = dbQuery(SQL` INSERT INTO ids (id, table_name) VALUES - (${genesis.id}, 'threads'), + (${genesis().id}, 'threads'), (${bots.commbot.staffThreadID}, 'threads') `); @@ -455,10 +455,10 @@ const createGenesisPromise = createThread( ashoatViewer, { - id: genesis.id, + id: genesis().id, type: threadTypes.GENESIS, - name: genesis.name, - description: genesis.description, + name: genesis().name, + description: genesis().description, initialMemberIDs: [bots.commbot.userID], }, createThreadOptions, diff --git a/keyserver/src/fetchers/thread-permission-fetchers.js b/keyserver/src/fetchers/thread-permission-fetchers.js --- a/keyserver/src/fetchers/thread-permission-fetchers.js +++ b/keyserver/src/fetchers/thread-permission-fetchers.js @@ -305,7 +305,7 @@ ignoreMembers.add(memberID); continue; } - const isParentThreadGenesis = params.parentThreadID === genesis.id; + const isParentThreadGenesis = params.parentThreadID === genesis().id; if ( (memberOfContainingThread.get(memberID) === 'no-containing-thread' || isParentThreadGenesis) && diff --git a/keyserver/src/updaters/thread-permission-updaters.js b/keyserver/src/updaters/thread-permission-updaters.js --- a/keyserver/src/updaters/thread-permission-updaters.js +++ b/keyserver/src/updaters/thread-permission-updaters.js @@ -119,7 +119,7 @@ FROM threads t INNER JOIN memberships pm ON pm.thread = t.parent_thread_id WHERE t.id = ${threadID} AND - (pm.user IN (${userIDs}) OR t.parent_thread_id != ${genesis.id}) + (pm.user IN (${userIDs}) OR t.parent_thread_id != ${genesis().id}) `; const containingMembershipQuery = SQL` SELECT cm.user, cm.role AS containing_role @@ -196,13 +196,13 @@ const relationshipChangeset = new RelationshipChangeset(); const existingMemberIDs = [...existingMembershipInfo.keys()]; - if (threadID !== genesis.id) { + if (threadID !== genesis().id) { relationshipChangeset.setAllRelationshipsExist(existingMemberIDs); } const parentMemberIDs = parentMembershipResults.map(row => row.user.toString(), ); - if (parentThreadID && parentThreadID !== genesis.id) { + if (parentThreadID && parentThreadID !== genesis().id) { relationshipChangeset.setAllRelationshipsExist(parentMemberIDs); } @@ -302,7 +302,7 @@ }); } - if (permissions && !existingMembership && threadID !== genesis.id) { + if (permissions && !existingMembership && threadID !== genesis().id) { relationshipChangeset.setRelationshipsNeeded(userID, existingMemberIDs); } @@ -452,7 +452,7 @@ const existingMemberIDs = existingMembers .filter(([, { curRole }]) => curRole) .map(([userID]) => userID); - if (threadID !== genesis.id) { + if (threadID !== genesis().id) { relationshipChangeset.setAllRelationshipsExist(existingMemberIDs); } @@ -529,7 +529,7 @@ }); } - if (permissions && !existingMembership && threadID !== genesis.id) { + if (permissions && !existingMembership && threadID !== genesis().id) { // If there was no membership row before, and we are creating one, // we'll need to make sure the new member has a relationship row with // each existing member. We expect that whoever called us already @@ -803,13 +803,13 @@ const relationshipChangeset = new RelationshipChangeset(); const existingMemberIDs = membershipResults.map(row => row.user.toString()); - if (threadID !== genesis.id) { + if (threadID !== genesis().id) { relationshipChangeset.setAllRelationshipsExist(existingMemberIDs); } const parentMemberIDs = parentMembershipResults.map(row => row.user.toString(), ); - if (parentThreadID && parentThreadID !== genesis.id) { + if (parentThreadID && parentThreadID !== genesis().id) { relationshipChangeset.setAllRelationshipsExist(parentMemberIDs); } @@ -870,7 +870,7 @@ }); } - if (permissions && !existingMembership && threadID !== genesis.id) { + if (permissions && !existingMembership && threadID !== genesis().id) { // If there was no membership row before, and we are creating one, // we'll need to make sure the new member has a relationship row with // each existing member. We handle guaranteeing that new members have @@ -1160,7 +1160,7 @@ savedUsers.push(userID); } for (const [threadID, savedUsers] of threadsToSavedUsers) { - if (threadID !== genesis.id) { + if (threadID !== genesis().id) { relationshipChangeset.setAllRelationshipsNeeded(savedUsers); } } diff --git a/lib/actions/thread-actions.js b/lib/actions/thread-actions.js --- a/lib/actions/thread-actions.js +++ b/lib/actions/thread-actions.js @@ -208,7 +208,7 @@ callKeyserverEndpoint: CallKeyserverEndpoint, ): ((input: ClientNewThreadRequest) => Promise) => async input => { - const parentThreadID = input.parentThreadID ?? genesis.id; + const parentThreadID = input.parentThreadID ?? genesis().id; const keyserverID = extractKeyserverIDFromID(parentThreadID); const requests = { [keyserverID]: input }; diff --git a/lib/components/chat-mention-provider.react.js b/lib/components/chat-mention-provider.react.js --- a/lib/components/chat-mention-provider.react.js +++ b/lib/components/chat-mention-provider.react.js @@ -47,7 +47,7 @@ const getChatMentionSearchIndex = React.useCallback( (threadInfo: ThreadInfo) => { - if (threadInfo.community === genesis.id) { + if (threadInfo.community === genesis().id) { const communityThreadID = getCommunityThreadIDForGenesisThreads(threadInfo); return searchIndices[communityThreadID]; @@ -170,7 +170,7 @@ lastThreadInTraversePath.type !== threadTypes.PERSONAL && lastThreadInTraversePath.type !== threadTypes.PRIVATE ) { - result[genesis.id][lastThreadInTraversePath.id] = { + result[genesis().id][lastThreadInTraversePath.id] = { threadInfo: lastThreadInTraversePath, rawChatName: threadInfos[lastThreadInTraversePath.id].uiName, }; diff --git a/lib/facts/genesis.js b/lib/facts/genesis.js --- a/lib/facts/genesis.js +++ b/lib/facts/genesis.js @@ -1,5 +1,7 @@ // @flow +import { authoritativeKeyserverID } from '../utils/authoritative-keyserver.js'; + type Genesis = { +id: string, +name: string, @@ -7,8 +9,8 @@ +introMessages: $ReadOnlyArray, }; -const genesis: Genesis = { - id: process.env['KEYSERVER'] ? '1' : '256|1', +const genesis: () => Genesis = () => ({ + id: process.env['KEYSERVER'] ? '1' : `${authoritativeKeyserverID()}|1`, name: 'GENESIS', description: 'This is the first community on Comm. In the future it will be possible to create chats outside of a community, but for now all of these chats get set with GENESIS as their parent. GENESIS is hosted on Ashoat’s keyserver.', @@ -18,6 +20,6 @@ 'this is meant to be temporary. we’re working on support for chats that can exist outside of any community, as well as support for user-hosted communities', 'to learn more about our roadmap and how Genesis fits in, check out [this document](https://www.notion.so/Comm-Genesis-1059f131fb354250abd1966894b15951)', ], -}; +}); export default genesis; diff --git a/lib/hooks/chat-mention-hooks.js b/lib/hooks/chat-mention-hooks.js --- a/lib/hooks/chat-mention-hooks.js +++ b/lib/hooks/chat-mention-hooks.js @@ -29,7 +29,7 @@ return React.useMemo(() => { const communityID = - threadInfo.community === genesis.id + threadInfo.community === genesis().id ? communityThreadIDForGenesisThreads : threadInfo.community ?? threadInfo.id; diff --git a/lib/selectors/thread-selectors.js b/lib/selectors/thread-selectors.js --- a/lib/selectors/thread-selectors.js +++ b/lib/selectors/thread-selectors.js @@ -453,7 +453,7 @@ const rawThreadInfo = rawThreadInfos[threadID]; if ( threadIsPending(threadID) || - (rawThreadInfo.parentThreadID !== genesis.id && + (rawThreadInfo.parentThreadID !== genesis().id && rawThreadInfo.type !== threadTypes.SIDEBAR) ) { continue; diff --git a/lib/shared/ancestor-threads.js b/lib/shared/ancestor-threads.js --- a/lib/shared/ancestor-threads.js +++ b/lib/shared/ancestor-threads.js @@ -17,7 +17,7 @@ const ancestorThreads = useSelector(ancestorThreadInfos(threadInfo.id)); const genesisThreadInfo = useSelector( - state => threadInfoSelector(state)[genesis.id], + state => threadInfoSelector(state)[genesis().id], ); return React.useMemo(() => { diff --git a/lib/shared/avatar-utils.js b/lib/shared/avatar-utils.js --- a/lib/shared/avatar-utils.js +++ b/lib/shared/avatar-utils.js @@ -306,7 +306,7 @@ return thread.avatar; } - if (containingThreadInfo && containingThreadInfo.id !== genesis.id) { + if (containingThreadInfo && containingThreadInfo.id !== genesis().id) { return containingThreadInfo.avatar ? containingThreadInfo.avatar : getDefaultAvatar(containingThreadInfo.id, containingThreadInfo.color); diff --git a/lib/shared/search-utils.js b/lib/shared/search-utils.js --- a/lib/shared/search-utils.js +++ b/lib/shared/search-utils.js @@ -107,14 +107,14 @@ const communityThreadInfo = React.useMemo( () => - inputCommunityThreadInfo && inputCommunityThreadInfo.id !== genesis.id + inputCommunityThreadInfo && inputCommunityThreadInfo.id !== genesis().id ? inputCommunityThreadInfo : null, [inputCommunityThreadInfo], ); const parentThreadInfo = React.useMemo( () => - inputParentThreadInfo && inputParentThreadInfo.id !== genesis.id + inputParentThreadInfo && inputParentThreadInfo.id !== genesis().id ? inputParentThreadInfo : null, [inputParentThreadInfo], diff --git a/lib/shared/thread-utils.js b/lib/shared/thread-utils.js --- a/lib/shared/thread-utils.js +++ b/lib/shared/thread-utils.js @@ -215,7 +215,7 @@ if (!threadInfo) { return false; } - if (threadInfo.id === genesis.id) { + if (threadInfo.id === genesis().id) { return true; } return threadInfo.members.some(member => member.id === userID && member.role); @@ -240,7 +240,7 @@ function threadMembersWithoutAddedAshoat< T: LegacyRawThreadInfo | RawThreadInfo | ThreadInfo, >(threadInfo: T): $PropertyType { - if (threadInfo.community !== genesis.id) { + if (threadInfo.community !== genesis().id) { return threadInfo.members; } return threadInfo.members.filter( @@ -801,7 +801,7 @@ let currentUser; for (const serverMember of serverThreadInfo.members) { if ( - serverThreadInfo.id === genesis.id && + serverThreadInfo.id === genesis().id && serverMember.id !== viewerID && serverMember.id !== ashoat.id ) { @@ -1168,7 +1168,7 @@ return 'thread'; } else if ( threadType === threadTypes.COMMUNITY_SECRET_SUBTHREAD && - parentThreadID === genesis.id + parentThreadID === genesis().id ) { return 'chat'; } else if ( diff --git a/native/chat/message-list-container.react.js b/native/chat/message-list-container.react.js --- a/native/chat/message-list-container.react.js +++ b/native/chat/message-list-container.react.js @@ -359,7 +359,7 @@ const measureMessages = useHeightMeasurer(); const genesisThreadInfo = useSelector( - state => threadInfoSelector(state)[genesis.id], + state => threadInfoSelector(state)[genesis().id], ); const bannerText = diff --git a/web/chat/chat-thread-list.react.js b/web/chat/chat-thread-list.react.js --- a/web/chat/chat-thread-list.react.js +++ b/web/chat/chat-thread-list.react.js @@ -103,7 +103,7 @@ ); }, [popModal, pushModal, communityThreadInfo]); - const isChatCreation = !communityID || communityID === genesis.id; + const isChatCreation = !communityID || communityID === genesis().id; const onClickCreate = isChatCreation ? onClickNewThread