forked from manifoldmarkets/manifold
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notification.ts
434 lines (414 loc) · 12.5 KB
/
notification.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
import { OutcomeType } from 'common/contract'
import { groupPath } from './group'
import { PAST_BET } from './user'
import { notification_preference } from './user-notification-preferences'
import { Bet } from 'common/bet'
import { league_user_info } from './leagues'
export type Notification = {
id: string
userId: string
reasonText?: string
reason: NotificationReason
createdTime: number
viewTime?: number
isSeen: boolean
sourceId: string
sourceType: notification_source_types
sourceUpdateType?: notification_source_update_types
// sourceContractId is used to group notifications on the same contract together
sourceContractId?: string
sourceUserName: string
sourceUserUsername: string
sourceUserAvatarUrl: string
sourceText: string
data?: { [key: string]: any }
sourceContractTitle?: string
sourceContractCreatorUsername?: string
sourceContractSlug?: string
sourceSlug?: string
sourceTitle?: string
isSeenOnHref?: string
}
export type NotificationReason =
| notification_reason_types
| notification_preference
export type notification_source_types =
| 'contract'
| 'comment'
| 'bet'
| 'answer'
| 'liquidity'
| 'follow'
| 'tip'
| 'admin_message'
| 'group'
| 'user'
| 'bonus' // strictly unique bettor bonuses atm
| 'challenge'
| 'betting_streak_bonus'
| 'betting_streak_expiring'
| 'loan'
| 'tip_and_like'
| 'badge'
| 'signup_bonus'
| 'comment_like'
| 'contract_like'
| 'weekly_portfolio_update'
| 'quest_reward'
| 'league_change'
| 'bounty_added'
| 'mana_payment'
| 'referral_program'
| 'follow_suggestion'
| 'market_review'
| 'comment_on_lover'
| 'new_match'
export type notification_source_update_types =
| 'created'
| 'updated'
| 'resolved'
| 'deleted'
| 'closed'
/** @deprecated - use a notification_preference (in user-notification-preferences.ts) */
export type notification_reason_types =
| 'tagged_user'
| 'on_new_follow'
| 'contract_from_followed_user'
| 'contract_from_private_group'
| 'you_referred_user'
| 'user_joined_to_bet_on_your_market'
| 'unique_bettors_on_your_contract'
| 'bet_fill'
| 'limit_order_cancelled'
| 'user_joined_from_your_group_invite'
| 'betting_streak_incremented'
| 'loan_income'
| 'comment_on_your_contract'
| 'answer_on_your_contract'
| 'comment_on_contract_you_follow'
| 'answer_on_contract_you_follow'
| 'update_on_contract_you_follow'
| 'resolution_on_contract_you_follow'
| 'comment_on_contract_with_users_shares_in'
| 'answer_on_contract_with_users_shares_in'
| 'update_on_contract_with_users_shares_in'
| 'resolution_on_contract_with_users_shares_in'
| 'comment_on_contract_with_users_answer'
| 'update_on_contract_with_users_answer'
| 'resolution_on_contract_with_users_answer'
| 'answer_on_contract_with_users_answer'
| 'comment_on_contract_with_users_comment'
| 'answer_on_contract_with_users_comment'
| 'update_on_contract_with_users_comment'
| 'resolution_on_contract_with_users_comment'
| 'reply_to_users_answer'
| 'reply_to_users_comment'
| 'your_contract_closed'
| 'subsidized_your_market'
| 'group_role_changed'
| 'added_to_group'
| 'bounty_awarded'
| 'bounty_added'
| 'mana_payment_received'
| 'poll_you_follow_closed'
| 'your_poll_closed'
type notification_descriptions = {
[key in notification_preference]: {
simple: string
detailed: string
necessary?: boolean
verb?: string
}
}
export const NOTIFICATION_DESCRIPTIONS: notification_descriptions = {
all_answers_on_my_markets: {
simple: 'Answers on your questions',
detailed: 'Answers on your own questions',
verb: 'answered your question',
},
all_comments_on_my_markets: {
simple: 'Comments on your questions',
detailed: 'Comments on your own questions',
verb: 'commented on your market',
},
betting_streaks: {
simple: `Prediction streak bonuses & expirations`,
detailed: `Bonuses and expiration notices for prediction streaks made over consecutive days`,
},
quest_payout: {
simple: `Quest completion rewards`,
detailed: `Bonuses paid out for completing quests`,
},
contract_from_followed_user: {
simple: 'New questions from users you follow',
detailed: 'New questions from users you follow',
},
contract_from_private_group: {
simple: 'New questions from private groups',
detailed: 'New questions from private groups you are a member of',
},
limit_order_fills: {
simple: 'Limit order fills',
detailed: 'When your limit order is filled by another user',
},
loan_income: {
simple: 'Automatic loans from your predictions in unresolved questions',
detailed:
'Automatic loans from your predictions that are locked in unresolved questions',
},
market_updates_on_watched_markets: {
simple: 'All creator updates',
detailed: 'All market updates made by the creator',
},
market_updates_on_watched_markets_with_shares_in: {
simple: `Only creator updates on questions that you've ${PAST_BET}`,
detailed: `Only updates made by the creator on questions that you've ${PAST_BET}`,
},
on_new_follow: {
simple: 'A user followed you',
detailed: 'A user followed you',
},
onboarding_flow: {
simple: 'Emails to help you get started using Manifold',
detailed: 'Emails to help you learn how to use Manifold',
},
probability_updates_on_watched_markets: {
simple: 'Large changes in probability on questions that you watch',
detailed: 'Large changes in probability on questions that you watch',
},
profit_loss_updates: {
simple: 'Weekly portfolio updates',
detailed: 'Weekly portfolio updates',
},
referral_bonuses: {
simple: 'Referring new users',
detailed: 'Bonuses you receive from referring a new user',
},
resolutions_on_watched_markets: {
simple: 'All question resolutions',
detailed: "All resolutions on questions that you're watching",
},
resolutions_on_watched_markets_with_shares_in: {
simple: `Only question resolutions that you've ${PAST_BET}`,
detailed: `Only resolutions of questions you're watching and that you've ${PAST_BET}`,
},
subsidized_your_market: {
simple: 'Your question was subsidized',
detailed: 'When someone subsidizes your market',
},
tagged_user: {
simple: 'A user tagged you',
detailed: 'When another use tags you',
verb: 'tagged you',
},
league_changed: {
simple: 'Your league changed',
detailed: 'When you join, move up, or move down a league',
},
thank_you_for_purchases: {
simple: 'Thank you notes for your purchases',
detailed: 'Thank you notes for your purchases',
},
trending_markets: {
simple: 'Weekly interesting questions',
detailed: 'Weekly interesting questions',
},
unique_bettors_on_your_contract: {
simple: 'Unique predictors on your questions',
detailed: 'Bonuses for unique predictors on your questions',
},
your_contract_closed: {
simple: 'Your question has closed and you need to resolve it (necessary)',
detailed: 'Your question has closed and you need to resolve it (necessary)',
necessary: true,
},
all_comments_on_watched_markets: {
simple: 'All new comments',
detailed: 'All new comments on questions you follow',
},
all_comments_on_contracts_with_shares_in_on_watched_markets: {
simple: `Only on questions you've ${PAST_BET}`,
detailed: `Comments on questions that you're watching and you've ${PAST_BET}`,
},
all_replies_to_my_comments_on_watched_markets: {
simple: 'Only replies to your comments',
detailed: "Only replies to your comments on questions you're watching",
verb: 'replied to you',
},
all_replies_to_my_answers_on_watched_markets: {
simple: 'Only replies to your answers',
detailed: "Only replies to your answers on questions you're watching",
verb: 'replied to you',
},
all_answers_on_watched_markets: {
simple: 'All new answers',
detailed: "All new answers on questions you're watching",
},
all_answers_on_contracts_with_shares_in_on_watched_markets: {
simple: `Only on questions you've ${PAST_BET}`,
detailed: `Answers on questions that you're watching and that you've ${PAST_BET}`,
},
opt_out_all: {
simple: 'Opt out of all notifications (excludes when your questions close)',
detailed:
'Opt out of all notifications excluding your own question closure notifications',
},
user_liked_your_content: {
simple: 'A user liked your content',
detailed: 'A user liked your comment, market, or other content',
},
group_role_changed: {
simple: 'Changes in group roles',
detailed: 'Changes to your role in groups you are a member of',
},
added_to_group: {
simple: 'Getting added to new groups',
detailed: 'When an admin adds you to their group',
},
bounty_awarded: {
simple: 'Bounties you receive',
detailed: 'When the creator awards you a bounty for your comment',
},
bounty_added: {
simple: 'Bounties added to your question',
detailed: 'When another user adds a bounty to your question',
},
all_votes_on_watched_markets: {
simple: 'Votes on polls you follow',
detailed: 'When a user votes on a poll you follow',
},
vote_on_your_contract: {
simple: 'Votes on your polls',
detailed: 'When a user votes on a poll you created',
},
poll_close_on_watched_markets: {
simple: 'Polls you follow close',
detailed: 'When a poll you follow closes',
},
your_poll_closed: {
simple: 'Your poll closes',
detailed: 'When a poll you created closes',
},
review_on_your_market: {
simple: 'Reviews on your questions',
detailed: 'When a user reviews your question after resolution',
},
}
export type BettingStreakData = {
streak: number
bonusAmount: number
}
export type LeagueChangeData = {
previousLeague: league_user_info | undefined
newLeague: { season: number; division: number; cohort: string }
bonusAmount: number
}
export type BetFillData = {
betOutcome: string
betAnswer?: string
creatorOutcome: string
probability: number
fillAmount: number
limitOrderTotal?: number
limitOrderRemaining?: number
limitAt?: string
outcomeType?: OutcomeType
}
export type ContractResolutionData = {
outcome: string
userPayout: number
userInvestment: number
profitRank?: number
totalShareholders?: number
profit?: number
answerId?: string
}
export type UniqueBettorData = {
bet: Bet
outcomeType: OutcomeType
answerText?: string
min?: number
max?: number
isLogScale?: boolean
}
export type ReviewNotificationData = {
rating: number
review: string
}
export function getSourceIdForLinkComponent(
sourceId: string,
sourceType?: notification_source_types
) {
switch (sourceType) {
case 'answer':
return `answer-${sourceId}`
case 'comment':
return sourceId
case 'contract':
return ''
case 'bet':
return ''
default:
return sourceId
}
}
export function getSourceUrl(notification: Notification) {
const {
sourceType,
sourceId,
sourceUserUsername,
sourceContractCreatorUsername,
sourceContractSlug,
sourceSlug,
} = notification
if (sourceType === 'weekly_portfolio_update')
return `/week/${sourceUserUsername}/${sourceSlug}`
if (sourceType === 'follow') return `/${sourceUserUsername}`
if (sourceType === 'group' && sourceSlug) return `${groupPath(sourceSlug)}`
// User referral via contract:
if (
sourceContractCreatorUsername &&
sourceContractSlug &&
sourceType === 'user'
)
return `/${sourceContractCreatorUsername}/${sourceContractSlug}`
// User referral:
if (sourceType === 'user' && !sourceContractSlug)
return `/${sourceUserUsername}`
if (
sourceType === 'challenge' ||
ReactionNotificationTypes.includes(sourceType)
)
return `${sourceSlug}`
if (sourceContractCreatorUsername && sourceContractSlug) {
return `/${sourceContractCreatorUsername}/${sourceContractSlug}#${getSourceIdForLinkComponent(
sourceId ?? '',
sourceType
)}`
}
if (sourceSlug) {
return `${
sourceSlug.startsWith('/') ? sourceSlug : '/' + sourceSlug
}#${getSourceIdForLinkComponent(sourceId ?? '', sourceType)}`
}
return ''
}
export const ReactionNotificationTypes: Partial<notification_source_types>[] = [
'comment_like',
'contract_like',
]
export const BalanceChangeNotificationTypes: NotificationReason[] = [
'loan_income',
// bonuses
'betting_streak_incremented',
'unique_bettors_on_your_contract',
// resolutions
'resolution_on_contract_with_users_shares_in',
// referrals
'you_referred_user',
'user_joined_to_bet_on_your_market',
'user_joined_from_your_group_invite',
'quest_payout',
'bet_fill',
'mana_payment_received',
]