2023-11-19 21:09:47 +00:00
import { hasDeleteMention } from './item'
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
export const toastDeleteScheduled = ( toaster , upsertResponseData , isEdit , itemText ) => {
const keys = Object . keys ( upsertResponseData )
const data = upsertResponseData [ keys [ 0 ] ]
if ( ! data ) return
const deleteScheduledAt = data . deleteScheduledAt ? new Date ( data . deleteScheduledAt ) : undefined
if ( deleteScheduledAt ) {
const itemType = {
upsertDiscussion : 'discussion post' ,
upsertLink : 'link post' ,
upsertPoll : 'poll' ,
upsertBounty : 'bounty' ,
upsertJob : 'job' ,
upsertComment : 'comment'
} [ keys [ 0 ] ] ? ? 'item'
const message = ` ${ itemType === 'comment' ? 'your comment' : isEdit ? ` this ${ itemType } ` : ` your new ${ itemType } ` } will be deleted at ${ deleteScheduledAt . toLocaleString ( ) } `
toaster . success ( message )
return
}
if ( hasDeleteMention ( itemText ) ) {
// There's a delete mention but the deletion wasn't scheduled
toaster . warning ( 'it looks like you tried to use the delete bot but it didn\'t work. make sure you use the correct format: "@delete in n units" e.g. "@delete in 2 hours"' , 10000 )
}
}