diff --git a/flow-typed/Comment.js b/flow-typed/Comment.js index ba945227c..95ad48cf6 100644 --- a/flow-typed/Comment.js +++ b/flow-typed/Comment.js @@ -72,6 +72,26 @@ declare type CommentsState = { fetchingBlockedWords: boolean, }; +// Authorization parameters for calls requiring user authentication +declare type Authorization = { + channel_name: string, + channel_id: string, + signature: string, + signing_ts: string, +}; + +// ModAuthorization parameters for calls requiring creator/moderator authentication +declare type ModAuthorization = { + // Publisher, Moderator or Commentron Admin + mod_channel_id: string, + mod_channel_name: string, + // Creator that Moderator is delegated from. Used for delegated moderation + creator_channel_id: string, + creator_channel_name: string, + signature: string, + signing_ts: string, +}; + declare type CommentReactParams = { comment_ids: string, channel_name: string, @@ -243,30 +263,17 @@ declare type BlockedListArgs = { signing_ts: string, }; -declare type ModerationAddDelegateParams = { +declare type ModerationAddDelegateParams = Authorization & { mod_channel_id: string, mod_channel_name: string, - creator_channel_id: string, - creator_channel_name: string, - signature: string, - signing_ts: string, }; -declare type ModerationRemoveDelegateParams = { +declare type ModerationRemoveDelegateParams = Authorization & { mod_channel_id: string, mod_channel_name: string, - creator_channel_id: string, - creator_channel_name: string, - signature: string, - signing_ts: string, }; -declare type ModerationListDelegatesParams = { - creator_channel_id: string, - creator_channel_name: string, - signature: string, - signing_ts: string, -}; +declare type ModerationListDelegatesParams = Authorization; declare type ModerationAmIParams = { channel_name: string, diff --git a/static/app-strings.json b/static/app-strings.json index 3d94b120c..8a9e93408 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -1691,6 +1691,7 @@ "Add as moderator": "Add as moderator", "Assign this user to moderate %channel%.": "Assign this user to moderate %channel%.", "Assign this user to moderate your channel.": "Assign this user to moderate your channel.", + "Added %user% as moderator for %myChannel%": "Added %user% as moderator for %myChannel%", "Mute (m)": "Mute (m)", "Playback Rate (<, >)": "Playback Rate (<, >)", "Fullscreen (f)": "Fullscreen (f)", diff --git a/ui/redux/actions/comments.js b/ui/redux/actions/comments.js index 8b006da2e..df3a38ec0 100644 --- a/ui/redux/actions/comments.js +++ b/ui/redux/actions/comments.js @@ -1319,17 +1319,7 @@ export function doCommentModAddDelegate( showToast: boolean = false ) { return async (dispatch: Dispatch, getState: GetState) => { - let signature: ?{ - signature: string, - signing_ts: string, - }; - try { - signature = await Lbry.channel_sign({ - channel_id: creatorChannelClaim.claim_id, - hexdata: toHex(creatorChannelClaim.name), - }); - } catch (e) {} - + const signature = await channelSignData(creatorChannelClaim.claim_id, creatorChannelClaim.name); if (!signature) { return; } @@ -1337,10 +1327,9 @@ export function doCommentModAddDelegate( return Comments.moderation_add_delegate({ mod_channel_id: modChannelId, mod_channel_name: modChannelName, - creator_channel_id: creatorChannelClaim.claim_id, - creator_channel_name: creatorChannelClaim.name, - signature: signature.signature, - signing_ts: signature.signing_ts, + channel_id: creatorChannelClaim.claim_id, + channel_name: creatorChannelClaim.name, + ...signature, }) .then(() => { if (showToast) { @@ -1357,12 +1346,7 @@ export function doCommentModAddDelegate( } }) .catch((err) => { - dispatch( - doToast({ - message: err.message, - isError: true, - }) - ); + dispatch(doToast({ message: err.message, isError: true })); }); }; } @@ -1373,17 +1357,7 @@ export function doCommentModRemoveDelegate( creatorChannelClaim: ChannelClaim ) { return async (dispatch: Dispatch, getState: GetState) => { - let signature: ?{ - signature: string, - signing_ts: string, - }; - try { - signature = await Lbry.channel_sign({ - channel_id: creatorChannelClaim.claim_id, - hexdata: toHex(creatorChannelClaim.name), - }); - } catch (e) {} - + const signature = await channelSignData(creatorChannelClaim.claim_id, creatorChannelClaim.name); if (!signature) { return; } @@ -1391,50 +1365,29 @@ export function doCommentModRemoveDelegate( return Comments.moderation_remove_delegate({ mod_channel_id: modChannelId, mod_channel_name: modChannelName, - creator_channel_id: creatorChannelClaim.claim_id, - creator_channel_name: creatorChannelClaim.name, - signature: signature.signature, - signing_ts: signature.signing_ts, + channel_id: creatorChannelClaim.claim_id, + channel_name: creatorChannelClaim.name, + ...signature, }).catch((err) => { - dispatch( - doToast({ - message: err.message, - isError: true, - }) - ); + dispatch(doToast({ message: err.message, isError: true })); }); }; } export function doCommentModListDelegates(channelClaim: ChannelClaim) { return async (dispatch: Dispatch, getState: GetState) => { - dispatch({ - type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_STARTED, - }); - - let signature: ?{ - signature: string, - signing_ts: string, - }; - try { - signature = await Lbry.channel_sign({ - channel_id: channelClaim.claim_id, - hexdata: toHex(channelClaim.name), - }); - } catch (e) {} + dispatch({ type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_STARTED }); + const signature = await channelSignData(channelClaim.claim_id, channelClaim.name); if (!signature) { - dispatch({ - type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED, - }); + dispatch({ type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED }); return; } return Comments.moderation_list_delegates({ - creator_channel_id: channelClaim.claim_id, - creator_channel_name: channelClaim.name, - signature: signature.signature, - signing_ts: signature.signing_ts, + channel_id: channelClaim.claim_id, + channel_name: channelClaim.name, + ...signature, }) .then((response) => { dispatch({ @@ -1446,9 +1399,7 @@ export function doCommentModListDelegates(channelClaim: ChannelClaim) { }); }) .catch((err) => { - dispatch({ - type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED, - }); + dispatch({ type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED }); }); }; }