Skip to content

Commit

Permalink
timeline upgrade
Browse files Browse the repository at this point in the history
  • Loading branch information
ghobs91 committed Dec 30, 2023
1 parent 0960c45 commit 83dc352
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
3 changes: 3 additions & 0 deletions src/app.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ function App() {
const instanceURL = store.local.get('instanceURL');
const myCurrentInstance = api().instance;
const { instance } = api();
const { masto } = api({ instance });
const formattedShortcuts = [
{
icon: "home",
Expand Down Expand Up @@ -115,6 +116,8 @@ function App() {
},
]



useLayoutEffect(() => {
const theme = store.local.get('theme');
if (theme) {
Expand Down
7 changes: 5 additions & 2 deletions src/components/timeline.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { useSnapshot } from 'valtio';

import states, { statusKey } from '../utils/states';
import statusPeek from '../utils/status-peek';
import { groupBoosts, groupContext } from '../utils/timeline-utils';
import { groupBoosts, groupContext, applyMutedWords } from '../utils/timeline-utils';
import useInterval from '../utils/useInterval';
import usePageVisibility from '../utils/usePageVisibility';
import useScroll from '../utils/useScroll';
Expand Down Expand Up @@ -64,7 +64,10 @@ function Timeline({
value = groupBoosts(value);
}
value = groupContext(value);
console.log(value);
if (value) {
value = applyMutedWords(value);
}
// console.log(value);
if (firstLoad) {
setItems(value);
} else {
Expand Down
31 changes: 31 additions & 0 deletions src/utils/timeline-utils.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import store from './store';
import { api } from './api';

export function groupBoosts(values) {
let newValues = [];
Expand Down Expand Up @@ -49,6 +50,36 @@ export function groupBoosts(values) {
}
}

export function applyMutedWords(values) {
const { masto } = api();
(async () => {
try {
const filterResults = await masto.v2.filters.fetch({
resolve: true
});
if (filterResults) {
let newValues = [];
console.log(`users filters: ${filterResults}`);
values.forEach((value) => {
filterResults.forEach((filterList) => {
filterList.keywords.forEach((keyword) => {
if (value.indexOf(keyword) === -1) {
newValues.push(value);
}
});
});
});
return newValues;
} else {
return values;
}
} catch (e) {
alert('Error: ' + e);
console.error(e);
}
})();
}

export function dedupeBoosts(items, instance) {
const boostedStatusIDs = store.account.get('boostedStatusIDs') || {};
const filteredItems = items.filter((item) => {
Expand Down

0 comments on commit 83dc352

Please sign in to comment.