2022-09-12 16:34:56 +00:00
|
|
|
import { notification_subscription_types, PrivateUser } from './user'
|
|
|
|
import { DOMAIN } from './envs/constants'
|
|
|
|
|
2022-06-01 13:11:25 +00:00
|
|
|
export type Notification = {
|
|
|
|
id: string
|
|
|
|
userId: string
|
|
|
|
reasonText?: string
|
|
|
|
reason?: notification_reason_types
|
|
|
|
createdTime: number
|
|
|
|
viewTime?: number
|
|
|
|
isSeen: boolean
|
|
|
|
|
|
|
|
sourceId?: string
|
|
|
|
sourceType?: notification_source_types
|
2022-06-06 17:36:59 +00:00
|
|
|
sourceUpdateType?: notification_source_update_types
|
2022-06-01 13:11:25 +00:00
|
|
|
sourceContractId?: string
|
|
|
|
sourceUserName?: string
|
|
|
|
sourceUserUsername?: string
|
|
|
|
sourceUserAvatarUrl?: string
|
2022-06-08 14:43:24 +00:00
|
|
|
sourceText?: string
|
2022-09-14 13:27:20 +00:00
|
|
|
data?: { [key: string]: any }
|
2022-06-22 16:35:50 +00:00
|
|
|
|
2022-06-08 14:43:24 +00:00
|
|
|
sourceContractTitle?: string
|
|
|
|
sourceContractCreatorUsername?: string
|
|
|
|
sourceContractSlug?: string
|
2022-06-22 16:35:50 +00:00
|
|
|
|
|
|
|
sourceSlug?: string
|
|
|
|
sourceTitle?: string
|
2022-07-05 23:18:37 +00:00
|
|
|
|
|
|
|
isSeenOnHref?: string
|
2022-06-01 13:11:25 +00:00
|
|
|
}
|
|
|
|
export type notification_source_types =
|
|
|
|
| 'contract'
|
|
|
|
| 'comment'
|
|
|
|
| 'bet'
|
|
|
|
| 'answer'
|
|
|
|
| 'liquidity'
|
2022-06-06 17:36:59 +00:00
|
|
|
| 'follow'
|
|
|
|
| 'tip'
|
|
|
|
| 'admin_message'
|
2022-06-22 16:35:50 +00:00
|
|
|
| 'group'
|
2022-07-01 13:47:19 +00:00
|
|
|
| 'user'
|
2022-07-05 17:29:26 +00:00
|
|
|
| 'bonus'
|
2022-08-04 21:27:02 +00:00
|
|
|
| 'challenge'
|
2022-08-19 17:10:32 +00:00
|
|
|
| 'betting_streak_bonus'
|
2022-08-22 05:22:49 +00:00
|
|
|
| 'loan'
|
2022-08-30 15:38:59 +00:00
|
|
|
| 'like'
|
|
|
|
| 'tip_and_like'
|
2022-06-01 13:11:25 +00:00
|
|
|
|
2022-06-06 17:36:59 +00:00
|
|
|
export type notification_source_update_types =
|
2022-06-01 13:11:25 +00:00
|
|
|
| 'created'
|
|
|
|
| 'updated'
|
|
|
|
| 'resolved'
|
2022-06-06 17:36:59 +00:00
|
|
|
| 'deleted'
|
|
|
|
| 'closed'
|
|
|
|
|
2022-09-12 16:34:56 +00:00
|
|
|
/* Optional - if possible use a keyof notification_subscription_types */
|
2022-06-06 17:36:59 +00:00
|
|
|
export type notification_reason_types =
|
|
|
|
| 'tagged_user'
|
|
|
|
| 'on_new_follow'
|
2022-09-12 16:34:56 +00:00
|
|
|
| 'contract_from_followed_user'
|
2022-07-01 13:47:19 +00:00
|
|
|
| 'you_referred_user'
|
|
|
|
| 'user_joined_to_bet_on_your_market'
|
2022-07-05 17:29:26 +00:00
|
|
|
| 'unique_bettors_on_your_contract'
|
2022-07-06 19:30:51 +00:00
|
|
|
| 'tip_received'
|
2022-07-10 18:05:44 +00:00
|
|
|
| 'bet_fill'
|
2022-07-18 16:40:44 +00:00
|
|
|
| 'user_joined_from_your_group_invite'
|
2022-08-04 21:27:02 +00:00
|
|
|
| 'challenge_accepted'
|
2022-08-19 17:10:32 +00:00
|
|
|
| 'betting_streak_incremented'
|
2022-08-22 05:22:49 +00:00
|
|
|
| 'loan_income'
|
2022-08-30 15:38:59 +00:00
|
|
|
| 'liked_and_tipped_your_contract'
|
2022-09-12 16:34:56 +00:00
|
|
|
| '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'
|
|
|
|
|
|
|
|
// Adding a new key:value here is optional, you can just use a key of notification_subscription_types
|
|
|
|
// You might want to add a key:value here if there will be multiple notification reasons that map to the same
|
|
|
|
// subscription type, i.e. 'comment_on_contract_you_follow' and 'comment_on_contract_with_users_answer' both map to
|
|
|
|
// 'all_comments_on_watched_markets' subscription type
|
|
|
|
// TODO: perhaps better would be to map notification_subscription_types to arrays of notification_reason_types
|
|
|
|
export const notificationReasonToSubscriptionType: Partial<
|
|
|
|
Record<notification_reason_types, keyof notification_subscription_types>
|
|
|
|
> = {
|
|
|
|
you_referred_user: 'referral_bonuses',
|
|
|
|
user_joined_to_bet_on_your_market: 'referral_bonuses',
|
|
|
|
tip_received: 'tips_on_your_comments',
|
|
|
|
bet_fill: 'limit_order_fills',
|
|
|
|
user_joined_from_your_group_invite: 'referral_bonuses',
|
|
|
|
challenge_accepted: 'limit_order_fills',
|
|
|
|
betting_streak_incremented: 'betting_streaks',
|
|
|
|
liked_and_tipped_your_contract: 'tips_on_your_markets',
|
|
|
|
comment_on_your_contract: 'all_comments_on_my_markets',
|
|
|
|
answer_on_your_contract: 'all_answers_on_my_markets',
|
|
|
|
comment_on_contract_you_follow: 'all_comments_on_watched_markets',
|
|
|
|
answer_on_contract_you_follow: 'all_answers_on_watched_markets',
|
|
|
|
update_on_contract_you_follow: 'market_updates_on_watched_markets',
|
|
|
|
resolution_on_contract_you_follow: 'resolutions_on_watched_markets',
|
|
|
|
comment_on_contract_with_users_shares_in:
|
|
|
|
'all_comments_on_contracts_with_shares_in_on_watched_markets',
|
|
|
|
answer_on_contract_with_users_shares_in:
|
|
|
|
'all_answers_on_contracts_with_shares_in_on_watched_markets',
|
|
|
|
update_on_contract_with_users_shares_in:
|
|
|
|
'market_updates_on_watched_markets_with_shares_in',
|
|
|
|
resolution_on_contract_with_users_shares_in:
|
|
|
|
'resolutions_on_watched_markets_with_shares_in',
|
|
|
|
comment_on_contract_with_users_answer: 'all_comments_on_watched_markets',
|
|
|
|
update_on_contract_with_users_answer: 'market_updates_on_watched_markets',
|
|
|
|
resolution_on_contract_with_users_answer: 'resolutions_on_watched_markets',
|
|
|
|
answer_on_contract_with_users_answer: 'all_answers_on_watched_markets',
|
|
|
|
comment_on_contract_with_users_comment: 'all_comments_on_watched_markets',
|
|
|
|
answer_on_contract_with_users_comment: 'all_answers_on_watched_markets',
|
|
|
|
update_on_contract_with_users_comment: 'market_updates_on_watched_markets',
|
|
|
|
resolution_on_contract_with_users_comment: 'resolutions_on_watched_markets',
|
|
|
|
reply_to_users_answer: 'all_replies_to_my_answers_on_watched_markets',
|
|
|
|
reply_to_users_comment: 'all_replies_to_my_comments_on_watched_markets',
|
|
|
|
}
|
|
|
|
|
|
|
|
export const getDestinationsForUser = async (
|
|
|
|
privateUser: PrivateUser,
|
|
|
|
reason: notification_reason_types | keyof notification_subscription_types
|
|
|
|
) => {
|
2022-09-14 16:26:08 +00:00
|
|
|
const notificationSettings = privateUser.notificationPreferences
|
2022-09-12 16:34:56 +00:00
|
|
|
let destinations
|
|
|
|
let subscriptionType: keyof notification_subscription_types | undefined
|
|
|
|
if (Object.keys(notificationSettings).includes(reason)) {
|
|
|
|
subscriptionType = reason as keyof notification_subscription_types
|
|
|
|
destinations = notificationSettings[subscriptionType]
|
|
|
|
} else {
|
|
|
|
const key = reason as notification_reason_types
|
|
|
|
subscriptionType = notificationReasonToSubscriptionType[key]
|
|
|
|
destinations = subscriptionType
|
|
|
|
? notificationSettings[subscriptionType]
|
|
|
|
: []
|
|
|
|
}
|
2022-09-14 16:26:08 +00:00
|
|
|
// const unsubscribeEndpoint = getFunctionUrl('unsubscribe')
|
2022-09-12 16:34:56 +00:00
|
|
|
return {
|
|
|
|
sendToEmail: destinations.includes('email'),
|
|
|
|
sendToBrowser: destinations.includes('browser'),
|
2022-09-14 16:26:08 +00:00
|
|
|
// unsubscribeUrl: `${unsubscribeEndpoint}?id=${privateUser.id}&type=${subscriptionType}`,
|
2022-09-12 16:34:56 +00:00
|
|
|
urlToManageThisNotification: `${DOMAIN}/notifications?tab=settings§ion=${subscriptionType}`,
|
|
|
|
}
|
|
|
|
}
|
2022-09-14 13:27:20 +00:00
|
|
|
|
|
|
|
export type BettingStreakData = {
|
|
|
|
streak: number
|
|
|
|
bonusAmount: number
|
|
|
|
}
|