diff --git a/src/components/beneficiarySelectionContent/beneficiarySelectionContent.tsx b/src/components/beneficiarySelectionContent/beneficiarySelectionContent.tsx index dc9d41fff..2f883d7df 100644 --- a/src/components/beneficiarySelectionContent/beneficiarySelectionContent.tsx +++ b/src/components/beneficiarySelectionContent/beneficiarySelectionContent.tsx @@ -12,6 +12,7 @@ import { lookupAccounts } from '../../providers/hive/dhive'; import { setBeneficiaries as setBeneficiariesAction } from '../../redux/actions/editorActions'; import { TEMP_BENEFICIARIES_ID } from '../../redux/constants/constants'; import { Beneficiary } from '../../redux/reducers/editorReducer'; +import { BENEFICIARY_SRC_ENCODER } from '../../providers/speak/constants'; interface BeneficiarySelectionContentProps { draftId: string; @@ -59,9 +60,7 @@ const BeneficiarySelectionContent = ({ }, [powerDownBeneficiaries]); useEffect(() => { - if (draftId) { readTempBeneficiaries(); - } }, [draftId]); useEffect(() => { @@ -344,7 +343,7 @@ const BeneficiarySelectionContent = ({ wrapperStyle={styles.usernameFormInputWrapper} /> - {!_isCurrentUser ? ( + {!_isCurrentUser && item.src !== BENEFICIARY_SRC_ENCODER ? ( {isExtensionVisible && } { const intl = useIntl(); + const dispatch = useDispatch(); const deleteMediaMutation = editorQueries.useMediaDeleteMutation(); @@ -114,17 +119,48 @@ const UploadsGalleryContent = ({ } setDeleteIds([...deleteIds]); } else { - insertMedia(new Map([[index, true]])); + + let isUnpublishedInserted = false + if (item.speakData && item.speakData.status !== ThreeSpeakStatus.PUBLISHED) { + //make sure this is not the second ubpublished video being inserted + + insertedMediaUrls.forEach((url) => { + const _mediaItem = mediaUploads.find((item) => (item.url === url && item.speakData?.status !== ThreeSpeakStatus.PUBLISHED)); + if (_mediaItem) { + isUnpublishedInserted = true; + } + }) + + if (!isUnpublishedInserted) { + //update beneficiaries + const vidBeneficiaries = JSON.parse(item.speakData.beneficiaries || '[]') + const beneficiaries = [...DEFAULT_SPEAK_BENEFICIARIES, ...vidBeneficiaries] + const _draftId = draftId || TEMP_BENEFICIARIES_ID; + Alert.alert(_draftId, JSON.stringify(beneficiaries)) + dispatch(setBeneficiaries(_draftId, beneficiaries)) + } + } + + //TOOD: later handle beneficiaries removal on item deletion from body + if(!isUnpublishedInserted){ + insertMedia(new Map([[index, true]])); + } else { + dispatch(showActionModal({ + title:"Fail", + body:"Can only have one unpublished video per post" + })) + } + } }; - return }; diff --git a/src/components/uploadsGalleryModal/container/uploadsGalleryModal.tsx b/src/components/uploadsGalleryModal/container/uploadsGalleryModal.tsx index ed2c7889f..97248dcf3 100644 --- a/src/components/uploadsGalleryModal/container/uploadsGalleryModal.tsx +++ b/src/components/uploadsGalleryModal/container/uploadsGalleryModal.tsx @@ -48,6 +48,7 @@ export interface MediaInsertData { } interface UploadsGalleryModalProps { + draftId?: string; postBody: string; paramFiles: any[]; isEditing: boolean; @@ -61,6 +62,7 @@ interface UploadsGalleryModalProps { export const UploadsGalleryModal = forwardRef( ( { + draftId, postBody, paramFiles, isEditing, @@ -420,6 +422,7 @@ export const UploadsGalleryModal = forwardRef( !isPreviewActive && showModal && ( { try { const response = await speakApi.get( diff --git a/src/screens/editor/container/editorContainer.tsx b/src/screens/editor/container/editorContainer.tsx index cd78e5314..4fa5c84d1 100644 --- a/src/screens/editor/container/editorContainer.tsx +++ b/src/screens/editor/container/editorContainer.tsx @@ -20,6 +20,7 @@ import { reblog, postComment, } from '../../../providers/hive/dhive'; +import unionBy from 'lodash/unionBy'; // Constants import { default as ROUTES } from '../../../constants/routeNames'; @@ -52,6 +53,7 @@ import { PointActivityIds } from '../../../providers/ecency/ecency.types'; import { usePostsCachePrimer } from '../../../providers/queries/postQueries/postQueries'; import { PostTypes } from '../../../constants/postTypes'; import { speakQueries } from '../../../providers/queries'; +import { BENEFICIARY_SRC_ENCODER, DEFAULT_SPEAK_BENEFICIARIES } from '../../../providers/speak/constants'; /* * Props Name Description Value @@ -602,9 +604,9 @@ class EditorContainer extends Component { } = this.props; const { rewardType, isPostSending, thumbUrl, draftId, shouldReblog } = this.state; - //TODO: handle appropriate speak beneficiaries if needed + //ref: https://swimlanes.io/u/7xPWxOvpH - const beneficiaries = this._extractBeneficiaries(); + let beneficiaries = this._extractBeneficiaries(); if (isPostSending) { return; @@ -613,13 +615,23 @@ class EditorContainer extends Component { if (currentAccount) { // build speak video body - try{ + try { fields.body = speakContentBuilder.build(fields.body); - } catch(err){ + + //verify and video beneficiaries redundent + if (!speakContentBuilder.videoPublishMeta) { + beneficiaries = beneficiaries.filter(item => item.src !== BENEFICIARY_SRC_ENCODER); + } else { + const encoderBene = [ + ...JSON.parse(speakContentBuilder.videoPublishMeta.beneficiaries || []), + ...DEFAULT_SPEAK_BENEFICIARIES]; + beneficiaries = unionBy(encoderBene, beneficiaries, 'account'); + } + } catch (err) { console.warn("fail", err); return; } - + this.setState({ isPostSending: true, diff --git a/src/screens/editor/screen/editorScreen.tsx b/src/screens/editor/screen/editorScreen.tsx index 297470766..b18fac7a5 100644 --- a/src/screens/editor/screen/editorScreen.tsx +++ b/src/screens/editor/screen/editorScreen.tsx @@ -495,6 +495,7 @@ class EditorScreen extends Component { /> )}