setting beneficiaries for ubpublished video, added redundency during post publishing

This commit is contained in:
Nouman Tahir 2023-11-16 16:11:36 +05:00
parent 6e60a612ee
commit b25035c55c
9 changed files with 112 additions and 41 deletions

View File

@ -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}
/>
</View>
{!_isCurrentUser ? (
{!_isCurrentUser && item.src !== BENEFICIARY_SRC_ENCODER ? (
<IconButton
name="close"
iconType="MaterialCommunityIcons"

View File

@ -15,6 +15,7 @@ import { MediaInsertData, Modes } from '../../uploadsGalleryModal/container/uplo
import Formats from './formats/formats';
type Props = {
draftId?:string;
postBody: string;
paramFiles: any[];
isEditing: boolean;
@ -28,6 +29,7 @@ type Props = {
};
export const EditorToolbar = ({
draftId,
postBody,
paramFiles,
isEditing,
@ -201,6 +203,7 @@ export const EditorToolbar = ({
>
{isExtensionVisible && <View style={styles.indicator} />}
<UploadsGalleryModal
draftId={draftId}
ref={uploadsGalleryModalRef}
postBody={postBody}
isPreviewActive={isPreviewActive}

View File

@ -1,16 +1,16 @@
import React, { useState, useRef, useEffect, useCallback, Fragment } from 'react';
import { postBodySummary, renderPostBody } from '@ecency/render-helper';
import { debounce, get } from 'lodash';
import React, { Fragment, useCallback, useEffect, useRef, useState } from 'react';
import {
View,
KeyboardAvoidingView,
Text,
Platform,
ScrollView,
Text,
TouchableOpacity,
View,
} from 'react-native';
import { renderPostBody, postBodySummary } from '@ecency/render-helper';
import { useDispatch, useSelector } from 'react-redux';
import { get, debounce } from 'lodash';
import Animated, { BounceInRight } from 'react-native-reanimated';
import { useDispatch, useSelector } from 'react-redux';
import { Icon } from '../../icon';
// Utils
@ -21,34 +21,34 @@ import { toggleAccountsBottomSheet } from '../../../redux/actions/uiAction';
// Components
import {
InsertLinkModal,
Modal,
PostBody,
TextInput,
UserAvatar,
TitleArea,
SnippetsModal,
SummaryArea,
TagArea,
TagInput,
SummaryArea,
Modal,
SnippetsModal,
TextInput,
TitleArea,
Tooltip,
InsertLinkModal,
UserAvatar,
} from '../../index';
// Styles
import styles from '../styles/markdownEditorStyles';
import applySnippet from '../children/formats/applySnippet';
import { MainButton } from '../../mainButton';
import { useAppSelector } from '../../../hooks';
import { walkthrough } from '../../../redux/constants/walkthroughConstants';
import isAndroidOreo from '../../../utils/isAndroidOreo';
import { OptionsModal } from '../../atoms';
import { walkthrough } from '../../../redux/constants/walkthroughConstants';
import { MainButton } from '../../mainButton';
import { MediaInsertData } from '../../uploadsGalleryModal/container/uploadsGalleryModal';
import { EditorToolbar } from '../children/editorToolbar';
import { extractImageUrls } from '../../../utils/editor';
import { useAppSelector } from '../../../hooks';
import applySnippet from '../children/formats/applySnippet';
import styles from '../styles/markdownEditorStyles';
// const MIN_BODY_INPUT_HEIGHT = 300;
const MarkdownEditorView = ({
draftId,
paramFiles,
draftBody,
intl,
@ -432,6 +432,7 @@ const MarkdownEditorView = ({
{_renderFloatingDraftButton()}
<EditorToolbar
draftId={draftId}
postBody={bodyTextRef.current}
isPreviewActive={isPreviewActive}
paramFiles={paramFiles}

View File

@ -1,36 +1,39 @@
import { proxifyImageSrc } from '@ecency/render-helper';
import React, { useEffect, useRef, useState } from 'react';
import { useIntl } from 'react-intl';
import {
ActivityIndicator,
Alert,
Keyboard,
Platform,
Text,
TouchableOpacity,
View,
View
} from 'react-native';
import EStyleSheet from 'react-native-extended-stylesheet';
import { FlatList } from 'react-native-gesture-handler';
import Animated, {
default as AnimatedView,
EasingNode,
SlideInRight,
SlideOutRight,
ZoomIn,
EasingNode,
} from 'react-native-reanimated';
import EStyleSheet from 'react-native-extended-stylesheet';
import FastImage from 'react-native-fast-image';
import { FlatList } from 'react-native-gesture-handler';
import { Icon, IconButton } from '../..';
import { MediaItem } from '../../../providers/ecency/ecency.types';
import { editorQueries } from '../../../providers/queries';
import { MediaPreviewItem } from './mediaPreviewItem';
import styles, {
COMPACT_HEIGHT,
EXPANDED_HEIGHT,
MAX_HORIZONTAL_THUMBS,
} from './uploadsGalleryModalStyles';
import { editorQueries } from '../../../providers/queries';
import { MediaItem } from '../../../providers/ecency/ecency.types';
import { MediaPreviewItem } from './mediaPreviewItem';
import { ThreeSpeakStatus } from '../../../providers/speak/speak.types';
import { useDispatch } from 'react-redux';
import { setBeneficiaries } from '../../../redux/actions/editorActions';
import { TEMP_BENEFICIARIES_ID } from '../../../redux/constants/constants';
import { DEFAULT_SPEAK_BENEFICIARIES } from '../../../providers/speak/constants';
import { showActionModal } from '../../../redux/actions/uiAction';
type Props = {
draftId?: string;
insertedMediaUrls: string[];
mediaUploads: MediaItem[];
isAddingToUploads: boolean;
@ -40,6 +43,7 @@ type Props = {
};
const UploadsGalleryContent = ({
draftId,
insertedMediaUrls,
mediaUploads,
isAddingToUploads,
@ -48,6 +52,7 @@ const UploadsGalleryContent = ({
handleOpenCamera,
}: Props) => {
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 <MediaPreviewItem
return <MediaPreviewItem
item={item}
insertedMediaUrls={insertedMediaUrls}
deleteIds={deleteIds}
isDeleteMode={isDeleteMode}
isDeleting={isDeleting}
isExpandedMode={isExpandedMode}
isExpandedMode={isExpandedMode}
onPress={_onPress} />
};

View File

@ -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 && (
<UploadsGalleryContent
draftId={draftId}
insertedMediaUrls={mediaUrls}
mediaUploads={data}
isAddingToUploads={isAddingToUploads}

View File

@ -7,3 +7,18 @@ export const BASE_URL_SPEAK_WATCH = 'https://3speak.tv/watch';
export const PATH_MOBILE = 'mobile';
export const PATH_LOGIN = 'login';
export const PATH_API = 'api';
export const DEFAULT_SPEAK_BENEFICIARIES = [
{
account: "spk.beneficiary",
src: "ENCODER_PAY",
weight: 900
},
{
account: "threespeakleader",
src: "ENCODER_PAY",
weight: 100
}
];
export const BENEFICIARY_SRC_ENCODER = 'ENCODER_PAY';

View File

@ -12,6 +12,7 @@ const speakApi = axios.create({
baseURL: `${BASE_URL_SPEAK_STUDIO}/${PATH_MOBILE}`,
});
export const threespeakAuth = async (currentAccount: any, pinHash: string) => {
try {
const response = await speakApi.get(

View File

@ -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<EditorContainerProps, any> {
} = 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<EditorContainerProps, any> {
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,

View File

@ -495,6 +495,7 @@ class EditorScreen extends Component {
/>
)}
<MarkdownEditor
draftId={draftId}
paramFiles={paramFiles}
componentID="body"
draftBody={fields && fields.body}