Skip to content

Commit 3fed979

Browse files
committed
Send experiment required to enable pomelo UI in discord client
1 parent 4d027a4 commit 3fed979

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

src/api/routes/experiments.ts

+16-2
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,28 @@
1616
along with this program. If not, see <https://www.gnu.org/licenses/>.
1717
*/
1818

19-
import { Router, Response, Request } from "express";
2019
import { route } from "@spacebar/api";
20+
import { Config, Experiments } from "@spacebar/util";
21+
import { Request, Response, Router } from "express";
2122

2223
const router = Router();
2324

2425
router.get("/", route({}), (req: Request, res: Response) => {
2526
// TODO:
26-
res.send({ fingerprint: "", assignments: [], guild_experiments: [] });
27+
const { uniqueUsernames } = Config.get().general;
28+
29+
const data: Experiments = {
30+
fingerprint: "fingerprint",
31+
assignments: [],
32+
guild_experiments: [],
33+
};
34+
// this enables the pomelo/unique usernames UI in the official clients
35+
if (uniqueUsernames) {
36+
// hash, revision, bucket, override, population, hash_result, as_mode
37+
// bucket 4 is used by the official client, and enables live checking and suggestions, 3 is only live checking
38+
data.assignments.push([2476969328, 0, 3, -1, 0, 9267, 0, 0]);
39+
}
40+
res.send(data);
2741
});
2842

2943
export default router;

src/util/interfaces/Experiments.ts

+36
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
Spacebar: A FOSS re-implementation and extension of the Discord.com backend.
3+
Copyright (C) 2023 Spacebar and Spacebar Contributors
4+
5+
This program is free software: you can redistribute it and/or modify
6+
it under the terms of the GNU Affero General Public License as published
7+
by the Free Software Foundation, either version 3 of the License, or
8+
(at your option) any later version.
9+
10+
This program is distributed in the hope that it will be useful,
11+
but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13+
GNU Affero General Public License for more details.
14+
15+
You should have received a copy of the GNU Affero General Public License
16+
along with this program. If not, see <https://www.gnu.org/licenses/>.
17+
*/
18+
19+
export type GuildExperiment = [
20+
number,
21+
string | null,
22+
number,
23+
unknown[],
24+
unknown[],
25+
unknown[],
26+
unknown | null,
27+
unknown | null,
28+
number,
29+
number,
30+
];
31+
32+
export interface Experiments {
33+
fingerprint: string;
34+
assignments: number[][];
35+
guild_experiments: GuildExperiment[];
36+
}

src/util/interfaces/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
export * from "./Activity";
2020
export * from "./ConnectedAccount";
2121
export * from "./Event";
22+
export * from "./Experiments";
2223
export * from "./GuildWelcomeScreen";
2324
export * from "./Interaction";
2425
export * from "./Presence";

0 commit comments

Comments
 (0)