2024-05-19 20:52:02 +00:00
import { hasDeleteMention , hasReminderMention } from './item'
2023-11-19 21:09:47 +00:00
multiple forwards on a post (#403)
* multiple forwards on a post
first phase of the multi-forward support
* update the graphql mutation for discussion posts to accept and validate multiple forwards
* update the discussion form to allow multiple forwards in the UI
* start working on db schema changes
* uncomment db schema, add migration to create the new model, and update create_item, update_item
stored procedures
* Propagate updates from discussion to poll, link, and bounty forms
Update the create, update poll sql functions for multi forward support
* Update gql, typedefs, and resolver to return forwarded users in items responses
* UI changes to show multiple forward recipients, and conditional upvote logic changes
* Update notification text to reflect multiple forwards upon vote action
* Disallow duplicate stacker entries
* reduce duplication in populating adv-post-form initial values
* Update item_act sql function to implement multi-way forwarding
* Update referral functions to scale referral bonuses for forwarded users
* Update notification text to reflect non-100% forwarded sats cases
* Update wallet history sql queries to accommodate multi-forward use cases
* Block zaps for posts you are forwarded zaps at the API layer, in addition
to in the UI
* Delete fwdUserId column from Item table as part of migration
* Fix how we calculate stacked sats after partial forwards in wallet history
* Exclude entries from wallet history that are 0 stacked sats from posts with 100% forwarded to other users
* Fix wallet history query for forwarded stacked sats to be scaled by the fwd pct
* Reduce duplication in adv post form, and do some style tweaks for better layout
* Use MAX_FORWARDS constants
* Address various PR feedback
* first enhancement pass
* enhancement pass too
---------
Co-authored-by: keyan <keyan.kousha+huumn@gmail.com>
Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
2023-08-23 22:44:17 +00:00
/ * *
* Normalize an array of forwards by converting the pct from a string to a number
* Also extracts nym from nested user object , if necessary
* @ param { * } forward Array of forward objects ( { nym ? : string , pct : string , user ? : { name : string } } )
* @ returns normalized array , or undefined if not provided
* /
export const normalizeForwards = ( forward ) => {
if ( ! Array . isArray ( forward ) ) {
return undefined
}
return forward . filter ( fwd => fwd . nym || fwd . user ? . name ) . map ( fwd => ( { nym : fwd . nym ? ? fwd . user ? . name , pct : Number ( fwd . pct ) } ) )
}
2023-11-19 21:09:47 +00:00
2024-07-01 17:02:29 +00:00
export const toastUpsertSuccessMessages = ( toaster , upsertResponseData , dataKey , itemText ) => {
const SCHEDULERS = {
delete : {
hasMention : hasDeleteMention ,
scheduledAtKey : 'deleteScheduledAt' ,
mention : '@delete'
} ,
remindme : {
hasMention : hasReminderMention ,
scheduledAtKey : 'reminderScheduledAt' ,
mention : '@remindme'
}
2023-11-19 21:09:47 +00:00
}
2024-05-19 20:52:02 +00:00
2024-07-01 17:02:29 +00:00
for ( const key in SCHEDULERS ) {
const { hasMention , scheduledAtKey , mention } = SCHEDULERS [ key ]
if ( hasMention ( itemText ) ) {
const scheduledAt = upsertResponseData [ dataKey ] ? . result ? . [ scheduledAtKey ]
const options = { persistOnNavigate : dataKey !== 'upsertComment' }
if ( scheduledAt ) {
toaster . success ( ` ${ mention } bot will trigger at ${ new Date ( scheduledAt ) . toLocaleString ( ) } ` , options )
} else {
toaster . warning ( ` It looks like you tried to use the ${ mention } bot but it didn't work. Make sure you use the correct format: " ${ mention } in n units" e.g. " ${ mention } in 2 hours" ` , options )
}
}
2024-05-19 20:52:02 +00:00
}
}