Skip to content

Commit 28d0b35

Browse files
committed
Move discord move to create profile
1 parent f7f09cd commit 28d0b35

File tree

2 files changed

+44
-34
lines changed

2 files changed

+44
-34
lines changed

backend/api/src/create-profile.ts

Lines changed: 44 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { track } from 'shared/analytics'
77
import { updateUser } from 'shared/supabase/users'
88
import { tryCatch } from 'common/util/try-catch'
99
import { insert } from 'shared/supabase/utils'
10+
import {sendDiscordMessage} from "common/discord/core";
1011

1112
export const createProfile: APIHandler<'create-profile'> = async (body, auth) => {
1213
const pg = createSupabaseDirectClient()
@@ -40,7 +41,48 @@ export const createProfile: APIHandler<'create-profile'> = async (body, auth) =>
4041
}
4142

4243
log('Created user', data)
43-
await track(user.id, 'create profile', { username: user.username })
4444

45-
return data
45+
const continuation = async () => {
46+
try {
47+
await track(auth.uid, 'create profile', {username: user.username})
48+
} catch (e) {
49+
console.log('Failed to track create profile', e)
50+
}
51+
try {
52+
await sendDiscordMessage(
53+
`**${user.name}** just created a profile at https://www.compassmeet.com/${user.username}`,
54+
'members',
55+
)
56+
} catch (e) {
57+
console.log('Failed to send discord new profile', e)
58+
}
59+
try {
60+
const nProfiles = await pg.one<number>(
61+
`SELECT count(*) FROM users`,
62+
[],
63+
(r) => Number(r.count)
64+
)
65+
66+
const isMilestone = (n: number) => {
67+
return (
68+
[15, 20, 30, 40].includes(n) || // early milestones
69+
n % 50 === 0
70+
)
71+
}
72+
if (isMilestone(nProfiles)) {
73+
await sendDiscordMessage(
74+
`We just reached **${nProfiles}** total profiles! 🎉`,
75+
'general',
76+
)
77+
}
78+
79+
} catch (e) {
80+
console.log('Failed to send discord user milestone', e)
81+
}
82+
}
83+
84+
return {
85+
result: data,
86+
continue: continuation,
87+
}
4688
}

backend/api/src/create-user.ts

Lines changed: 0 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import {createSupabaseDirectClient} from 'shared/supabase/init'
1313
import {insert} from 'shared/supabase/utils'
1414
import {convertPrivateUser, convertUser} from 'common/supabase/users'
1515
import {getBucket} from "shared/firebase-utils";
16-
import {sendDiscordMessage} from "common/discord/core";
1716

1817
export const createUser: APIHandler<'create-user'> = async (
1918
props,
@@ -129,37 +128,6 @@ export const createUser: APIHandler<'create-user'> = async (
129128
} catch (e) {
130129
console.log('Failed to track create profile', e)
131130
}
132-
try {
133-
await sendDiscordMessage(
134-
`**${user.name}** just created a profile at https://www.compassmeet.com/${user.username}`,
135-
'members',
136-
)
137-
} catch (e) {
138-
console.log('Failed to send discord new user', e)
139-
}
140-
try {
141-
const nProfiles = await pg.one<number>(
142-
`SELECT count(*) FROM users`,
143-
[],
144-
(r) => Number(r.count)
145-
)
146-
147-
const isMilestone = (n: number) => {
148-
return (
149-
[15, 20, 30, 40].includes(n) || // early milestones
150-
n % 50 === 0
151-
)
152-
}
153-
if (isMilestone(nProfiles)) {
154-
await sendDiscordMessage(
155-
`We just reached **${nProfiles}** total profiles! 🎉`,
156-
'general',
157-
)
158-
}
159-
160-
} catch (e) {
161-
console.log('Failed to send discord user milestone', e)
162-
}
163131
}
164132

165133
return {

0 commit comments

Comments
 (0)