Fix resolve mentioned_channels

This commit is contained in:
Rafael 2022-01-26 10:01:42 -03:00 committed by Thomas Zarebczan
parent 44213fbad2
commit 6544f4c0b6

View file

@ -7,7 +7,7 @@ import Lbry from 'lbry';
import { parseURI, buildURI, isURIEqual } from 'util/lbryURI'; import { parseURI, buildURI, isURIEqual } from 'util/lbryURI';
import { devToast, doFailedSignatureToast, resolveCommentronError } from 'util/commentron-error'; import { devToast, doFailedSignatureToast, resolveCommentronError } from 'util/commentron-error';
import { selectClaimForUri, selectClaimsByUri, selectMyChannelClaims } from 'redux/selectors/claims'; import { selectClaimForUri, selectClaimsByUri, selectMyChannelClaims } from 'redux/selectors/claims';
import { doResolveUri, doClaimSearch } from 'redux/actions/claims'; import { doResolveUris, doClaimSearch } from 'redux/actions/claims';
import { doToast, doSeeNotifications } from 'redux/actions/notifications'; import { doToast, doSeeNotifications } from 'redux/actions/notifications';
import { import {
selectMyReactsForComment, selectMyReactsForComment,
@ -500,6 +500,8 @@ export function doCommentCreate(
const mentionMatches = [...comment.matchAll(MENTION_REGEX)]; const mentionMatches = [...comment.matchAll(MENTION_REGEX)];
if (mentionMatches.length > 0) { if (mentionMatches.length > 0) {
const mentionUrls = [];
mentionMatches.forEach((match) => { mentionMatches.forEach((match) => {
const matchTerm = match[0]; const matchTerm = match[0];
const mention = matchTerm.substring(matchTerm.indexOf('@')); const mention = matchTerm.substring(matchTerm.indexOf('@'));
@ -512,11 +514,20 @@ export function doCommentCreate(
if (claim) { if (claim) {
mentionedChannels.push({ channel_name: claim.name, channel_id: claim.claim_id }); mentionedChannels.push({ channel_name: claim.name, channel_id: claim.claim_id });
} else if (claim === undefined) { } else if (claim === undefined) {
dispatch(doResolveUri(mentionUri)) mentionUrls.push(mentionUri);
.then((response) => mentionedChannels.push({ channel_name: response.name, channel_id: response.claim_id }))
.catch((e) => {});
} }
}); });
if (mentionUrls.length > 0) {
await dispatch(doResolveUris(mentionUrls, true))
.then((response) => {
mentionedChannels = Object.values(response).map((claim) => {
// $FlowFixMe
return { channel_name: claim.name, channel_id: claim.claim_id };
});
})
.catch((e) => {});
}
} }
dispatch({ type: ACTIONS.COMMENT_CREATE_STARTED }); dispatch({ type: ACTIONS.COMMENT_CREATE_STARTED });