Rewrite shared feed

This commit is contained in:
Natsumi
2026-01-17 11:44:09 +13:00
parent 56bf69f64e
commit 9f80d5e64a
22 changed files with 534 additions and 841 deletions
+1 -50
View File
@@ -28,13 +28,10 @@ export const useFeedStore = defineStore('Feed', () => {
pageSizeLinked: true
});
const feedSessionTable = ref([]);
watch(
() => watchState.isLoggedIn,
(isLoggedIn) => {
feedTable.value.data.length = 0;
feedSessionTable.value = [];
if (isLoggedIn) {
initFeedTable();
}
@@ -160,9 +157,7 @@ export const useFeedStore = defineStore('Feed', () => {
function addFeed(feed) {
notificationStore.queueFeedNoty(feed);
feedSessionTable.value.push(feed);
sweepFeedSessionTable();
sharedFeedStore.updateSharedFeed(false);
sharedFeedStore.addEntry(feed);
if (
feedTable.value.filter.length > 0 &&
!feedTable.value.filter.includes(feed.type)
@@ -183,65 +178,21 @@ export const useFeedStore = defineStore('Feed', () => {
UiStore.notifyMenu('feed');
}
function sweepFeedSessionTable() {
const data = feedSessionTable.value;
const k = data.length;
if (!k) {
return;
}
// 24 hour limit
const date = new Date();
date.setDate(date.getDate() - 1);
const limit = date.toJSON();
if (data[0].created_at < limit) {
let i = 0;
while (i < k && data[i].created_at < limit) {
++i;
}
if (i === k) {
feedSessionTable.value = [];
return;
}
if (i) {
data.splice(0, i);
}
}
const maxLen = Math.floor(vrcxStore.maxTableSize * 1.5);
if (maxLen > 0 && data.length > maxLen + 100) {
data.splice(0, 100);
}
}
function sweepFeed() {
const { data } = feedTable.value;
const j = data.length;
if (j > vrcxStore.maxTableSize + 50) {
data.splice(0, 50);
}
sweepFeedSessionTable();
}
async function initFeedTable() {
feedTable.value.loading = true;
feedTableLookup();
const getFeedDatabaseResult = await database.getFeedDatabase();
if (getFeedDatabaseResult && getFeedDatabaseResult.length > 0) {
// rough, maybe 100 is enough
feedSessionTable.value = getFeedDatabaseResult.slice(-100);
} else {
feedSessionTable.value = [];
}
}
return {
feedTable,
feedSessionTable,
initFeedTable,
feedTableLookup,
addFeed
+4 -4
View File
@@ -993,6 +993,7 @@ export const useFriendStore = defineStore('Friend', () => {
friendLogTable.value.data.push(friendLogHistory);
database.addFriendLogHistory(friendLogHistory);
notificationStore.queueFriendLogNoty(friendLogHistory);
sharedFeedStore.addEntry(friendLogHistory);
const friendLogCurrent = {
userId: id,
displayName: ref.displayName,
@@ -1003,7 +1004,6 @@ export const useFriendStore = defineStore('Friend', () => {
database.setFriendLogCurrent(friendLogCurrent);
uiStore.notifyMenu('friend-log');
deleteFriendRequest(id);
sharedFeedStore.updateSharedFeed(true);
userRequest
.getUser({
userId: id
@@ -1067,13 +1067,13 @@ export const useFriendStore = defineStore('Friend', () => {
friendLogTable.value.data.push(friendLogHistory);
database.addFriendLogHistory(friendLogHistory);
notificationStore.queueFriendLogNoty(friendLogHistory);
sharedFeedStore.addEntry(friendLogHistory);
friendLog.delete(id);
database.deleteFriendLogCurrent(id);
favoriteStore.handleFavoriteDelete(id);
if (!appearanceSettingsStore.hideUnfriends) {
uiStore.notifyMenu('friend-log');
}
sharedFeedStore.updateSharedFeed(true);
deleteFriend(id);
}
});
@@ -1130,6 +1130,7 @@ export const useFriendStore = defineStore('Friend', () => {
notificationStore.queueFriendLogNoty(
friendLogHistoryDisplayName
);
sharedFeedStore.addEntry(friendLogHistoryDisplayName);
const friendLogCurrent = {
userId: ref.id,
displayName: ref.displayName,
@@ -1140,7 +1141,6 @@ export const useFriendStore = defineStore('Friend', () => {
database.setFriendLogCurrent(friendLogCurrent);
ctx.displayName = ref.displayName;
uiStore.notifyMenu('friend-log');
sharedFeedStore.updateSharedFeed(true);
}
}
if (
@@ -1176,6 +1176,7 @@ export const useFriendStore = defineStore('Friend', () => {
friendLogTable.value.data.push(friendLogHistoryTrustLevel);
database.addFriendLogHistory(friendLogHistoryTrustLevel);
notificationStore.queueFriendLogNoty(friendLogHistoryTrustLevel);
sharedFeedStore.addEntry(friendLogHistoryTrustLevel);
const friendLogCurrent2 = {
userId: ref.id,
displayName: ref.displayName,
@@ -1185,7 +1186,6 @@ export const useFriendStore = defineStore('Friend', () => {
friendLog.set(ref.id, friendLogCurrent2);
database.setFriendLogCurrent(friendLogCurrent2);
uiStore.notifyMenu('friend-log');
sharedFeedStore.updateSharedFeed(true);
}
ctx.trustLevel = ref.$trustLevel;
}
+6 -75
View File
@@ -15,7 +15,6 @@ import {
import { AppDebug } from '../service/appConfig';
import { database } from '../service/database';
import { useAdvancedSettingsStore } from './settings/advanced';
import { useAppearanceSettingsStore } from './settings/appearance';
import { useFriendStore } from './friend';
import { useGalleryStore } from './gallery';
import { useGameStore } from './game';
@@ -49,7 +48,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
const vrcxStore = useVrcxStore();
const advancedSettingsStore = useAdvancedSettingsStore();
const gameStore = useGameStore();
const appearanceSettingsStore = useAppearanceSettingsStore();
const generalSettingsStore = useGeneralSettingsStore();
const galleryStore = useGalleryStore();
const photonStore = usePhotonStore();
@@ -70,8 +68,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
vip: false
});
const gameLogSessionTable = ref([]);
const nowPlaying = ref({
url: '',
name: '',
@@ -93,7 +89,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
() => watchState.isLoggedIn,
(isLoggedIn) => {
gameLogTable.value.data.length = 0;
gameLogSessionTable.value = [];
if (isLoggedIn) {
// wait for friends to load, silly but works
setTimeout(() => {
@@ -225,14 +220,15 @@ export const useGameLogStore = defineStore('GameLog', () => {
workerTimers.setTimeout(() => updateNowPlaying(), 1000);
}
function tryLoadPlayerList() {
async function tryLoadPlayerList() {
// TODO: make this work again
if (!gameStore.isGameRunning) {
return;
}
console.log('Loading player list from game log...');
let ctx;
let i;
const data = gameLogSessionTable.value;
const data = await database.getGamelogDatabase();
if (data.length === 0) {
return;
}
@@ -358,13 +354,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
function addGameLog(entry) {
entry.isFriend = gameLogIsFriend(entry);
entry.isFavorite = gameLogIsFavorite(entry);
gameLogSessionTable.value.push(entry);
sweepGameLogSessionTable();
sharedFeedStore.updateSharedFeed(false);
if (entry.type === 'VideoPlay') {
// event time can be before last gameLog entry
sharedFeedStore.updateSharedFeed(true);
}
// If the VIP friend filter is enabled, logs from other friends will be ignored.
if (
@@ -402,38 +391,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
uiStore.notifyMenu('game-log');
}
function sweepGameLogSessionTable() {
const data = gameLogSessionTable.value;
const k = data.length;
if (!k) {
return;
}
// 24 hour limit
const date = new Date();
date.setDate(date.getDate() - 1);
const limit = date.toJSON();
if (data[0].created_at < limit) {
let i = 0;
while (i < k && data[i].created_at < limit) {
++i;
}
if (i === k) {
gameLogSessionTable.value = [];
return;
}
if (i) {
data.splice(0, i);
}
}
const maxLen = Math.floor(vrcxStore.maxTableSize * 1.5);
if (maxLen > 0 && data.length > maxLen + 100) {
data.splice(0, 100);
}
}
async function addGamelogLocationToDatabase(input) {
const groupName = await getGroupName(input.location);
const entry = {
@@ -518,8 +475,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
if (j > vrcxStore.maxTableSize + 50) {
data.splice(0, 50);
}
sweepGameLogSessionTable();
}
function addGameLogEntry(gameLog, location) {
@@ -657,22 +612,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
if (typeof ref1 === 'undefined') {
break;
}
const friendRef = friendStore.friends.get(userId);
if (typeof friendRef?.ref !== 'undefined') {
friendRef.ref.$joinCount++;
friendRef.ref.$lastSeen = new Date().toJSON();
friendRef.ref.$timeSpent +=
dayjs(gameLog.dt) - ref1.joinTime;
if (
appearanceSettingsStore.sidebarSortMethods.includes(
'Sort by Last Seen'
)
) {
// TODO: remove
friendStore.sortVIPFriends = true;
friendStore.sortOnlineFriends = true;
}
}
const time = dayjs(gameLog.dt) - ref1.joinTime;
locationStore.lastLocation.playerList.delete(userId);
locationStore.lastLocation.friendList.delete(userId);
@@ -958,13 +897,7 @@ export const useGameLogStore = defineStore('GameLog', () => {
break;
}
if (typeof entry !== 'undefined') {
// add tag colour
if (entry.userId) {
const tagRef = userStore.customUserTags.get(entry.userId);
if (typeof tagRef !== 'undefined') {
entry.tagColour = tagRef.colour;
}
}
sharedFeedStore.addEntry(entry);
notificationStore.queueGameLogNoty(entry);
addGameLog(entry);
}
@@ -1368,8 +1301,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
async function getGameLogTable() {
await database.initTables();
gameLogSessionTable.value = await database.getGamelogDatabase();
sweepGameLogSessionTable();
const dateTill = await database.getLastDateGameLogDatabase();
updateGameLog(dateTill);
}
@@ -1433,7 +1364,8 @@ export const useGameLogStore = defineStore('GameLog', () => {
async function initGameLogTable() {
const rows = await database.lookupGameLogDatabase(
gameLogTable.value.search,
gameLogTable.value.filter
gameLogTable.value.filter,
[]
);
for (const row of rows) {
row.isFriend = gameLogIsFriend(row);
@@ -1447,7 +1379,6 @@ export const useGameLogStore = defineStore('GameLog', () => {
nowPlaying,
gameLogTable,
gameLogSessionTable,
lastVideoUrl,
lastResourceloadUrl,
+2 -3
View File
@@ -73,8 +73,7 @@ async function registerSentryPiniaPlugin() {
GameLog: {
// @ts-ignore
...state.GameLog,
gameLogTable: null,
gameLogSessionTable: null
gameLogTable: null
},
Notification: {
// @ts-ignore
@@ -92,7 +91,7 @@ async function registerSentryPiniaPlugin() {
SharedFeed: {
// @ts-ignore
...state.SharedFeed,
sharedFeed: null
sharedFeedData: null
},
Group: {
// @ts-ignore
+10 -6
View File
@@ -387,11 +387,15 @@ export const useInstanceStore = defineStore('Instance', () => {
const L = parseLocation(location);
if (L.isRealInstance && L.worldId && L.instanceId) {
const args = await instanceRequest.getCachedInstance({
worldId: L.worldId,
instanceId: L.instanceId
});
instanceName = args.ref.displayName;
try {
const args = await instanceRequest.getCachedInstance({
worldId: L.worldId,
instanceId: L.instanceId
});
instanceName = args.ref.displayName;
} catch (e) {
console.error('getInstanceName failed location', location, e);
}
}
return instanceName;
@@ -976,8 +980,8 @@ export const useInstanceStore = defineStore('Instance', () => {
uiStore.notifyMenu('notification');
}
notificationStore.queueNotificationNoty(noty);
sharedFeedStore.addEntry(noty);
notificationStore.notificationTable.data.push(noty);
sharedFeedStore.updateSharedFeed(true);
}
/**
+8 -8
View File
@@ -95,14 +95,14 @@ export const useLocationStore = defineStore('Location', () => {
// with the current state of things, lets not run this if we don't need to
return;
}
let lastLocationTemp = '';
for (let i = gameLogStore.gameLogSessionTable.length - 1; i > -1; i--) {
const item = gameLogStore.gameLogSessionTable[i];
if (item.type === 'Location') {
lastLocationTemp = item.location;
break;
}
}
const lastLocationArray = await database.lookupGameLogDatabase(
'',
['Location'],
[],
1
);
const lastLocationTemp =
lastLocationArray.length > 0 ? lastLocationArray[0].location : '';
if (lastLocationTemp === location) {
return;
}
+1 -1
View File
@@ -146,10 +146,10 @@ export const useNotificationStore = defineStore('Notification', () => {
}
unseenNotifications.value.push(ref.id);
queueNotificationNoty(ref);
sharedFeedStore.addEntry(ref);
}
}
notificationTable.value.data.push(ref);
sharedFeedStore.updateSharedFeed(true);
const D = userStore.userDialog;
if (
D.visible === false ||
+1 -3
View File
@@ -1645,6 +1645,7 @@ export const usePhotonStore = defineStore('Photon', () => {
type
};
notificationStore.queueModerationNoty(noty);
sharedFeedStore.addEntry(noty);
const entry = {
created_at: gameLogDate,
userId: ref.id,
@@ -1653,9 +1654,6 @@ export const usePhotonStore = defineStore('Photon', () => {
};
moderationAgainstTable.value.push(entry);
}
if (block || mute || block !== row.block || mute !== row.mute) {
sharedFeedStore.updateSharedFeed(true);
}
if (block || mute) {
database.setModeration({
userId: ref.id,
+5
View File
@@ -1,11 +1,15 @@
import { defineStore } from 'pinia';
import { ref } from 'vue';
import { useSharedFeedStore } from '../sharedFeed';
import configRepository from '../../service/config';
export const useWristOverlaySettingsStore = defineStore(
'WristOverlaySettings',
() => {
const sharedFeed = useSharedFeedStore();
const overlayWrist = ref(true);
const hidePrivateFromFeed = ref(false);
const openVRAlways = ref(false);
@@ -68,6 +72,7 @@ export const useWristOverlaySettingsStore = defineStore(
'VRCX_hidePrivateFromFeed',
hidePrivateFromFeed.value
);
sharedFeed.loadSharedFeed();
}
function setOpenVRAlways() {
openVRAlways.value = !openVRAlways.value;
+382 -612
View File
File diff suppressed because it is too large Load Diff
+2 -8
View File
@@ -630,17 +630,11 @@ export const useUserStore = defineStore('User', () => {
...ref
});
currentTravelers.set(ref.id, travelRef);
sharedFeedStore.sharedFeed.pendingUpdate = true;
sharedFeedStore.updateSharedFeed(false);
onPlayerTraveling(travelRef);
}
} else {
ref.$location = parseLocation(ref.location);
if (currentTravelers.has(ref.id)) {
currentTravelers.delete(ref.id);
sharedFeedStore.sharedFeed.pendingUpdate = true;
sharedFeedStore.updateSharedFeed(false);
}
currentTravelers.delete(ref.id);
}
if (
!instanceStore.cachedInstances.has(ref.$location.tag) &&
@@ -1651,7 +1645,7 @@ export const useUserStore = defineStore('User', () => {
ref.$customTag = data.Tag;
ref.$customTagColour = data.TagColour;
}
sharedFeedStore.updateSharedFeed(true);
sharedFeedStore.addTag(data.UserId, data.TagColour);
}
async function initUserNotes() {
+1 -2
View File
@@ -44,12 +44,11 @@ export const useVrStore = defineStore('Vr', () => {
updateVRLastLocation();
updateVrNowPlaying();
// run these methods again to send data to the overlay
sharedFeedStore.updateSharedFeed(true);
sharedFeedStore.sendSharedFeed();
friendStore.updateOnlineFriendCounter(true); // force an update
}
async function saveOpenVROption() {
sharedFeedStore.updateSharedFeed(true);
updateVRConfigVars();
updateVRLastLocation();
AppApi.ExecuteVrOverlayFunction('notyClear', '');