Only show followed hashtags for non-followings

This commit is contained in:
Lim Chee Aun 2023-12-20 16:04:37 +08:00
parent 8ce720f305
commit 9983c8086c
3 changed files with 29 additions and 2 deletions

View file

@ -31,7 +31,11 @@ function Following({ title, path, id, ...props }) {
const results = await homeIterator.current.next();
let { value } = results;
if (value?.length) {
let latestItemChanged = false;
if (firstLoad) {
if (value[0].id !== latestItem.current) {
latestItemChanged = true;
}
latestItem.current = value[0].id;
console.log('First load', latestItem.current);
}
@ -41,7 +45,7 @@ function Following({ title, path, id, ...props }) {
saveStatus(item, instance);
});
value = dedupeBoosts(value, instance);
if (firstLoad) clearFollowedTagsState();
if (firstLoad && latestItemChanged) clearFollowedTagsState();
assignFollowedTags(value, instance);
// ENFORCE sort by datetime (Latest first)

View file

@ -19,6 +19,7 @@ export async function fetchRelationships(accounts, relationshipsMap = {}) {
}
return acc;
}, []);
if (!uniqueAccountIds.length) return null;
try {
const relationships = await masto.v1.accounts.relationships.fetch({

View file

@ -1,4 +1,5 @@
import { extractTagsFromStatus, getFollowedTags } from './followed-tags';
import { fetchRelationships } from './relationships';
import states, { statusKey } from './states';
import store from './store';
@ -182,6 +183,8 @@ export async function assignFollowedTags(items, instance) {
const followedTags = await getFollowedTags(); // [{name: 'tag'}, {...}]
if (!followedTags.length) return;
const { statusFollowedTags } = states;
console.log('statusFollowedTags', statusFollowedTags);
const statusWithFollowedTags = [];
items.forEach((item) => {
if (item.reblog) return;
const { id, content, tags = [] } = item;
@ -199,9 +202,28 @@ export async function assignFollowedTags(items, instance) {
return acc;
}, []);
if (itemFollowedTags.length) {
statusFollowedTags[sKey] = itemFollowedTags;
// statusFollowedTags[sKey] = itemFollowedTags;
statusWithFollowedTags.push({
item,
sKey,
followedTags: itemFollowedTags,
});
}
});
if (statusWithFollowedTags.length) {
const accounts = statusWithFollowedTags.map((s) => s.item.account);
const relationships = await fetchRelationships(accounts);
if (!relationships) return;
statusWithFollowedTags.forEach((s) => {
const { item, sKey, followedTags } = s;
const r = relationships[item.account.id];
if (!r.following) {
statusFollowedTags[sKey] = followedTags;
}
});
}
}
export function clearFollowedTagsState() {