-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make mechanism of moving users to the beta feature, separate between …
…games saved on frontend, games saved on backend and games shared (#2469) * Make mechanism of moving users to the beta feature, but it's not active yet, except for development and cosmin * remove console log * refactor code and use sha256Hash instead of custom hashing function * add function to move game to backend saving * add icons for backend saving and sharing * refactor code to remove most duplication * remove console log
- Loading branch information
1 parent
4821090
commit 9349ade
Showing
6 changed files
with
191 additions
and
166 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,9 +7,12 @@ import { lazy } from '../utils/lazy' | |
import { generateGameName } from '../words' | ||
import metrics from '../../../metrics' | ||
import { RoomParticipant } from '../state' | ||
import { sha256Hash } from "../../lib/codemirror/util"; | ||
|
||
const numberid = customAlphabet('0123456789') | ||
|
||
const whitelistedBetaCollabAndSavingStratEmails = ["[email protected]", "[email protected]", "[email protected]"] | ||
|
||
const app = lazy(() => { | ||
if (admin.apps.length === 0) { | ||
return initializeApp({ | ||
|
@@ -56,6 +59,7 @@ export interface Game { | |
code: string | ||
tutorialName?: string | ||
tutorialIndex?: number | ||
isSavedOnBackend?: boolean | ||
roomParticipants?: RoomParticipant[] | ||
isRoomOpen?: boolean | ||
password?: string | ||
|
@@ -253,7 +257,7 @@ export const getGame = async (id: string | undefined): Promise<Game | null> => { | |
return { id: _game.id, ..._game.data() } as Game | ||
} | ||
|
||
export const makeGame = async (ownerId: string, unprotected: boolean, name?: string, code?: string, tutorialName?: string, tutorialIndex?: number): Promise<Game> => { | ||
export const makeGame = async (ownerId: string, unprotected: boolean, name?: string, code?: string, tutorialName?: string, tutorialIndex?: number, isSavedOnBackend?: boolean): Promise<Game> => { | ||
|
||
const createdDate = Timestamp.now() | ||
const data = { | ||
|
@@ -264,7 +268,8 @@ export const makeGame = async (ownerId: string, unprotected: boolean, name?: str | |
name: name ?? generateGameName(), | ||
code: code ?? '', | ||
tutorialName: tutorialName ?? null, | ||
tutorialIndex: tutorialIndex ?? null | ||
tutorialIndex: tutorialIndex ?? null, | ||
isSavedOnBackend: isSavedOnBackend ?? false, | ||
} | ||
const _game = await addDocument('games', data); | ||
return { id: _game.id, ...data } as Game | ||
|
@@ -331,4 +336,27 @@ export const getSnapshotData = async (id: string): Promise<SnapshotData | null> | |
ownerName: user?.username ?? snapshot.ownerName, | ||
code: snapshot.code | ||
} | ||
} | ||
} | ||
|
||
export const updateUserGitHubToken = async (userId: string, githubAccessToken: string, githubId: string, githubUsername: string): Promise<void> => { | ||
await updateDocument('users', userId, { githubAccessToken, githubId, githubUsername }); | ||
} | ||
|
||
async function hashCodeToBigInt(string : string) : Promise<bigint>{ | ||
return BigInt(`0x${ await sha256Hash(string)}`); | ||
} | ||
|
||
export async function isAccountWhitelistedToUseCollabAndSavingBetaFeatures(id: string, email: string) : Promise<boolean>{ | ||
if(import.meta.env.PERCENT_OF_USERS_WHITELISTED_FOR_BETA_FEATURE == 0 || import.meta.env.PERCENT_OF_USERS_WHITELISTED_FOR_BETA_FEATURE == undefined) return false; | ||
let hashedId = await hashCodeToBigInt(id); | ||
|
||
if(hashedId % BigInt(100) < import.meta.env.PERCENT_OF_USERS_WHITELISTED_FOR_BETA_FEATURE || | ||
whitelistedBetaCollabAndSavingStratEmails.includes(email)){ | ||
return true | ||
} | ||
return false; | ||
} | ||
|
||
export const moveGameToBackendSaving = async (game: Game): Promise<Game> => { | ||
return makeGame(game.ownerId, game.unprotected, game.name, game.code, game.tutorialName, game.tutorialIndex, true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.