Skip to content

Commit

Permalink
Fix display of mastodon posts
Browse files Browse the repository at this point in the history
  • Loading branch information
twinkarma committed Jul 19, 2024
1 parent e479d29 commit 7e27cdd
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 40 deletions.
1 change: 1 addition & 0 deletions src/components/NavItems/Assistant/AssistantRuleBook.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ export const ASSISTANT_ACTIONS = [
KNOWN_LINKS.TELEGRAM,
KNOWN_LINKS.FACEBOOK,
KNOWN_LINKS.TWITTER,
KNOWN_LINKS.MASTODON,
],
cTypes: [CONTENT_TYPE.VIDEO],
exceptions: [],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,38 @@ function treeMapToElementsRecursive(
) {
let childElems = [];
if ("span" in treeElem) {
// If there's text in the node

const span = treeElem.span;
if (spanHighlightIndices === null) {
// console.log("No span highlight: ", text.substring(span.start, span.end));
childElems.push(text.substring(span.start, span.end));
} else {
// console.log("Span highlight: ", text.substring(span.start, span.end));
// If text span matches with indices for highlighting
// then try to wrap them in wrapFunc()
let currentIndex = span.start;
for (let i = 0; i < spanHighlightIndices.length; i++) {
const hSpan = spanHighlightIndices[i];
// console.log(
// "Matching span",
// span.start,
// span.end,
// hSpan.indices[0],
// hSpan.indices[1],
// );
const hSpanStart = hSpan.indices[0];
const hSpanEnd = hSpan.indices[1];
if (
(span.start <= hSpanStart && hSpanStart <= span.end) ||
(span.start <= hSpanEnd && hSpanEnd <= span.end)
) {
//If there's an overlap
// console.log(
// "Found lapping span ",
// span.start,
// span.end,
// hSpanStart,
// hSpanEnd,
// );

// If span doesn't start before the current index
if (hSpanStart > currentIndex) {
// If span doesn't start before the current index, add unlighlighted text
childElems.push(text.substring(currentIndex, hSpanStart));
}

const boundedStart =
hSpanStart < span.start ? span.start : hSpanStart;
const boundedEnd = hSpanEnd > span.end ? span.end : hSpanEnd;
if (wrapFunc) {
// console.log("Wrapping: ", text.substring(boundedStart, boundedEnd));
// Add parts of text that needs to be wrapped in wrapFunc()
childElems.push(
wrapFunc(text.substring(boundedStart, boundedEnd), hSpan),
);
} else {
// console.log(
// "Not wrapping: ",
// text.substring(boundedStart, boundedEnd),
// );
// No wrapFunc(), inserting plaintext
childElems.push(text.substring(boundedStart, boundedEnd));
}

Expand All @@ -81,7 +64,14 @@ function treeMapToElementsRecursive(
),
);
}
return React.createElement(treeElem.tag, null, childElems);

//Collect attributes
let attributes = {};
if (treeElem.attributes) {
attributes = treeElem.attributes;
}

return React.createElement(treeElem.tag, attributes, childElems);
}

/**
Expand Down
1 change: 1 addition & 0 deletions src/redux/sagas/assistantSaga.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -637,6 +637,7 @@ const filterAssistantResults = (
videoList = scrapeResult.videos;
}
break;
case KNOWN_LINKS.MASTODON:
case KNOWN_LINKS.TELEGRAM:
case KNOWN_LINKS.VK:
if (scrapeResult.images.length > 0) {
Expand Down
29 changes: 14 additions & 15 deletions tests/e2e/assistant.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -125,21 +125,20 @@ const MediaServices = {
mediaStatus: MediaVideoStatus.iframe,
services: [MediaServices.videoDownloadGeneric]
},
// Mastodon issues will be addressed very soon!
// // Mastodon link with youtube video link
// {
// url: "https://mstdn.social/@BBC/105203076554056414",
// mediaType: MediaType.video,
// mediaStatus: MediaVideoStatus.video,
// services: []
// },
// // Mastodon link with embedded video
// {
// url: "https://mstdn.social/@dtnsshow/112728823075224415",
// mediaType: MediaType.video,
// mediaStatus: MediaVideoStatus.video,
// services: []
// },
// Mastodon link with youtube video link
{
url: "https://mstdn.social/@BBC/105203076554056414",
mediaType: MediaType.video,
mediaStatus: MediaVideoStatus.video,
services: []
},
// Mastodon link with embedded video
{
url: "https://mstdn.social/@dtnsshow/112728823075224415",
mediaType: MediaType.video,
mediaStatus: MediaVideoStatus.video,
services: []
},
].forEach(({url, videoGridIndex, imageGridIndex, mediaType, mediaStatus, services}) => {
test(`Test assistant media services for url: ${url}`, async ({ page, extensionId }) => {

Expand Down

0 comments on commit 7e27cdd

Please sign in to comment.