Remove magic
This commit is contained in:
parent
5f58eb7982
commit
bb4dc54299
|
@ -45,7 +45,7 @@ export const createNotification = async (
|
||||||
) => {
|
) => {
|
||||||
const { contract: sourceContract, recipients, slug, title } = miscData ?? {}
|
const { contract: sourceContract, recipients, slug, title } = miscData ?? {}
|
||||||
|
|
||||||
const shouldGetNotification = (
|
const shouldReceiveNotification = (
|
||||||
userId: string,
|
userId: string,
|
||||||
userToReasonTexts: recipients_to_reason_texts
|
userToReasonTexts: recipients_to_reason_texts
|
||||||
) => {
|
) => {
|
||||||
|
@ -126,7 +126,7 @@ export const createNotification = async (
|
||||||
const followerUserId = doc.ref.parent.parent?.id
|
const followerUserId = doc.ref.parent.parent?.id
|
||||||
if (
|
if (
|
||||||
followerUserId &&
|
followerUserId &&
|
||||||
shouldGetNotification(followerUserId, userToReasonTexts)
|
shouldReceiveNotification(followerUserId, userToReasonTexts)
|
||||||
) {
|
) {
|
||||||
userToReasonTexts[followerUserId] = {
|
userToReasonTexts[followerUserId] = {
|
||||||
reason: 'contract_from_followed_user',
|
reason: 'contract_from_followed_user',
|
||||||
|
@ -135,50 +135,27 @@ export const createNotification = async (
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const notifyFollowedUser = (
|
|
||||||
userToReasonTexts: recipients_to_reason_texts,
|
|
||||||
followedUserId: string
|
|
||||||
) => {
|
|
||||||
if (shouldGetNotification(followedUserId, userToReasonTexts))
|
|
||||||
userToReasonTexts[followedUserId] = {
|
|
||||||
reason: 'on_new_follow',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
const notifyTaggedUsers = (
|
const notifyTaggedUsers = (
|
||||||
userToReasonTexts: recipients_to_reason_texts,
|
userToReasonTexts: recipients_to_reason_texts,
|
||||||
userIds: (string | undefined)[]
|
userIds: (string | undefined)[]
|
||||||
) => {
|
) => {
|
||||||
userIds.forEach((id) => {
|
userIds.forEach((id) => {
|
||||||
if (id && shouldGetNotification(id, userToReasonTexts))
|
if (id && shouldReceiveNotification(id, userToReasonTexts))
|
||||||
userToReasonTexts[id] = {
|
userToReasonTexts[id] = {
|
||||||
reason: 'tagged_user',
|
reason: 'tagged_user',
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
const notifyContractCreator = async (
|
|
||||||
userToReasonTexts: recipients_to_reason_texts,
|
|
||||||
sourceContract: Contract,
|
|
||||||
options?: { force: boolean }
|
|
||||||
) => {
|
|
||||||
if (
|
|
||||||
options?.force ||
|
|
||||||
shouldGetNotification(sourceContract.creatorId, userToReasonTexts)
|
|
||||||
)
|
|
||||||
userToReasonTexts[sourceContract.creatorId] = {
|
|
||||||
reason:
|
|
||||||
sourceType === 'liquidity'
|
|
||||||
? 'subsidized_your_market'
|
|
||||||
: 'your_contract_closed',
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// The following functions modify the userToReasonTexts object in place.
|
// The following functions modify the userToReasonTexts object in place.
|
||||||
const userToReasonTexts: recipients_to_reason_texts = {}
|
const userToReasonTexts: recipients_to_reason_texts = {}
|
||||||
|
|
||||||
if (sourceType === 'follow' && recipients?.[0]) {
|
if (sourceType === 'follow' && recipients?.[0]) {
|
||||||
notifyFollowedUser(userToReasonTexts, recipients[0])
|
if (shouldReceiveNotification(recipients[0], userToReasonTexts))
|
||||||
|
userToReasonTexts[recipients[0]] = {
|
||||||
|
reason: 'on_new_follow',
|
||||||
|
}
|
||||||
|
return await sendNotificationsIfSettingsPermit(userToReasonTexts)
|
||||||
} else if (
|
} else if (
|
||||||
sourceType === 'contract' &&
|
sourceType === 'contract' &&
|
||||||
sourceUpdateType === 'created' &&
|
sourceUpdateType === 'created' &&
|
||||||
|
@ -186,23 +163,27 @@ export const createNotification = async (
|
||||||
) {
|
) {
|
||||||
await notifyUsersFollowers(userToReasonTexts)
|
await notifyUsersFollowers(userToReasonTexts)
|
||||||
notifyTaggedUsers(userToReasonTexts, recipients ?? [])
|
notifyTaggedUsers(userToReasonTexts, recipients ?? [])
|
||||||
|
return await sendNotificationsIfSettingsPermit(userToReasonTexts)
|
||||||
} else if (
|
} else if (
|
||||||
sourceType === 'contract' &&
|
sourceType === 'contract' &&
|
||||||
sourceUpdateType === 'closed' &&
|
sourceUpdateType === 'closed' &&
|
||||||
sourceContract
|
sourceContract
|
||||||
) {
|
) {
|
||||||
await notifyContractCreator(userToReasonTexts, sourceContract, {
|
userToReasonTexts[sourceContract.creatorId] = {
|
||||||
force: true,
|
reason: 'your_contract_closed',
|
||||||
})
|
}
|
||||||
|
return await sendNotificationsIfSettingsPermit(userToReasonTexts)
|
||||||
} else if (
|
} else if (
|
||||||
sourceType === 'liquidity' &&
|
sourceType === 'liquidity' &&
|
||||||
sourceUpdateType === 'created' &&
|
sourceUpdateType === 'created' &&
|
||||||
sourceContract
|
sourceContract
|
||||||
) {
|
) {
|
||||||
await notifyContractCreator(userToReasonTexts, sourceContract)
|
if (shouldReceiveNotification(sourceContract.creatorId, userToReasonTexts))
|
||||||
|
userToReasonTexts[sourceContract.creatorId] = {
|
||||||
|
reason: 'subsidized_your_market',
|
||||||
|
}
|
||||||
|
return await sendNotificationsIfSettingsPermit(userToReasonTexts)
|
||||||
}
|
}
|
||||||
|
|
||||||
await sendNotificationsIfSettingsPermit(userToReasonTexts)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const createCommentOrAnswerOrUpdatedContractNotification = async (
|
export const createCommentOrAnswerOrUpdatedContractNotification = async (
|
||||||
|
|
|
@ -178,7 +178,8 @@ export const resolvemarket = newEndpoint(opts, async (req, auth) => {
|
||||||
} else if (contract.outcomeType === 'PSEUDO_NUMERIC') {
|
} else if (contract.outcomeType === 'PSEUDO_NUMERIC') {
|
||||||
if (resolutionText === 'MKT' && value) resolutionText = `${value}`
|
if (resolutionText === 'MKT' && value) resolutionText = `${value}`
|
||||||
}
|
}
|
||||||
console.log('resolutionText: ', resolutionText)
|
|
||||||
|
// TODO: this actually may be too slow to complete with a ton of users to notify?
|
||||||
await createCommentOrAnswerOrUpdatedContractNotification(
|
await createCommentOrAnswerOrUpdatedContractNotification(
|
||||||
contract.id,
|
contract.id,
|
||||||
'contract',
|
'contract',
|
||||||
|
|
Loading…
Reference in New Issue
Block a user