Commentron: param updates for moderation.*Delegates

## Reason
https://odysee-workspace.slack.com/archives/C02FMSYF51B/p1642435815038000?thread_ts=1642129696.024400&cid=C02FMSYF51B
Due to unaligned parameters not compliant with Authenticate, ModAuthenticate APIs.

It will still work without this PR as there is a compatibility layer, but should use the correct params moving forward.
This commit is contained in:
infinite-persistence 2022-01-18 10:18:08 +08:00
parent 783520f734
commit c1cb9345ad
No known key found for this signature in database
GPG key ID: B9C3252EDC3D0AA0
3 changed files with 41 additions and 82 deletions

39
flow-typed/Comment.js vendored
View file

@ -72,6 +72,26 @@ declare type CommentsState = {
fetchingBlockedWords: boolean, 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 = { declare type CommentReactParams = {
comment_ids: string, comment_ids: string,
channel_name: string, channel_name: string,
@ -243,30 +263,17 @@ declare type BlockedListArgs = {
signing_ts: string, signing_ts: string,
}; };
declare type ModerationAddDelegateParams = { declare type ModerationAddDelegateParams = Authorization & {
mod_channel_id: string, mod_channel_id: string,
mod_channel_name: 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_id: string,
mod_channel_name: string, mod_channel_name: string,
creator_channel_id: string,
creator_channel_name: string,
signature: string,
signing_ts: string,
}; };
declare type ModerationListDelegatesParams = { declare type ModerationListDelegatesParams = Authorization;
creator_channel_id: string,
creator_channel_name: string,
signature: string,
signing_ts: string,
};
declare type ModerationAmIParams = { declare type ModerationAmIParams = {
channel_name: string, channel_name: string,

View file

@ -1691,6 +1691,7 @@
"Add as moderator": "Add as moderator", "Add as moderator": "Add as moderator",
"Assign this user to moderate %channel%.": "Assign this user to moderate %channel%.", "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.", "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)", "Mute (m)": "Mute (m)",
"Playback Rate (<, >)": "Playback Rate (<, >)", "Playback Rate (<, >)": "Playback Rate (<, >)",
"Fullscreen (f)": "Fullscreen (f)", "Fullscreen (f)": "Fullscreen (f)",

View file

@ -1319,17 +1319,7 @@ export function doCommentModAddDelegate(
showToast: boolean = false showToast: boolean = false
) { ) {
return async (dispatch: Dispatch, getState: GetState) => { return async (dispatch: Dispatch, getState: GetState) => {
let signature: ?{ const signature = await channelSignData(creatorChannelClaim.claim_id, creatorChannelClaim.name);
signature: string,
signing_ts: string,
};
try {
signature = await Lbry.channel_sign({
channel_id: creatorChannelClaim.claim_id,
hexdata: toHex(creatorChannelClaim.name),
});
} catch (e) {}
if (!signature) { if (!signature) {
return; return;
} }
@ -1337,10 +1327,9 @@ export function doCommentModAddDelegate(
return Comments.moderation_add_delegate({ return Comments.moderation_add_delegate({
mod_channel_id: modChannelId, mod_channel_id: modChannelId,
mod_channel_name: modChannelName, mod_channel_name: modChannelName,
creator_channel_id: creatorChannelClaim.claim_id, channel_id: creatorChannelClaim.claim_id,
creator_channel_name: creatorChannelClaim.name, channel_name: creatorChannelClaim.name,
signature: signature.signature, ...signature,
signing_ts: signature.signing_ts,
}) })
.then(() => { .then(() => {
if (showToast) { if (showToast) {
@ -1357,12 +1346,7 @@ export function doCommentModAddDelegate(
} }
}) })
.catch((err) => { .catch((err) => {
dispatch( dispatch(doToast({ message: err.message, isError: true }));
doToast({
message: err.message,
isError: true,
})
);
}); });
}; };
} }
@ -1373,17 +1357,7 @@ export function doCommentModRemoveDelegate(
creatorChannelClaim: ChannelClaim creatorChannelClaim: ChannelClaim
) { ) {
return async (dispatch: Dispatch, getState: GetState) => { return async (dispatch: Dispatch, getState: GetState) => {
let signature: ?{ const signature = await channelSignData(creatorChannelClaim.claim_id, creatorChannelClaim.name);
signature: string,
signing_ts: string,
};
try {
signature = await Lbry.channel_sign({
channel_id: creatorChannelClaim.claim_id,
hexdata: toHex(creatorChannelClaim.name),
});
} catch (e) {}
if (!signature) { if (!signature) {
return; return;
} }
@ -1391,50 +1365,29 @@ export function doCommentModRemoveDelegate(
return Comments.moderation_remove_delegate({ return Comments.moderation_remove_delegate({
mod_channel_id: modChannelId, mod_channel_id: modChannelId,
mod_channel_name: modChannelName, mod_channel_name: modChannelName,
creator_channel_id: creatorChannelClaim.claim_id, channel_id: creatorChannelClaim.claim_id,
creator_channel_name: creatorChannelClaim.name, channel_name: creatorChannelClaim.name,
signature: signature.signature, ...signature,
signing_ts: signature.signing_ts,
}).catch((err) => { }).catch((err) => {
dispatch( dispatch(doToast({ message: err.message, isError: true }));
doToast({
message: err.message,
isError: true,
})
);
}); });
}; };
} }
export function doCommentModListDelegates(channelClaim: ChannelClaim) { export function doCommentModListDelegates(channelClaim: ChannelClaim) {
return async (dispatch: Dispatch, getState: GetState) => { return async (dispatch: Dispatch, getState: GetState) => {
dispatch({ dispatch({ type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_STARTED });
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) {}
const signature = await channelSignData(channelClaim.claim_id, channelClaim.name);
if (!signature) { if (!signature) {
dispatch({ dispatch({ type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED });
type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED,
});
return; return;
} }
return Comments.moderation_list_delegates({ return Comments.moderation_list_delegates({
creator_channel_id: channelClaim.claim_id, channel_id: channelClaim.claim_id,
creator_channel_name: channelClaim.name, channel_name: channelClaim.name,
signature: signature.signature, ...signature,
signing_ts: signature.signing_ts,
}) })
.then((response) => { .then((response) => {
dispatch({ dispatch({
@ -1446,9 +1399,7 @@ export function doCommentModListDelegates(channelClaim: ChannelClaim) {
}); });
}) })
.catch((err) => { .catch((err) => {
dispatch({ dispatch({ type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED });
type: ACTIONS.COMMENT_FETCH_MODERATION_DELEGATES_FAILED,
});
}); });
}; };
} }