only add users to default server on first connection
This commit is contained in:
+17
-18
@@ -1,4 +1,4 @@
|
||||
import { schema, t, table, SenderError } from "spacetimedb/server";
|
||||
import { schema, t, table, SenderError, type ReducerCtx } from "spacetimedb/server";
|
||||
|
||||
const channel_kind = t.enum("ChannelKind", { Text: t.unit(), Voice: t.unit() });
|
||||
|
||||
@@ -1350,6 +1350,7 @@ export const onConnect = spacetimedb.clientConnected((ctx) => {
|
||||
banner_id: undefined,
|
||||
biography: undefined,
|
||||
});
|
||||
autoJoinCommunityServer(ctx);
|
||||
}
|
||||
} else if (user) {
|
||||
ctx.db.user.identity.update({ ...user, online: true });
|
||||
@@ -1366,26 +1367,24 @@ export const onConnect = spacetimedb.clientConnected((ctx) => {
|
||||
banner_id: undefined,
|
||||
biography: undefined,
|
||||
});
|
||||
}
|
||||
|
||||
// Auto-join the "Spacetime Community" server if it exists
|
||||
const communityServer = [...ctx.db.server.iter()].find(
|
||||
(s) => s.name === "Spacetime Community",
|
||||
);
|
||||
if (communityServer) {
|
||||
const alreadyMember = [
|
||||
...ctx.db.server_member.by_identity.filter(ctx.sender),
|
||||
].some((m) => m.server_id === communityServer.id);
|
||||
if (!alreadyMember) {
|
||||
ctx.db.server_member.insert({
|
||||
id: 0n,
|
||||
identity: ctx.sender,
|
||||
server_id: communityServer.id,
|
||||
});
|
||||
}
|
||||
autoJoinCommunityServer(ctx);
|
||||
}
|
||||
});
|
||||
|
||||
function autoJoinCommunityServer(ctx: any) {
|
||||
// Auto-join the "Zep" server if it exists
|
||||
const communityServer = [...ctx.db.server.iter()].find(
|
||||
(s) => s.name === "Zep",
|
||||
);
|
||||
if (communityServer) {
|
||||
ctx.db.server_member.insert({
|
||||
id: 0n,
|
||||
identity: ctx.sender,
|
||||
server_id: communityServer.id,
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
export const onDisconnect = spacetimedb.clientDisconnected((ctx) => {
|
||||
const user = ctx.db.user.identity.find(ctx.sender);
|
||||
if (user) {
|
||||
|
||||
Reference in New Issue
Block a user