2022-09-12 16:34:56 +00:00
|
|
|
import { filterDefined } from './util/array'
|
|
|
|
|
2022-01-10 21:07:57 +00:00
|
|
|
export type User = {
|
2022-01-10 23:52:03 +00:00
|
|
|
id: string
|
2022-01-18 07:18:38 +00:00
|
|
|
createdTime: number
|
|
|
|
|
2022-01-10 23:52:03 +00:00
|
|
|
name: string
|
|
|
|
username: string
|
2022-05-06 18:29:15 +00:00
|
|
|
avatarUrl?: string
|
2022-01-18 07:18:38 +00:00
|
|
|
|
2022-02-18 01:16:58 +00:00
|
|
|
// For their user page
|
|
|
|
bio?: string
|
|
|
|
bannerUrl?: string
|
|
|
|
website?: string
|
|
|
|
twitterHandle?: string
|
|
|
|
discordHandle?: string
|
|
|
|
|
2022-01-10 23:52:03 +00:00
|
|
|
balance: number
|
2022-01-19 03:36:46 +00:00
|
|
|
totalDeposits: number
|
2022-06-22 20:29:40 +00:00
|
|
|
|
|
|
|
profitCached: {
|
|
|
|
daily: number
|
|
|
|
weekly: number
|
|
|
|
monthly: number
|
|
|
|
allTime: number
|
|
|
|
}
|
|
|
|
|
|
|
|
creatorVolumeCached: {
|
|
|
|
daily: number
|
|
|
|
weekly: number
|
|
|
|
monthly: number
|
|
|
|
allTime: number
|
|
|
|
}
|
2022-05-12 15:07:10 +00:00
|
|
|
|
2022-08-22 05:22:49 +00:00
|
|
|
nextLoanCached: number
|
2022-06-22 16:05:54 +00:00
|
|
|
followerCountCached: number
|
|
|
|
|
2022-05-12 15:07:10 +00:00
|
|
|
followedCategories?: string[]
|
2022-09-12 05:39:04 +00:00
|
|
|
homeSections?: string[]
|
2022-07-01 13:47:19 +00:00
|
|
|
|
|
|
|
referredByUserId?: string
|
|
|
|
referredByContractId?: string
|
2022-07-18 16:40:44 +00:00
|
|
|
referredByGroupId?: string
|
2022-07-15 14:45:52 +00:00
|
|
|
lastPingTime?: number
|
2022-07-30 07:50:03 +00:00
|
|
|
shouldShowWelcome?: boolean
|
2022-08-19 17:10:32 +00:00
|
|
|
lastBetTime?: number
|
|
|
|
currentBettingStreak?: number
|
2022-08-24 16:49:53 +00:00
|
|
|
hasSeenContractFollowModal?: boolean
|
2022-08-25 11:51:56 +00:00
|
|
|
freeMarketsCreated?: number
|
2022-08-28 05:23:25 +00:00
|
|
|
isBannedFromPosting?: boolean
|
2022-01-10 23:52:03 +00:00
|
|
|
}
|
2022-01-18 07:18:38 +00:00
|
|
|
|
2022-01-19 03:36:46 +00:00
|
|
|
export type PrivateUser = {
|
|
|
|
id: string // same as User.id
|
|
|
|
username: string // denormalized from User
|
|
|
|
|
|
|
|
email?: string
|
|
|
|
unsubscribedFromResolutionEmails?: boolean
|
2022-02-23 01:35:25 +00:00
|
|
|
unsubscribedFromCommentEmails?: boolean
|
2022-02-23 06:05:04 +00:00
|
|
|
unsubscribedFromAnswerEmails?: boolean
|
2022-05-11 15:51:58 +00:00
|
|
|
unsubscribedFromGenericEmails?: boolean
|
2022-08-19 17:43:57 +00:00
|
|
|
unsubscribedFromWeeklyTrendingEmails?: boolean
|
2022-08-22 22:36:39 +00:00
|
|
|
weeklyTrendingEmailSent?: boolean
|
2022-08-04 18:03:02 +00:00
|
|
|
manaBonusEmailSent?: boolean
|
2022-01-19 03:36:46 +00:00
|
|
|
initialDeviceToken?: string
|
|
|
|
initialIpAddress?: string
|
2022-05-16 03:41:07 +00:00
|
|
|
apiKey?: string
|
2022-09-12 16:34:56 +00:00
|
|
|
/** @deprecated - use notificationSubscriptionTypes */
|
2022-06-06 17:36:59 +00:00
|
|
|
notificationPreferences?: notification_subscribe_types
|
2022-09-12 16:34:56 +00:00
|
|
|
notificationSubscriptionTypes: notification_subscription_types
|
2022-01-19 03:36:46 +00:00
|
|
|
}
|
2022-06-06 17:36:59 +00:00
|
|
|
|
2022-09-12 16:34:56 +00:00
|
|
|
export type notification_destination_types = 'email' | 'browser'
|
|
|
|
export type notification_subscription_types = {
|
|
|
|
// Watched Markets
|
|
|
|
all_comments_on_watched_markets: notification_destination_types[]
|
|
|
|
all_answers_on_watched_markets: notification_destination_types[]
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
tipped_comments_on_watched_markets: notification_destination_types[]
|
|
|
|
comments_by_followed_users_on_watched_markets: notification_destination_types[]
|
|
|
|
all_replies_to_my_comments_on_watched_markets: notification_destination_types[]
|
|
|
|
all_replies_to_my_answers_on_watched_markets: notification_destination_types[]
|
|
|
|
all_comments_on_contracts_with_shares_in_on_watched_markets: notification_destination_types[]
|
|
|
|
|
|
|
|
// Answers
|
|
|
|
answers_by_followed_users_on_watched_markets: notification_destination_types[]
|
|
|
|
answers_by_market_creator_on_watched_markets: notification_destination_types[]
|
|
|
|
all_answers_on_contracts_with_shares_in_on_watched_markets: notification_destination_types[]
|
|
|
|
|
|
|
|
// On users' markets
|
|
|
|
your_contract_closed: notification_destination_types[]
|
|
|
|
all_comments_on_my_markets: notification_destination_types[]
|
|
|
|
all_answers_on_my_markets: notification_destination_types[]
|
|
|
|
subsidized_your_market: notification_destination_types[]
|
|
|
|
|
|
|
|
// Market updates
|
|
|
|
resolutions_on_watched_markets: notification_destination_types[]
|
|
|
|
resolutions_on_watched_markets_with_shares_in: notification_destination_types[]
|
|
|
|
market_updates_on_watched_markets: notification_destination_types[]
|
|
|
|
market_updates_on_watched_markets_with_shares_in: notification_destination_types[]
|
|
|
|
probability_updates_on_watched_markets: notification_destination_types[]
|
|
|
|
|
|
|
|
// Balance Changes
|
|
|
|
loan_income: notification_destination_types[]
|
|
|
|
betting_streaks: notification_destination_types[]
|
|
|
|
referral_bonuses: notification_destination_types[]
|
|
|
|
unique_bettors_on_your_contract: notification_destination_types[]
|
|
|
|
tips_on_your_comments: notification_destination_types[]
|
|
|
|
tips_on_your_markets: notification_destination_types[]
|
|
|
|
limit_order_fills: notification_destination_types[]
|
|
|
|
|
|
|
|
// General
|
|
|
|
tagged_user: notification_destination_types[]
|
|
|
|
on_new_follow: notification_destination_types[]
|
|
|
|
contract_from_followed_user: notification_destination_types[]
|
|
|
|
trending_markets: notification_destination_types[]
|
|
|
|
profit_loss_updates: notification_destination_types[]
|
|
|
|
onboarding_flow: notification_destination_types[]
|
|
|
|
thank_you_for_purchases: notification_destination_types[]
|
|
|
|
}
|
2022-06-06 17:36:59 +00:00
|
|
|
export type notification_subscribe_types = 'all' | 'less' | 'none'
|
2022-06-22 20:29:40 +00:00
|
|
|
|
|
|
|
export type PortfolioMetrics = {
|
|
|
|
investmentValue: number
|
|
|
|
balance: number
|
|
|
|
totalDeposits: number
|
|
|
|
timestamp: number
|
|
|
|
userId: string
|
|
|
|
}
|
2022-07-15 17:53:30 +00:00
|
|
|
|
|
|
|
export const MANIFOLD_USERNAME = 'ManifoldMarkets'
|
|
|
|
export const MANIFOLD_AVATAR_URL = 'https://manifold.markets/logo-bg-white.png'
|
2022-09-12 16:34:56 +00:00
|
|
|
|
|
|
|
export const getDefaultNotificationSettings = (
|
|
|
|
userId: string,
|
|
|
|
privateUser?: PrivateUser,
|
|
|
|
noEmails?: boolean
|
|
|
|
) => {
|
|
|
|
const prevPref = privateUser?.notificationPreferences ?? 'all'
|
|
|
|
const wantsLess = prevPref === 'less'
|
|
|
|
const wantsAll = prevPref === 'all'
|
|
|
|
const {
|
|
|
|
unsubscribedFromCommentEmails,
|
|
|
|
unsubscribedFromAnswerEmails,
|
|
|
|
unsubscribedFromResolutionEmails,
|
|
|
|
unsubscribedFromWeeklyTrendingEmails,
|
|
|
|
unsubscribedFromGenericEmails,
|
|
|
|
} = privateUser || {}
|
|
|
|
|
|
|
|
const constructPref = (browserIf: boolean, emailIf: boolean) => {
|
|
|
|
const browser = browserIf ? 'browser' : undefined
|
|
|
|
const email = noEmails ? undefined : emailIf ? 'email' : undefined
|
|
|
|
return filterDefined([browser, email]) as notification_destination_types[]
|
|
|
|
}
|
|
|
|
return {
|
|
|
|
// Watched Markets
|
|
|
|
all_comments_on_watched_markets: constructPref(
|
|
|
|
wantsAll,
|
|
|
|
!unsubscribedFromCommentEmails
|
|
|
|
),
|
|
|
|
all_answers_on_watched_markets: constructPref(
|
|
|
|
wantsAll,
|
|
|
|
!unsubscribedFromAnswerEmails
|
|
|
|
),
|
|
|
|
|
|
|
|
// Comments
|
|
|
|
tips_on_your_comments: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromCommentEmails
|
|
|
|
),
|
|
|
|
comments_by_followed_users_on_watched_markets: constructPref(
|
|
|
|
wantsAll,
|
|
|
|
false
|
|
|
|
),
|
|
|
|
all_replies_to_my_comments_on_watched_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromCommentEmails
|
|
|
|
),
|
|
|
|
all_replies_to_my_answers_on_watched_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromCommentEmails
|
|
|
|
),
|
|
|
|
all_comments_on_contracts_with_shares_in_on_watched_markets: constructPref(
|
|
|
|
wantsAll,
|
|
|
|
!unsubscribedFromCommentEmails
|
|
|
|
),
|
|
|
|
|
|
|
|
// Answers
|
|
|
|
answers_by_followed_users_on_watched_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromAnswerEmails
|
|
|
|
),
|
|
|
|
answers_by_market_creator_on_watched_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromAnswerEmails
|
|
|
|
),
|
|
|
|
all_answers_on_contracts_with_shares_in_on_watched_markets: constructPref(
|
|
|
|
wantsAll,
|
|
|
|
!unsubscribedFromAnswerEmails
|
|
|
|
),
|
|
|
|
|
|
|
|
// On users' markets
|
|
|
|
your_contract_closed: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromResolutionEmails
|
|
|
|
), // High priority
|
|
|
|
all_comments_on_my_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromCommentEmails
|
|
|
|
),
|
|
|
|
all_answers_on_my_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromAnswerEmails
|
|
|
|
),
|
|
|
|
subsidized_your_market: constructPref(wantsAll || wantsLess, true),
|
|
|
|
|
|
|
|
// Market updates
|
|
|
|
resolutions_on_watched_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromResolutionEmails
|
|
|
|
),
|
|
|
|
market_updates_on_watched_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
false
|
|
|
|
),
|
|
|
|
market_updates_on_watched_markets_with_shares_in: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
false
|
|
|
|
),
|
|
|
|
resolutions_on_watched_markets_with_shares_in: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromResolutionEmails
|
|
|
|
),
|
|
|
|
|
|
|
|
//Balance Changes
|
|
|
|
loan_income: constructPref(wantsAll || wantsLess, false),
|
|
|
|
betting_streaks: constructPref(wantsAll || wantsLess, false),
|
|
|
|
referral_bonuses: constructPref(wantsAll || wantsLess, true),
|
|
|
|
unique_bettors_on_your_contract: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
false
|
|
|
|
),
|
|
|
|
tipped_comments_on_watched_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
!unsubscribedFromCommentEmails
|
|
|
|
),
|
|
|
|
tips_on_your_markets: constructPref(wantsAll || wantsLess, true),
|
|
|
|
limit_order_fills: constructPref(wantsAll || wantsLess, false),
|
|
|
|
|
|
|
|
// General
|
|
|
|
tagged_user: constructPref(wantsAll || wantsLess, true),
|
|
|
|
on_new_follow: constructPref(wantsAll || wantsLess, true),
|
|
|
|
contract_from_followed_user: constructPref(wantsAll || wantsLess, true),
|
|
|
|
trending_markets: constructPref(
|
|
|
|
false,
|
|
|
|
!unsubscribedFromWeeklyTrendingEmails
|
|
|
|
),
|
|
|
|
profit_loss_updates: constructPref(false, true),
|
|
|
|
probability_updates_on_watched_markets: constructPref(
|
|
|
|
wantsAll || wantsLess,
|
|
|
|
false
|
|
|
|
),
|
|
|
|
thank_you_for_purchases: constructPref(
|
|
|
|
false,
|
|
|
|
!unsubscribedFromGenericEmails
|
|
|
|
),
|
|
|
|
onboarding_flow: constructPref(false, !unsubscribedFromGenericEmails),
|
|
|
|
} as notification_subscription_types
|
|
|
|
}
|