Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/frontend/src/boot/main-boot.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import { prefer } from '@/preferences.js';
import { updateCurrentAccountPartial } from '@/accounts.js';
import { migrateOldSettings } from '@/pref-migrate.js';
import { unisonReload } from '@/utility/unison-reload.js';
import { miRegistoryItem } from '@/registry-item.js';

export async function mainBoot() {
const { isClientUpdated, lastVersion } = await common(async () => {
Expand Down Expand Up @@ -285,6 +286,8 @@ export async function mainBoot() {
// }
//}
//miLocalStorage.setItem('lastUsed', Date.now().toString());
const channelLastReadedAt = await miRegistoryItem.get('channelsLastReadedAt');
miLocalStorage.setItemAsJson('channelsLastReadedAt', channelLastReadedAt);

const latestDonationInfoShownAt = miLocalStorage.getItem('latestDonationInfoShownAt');
const neverShowDonationInfo = miLocalStorage.getItem('neverShowDonationInfo');
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/components/MkChannelPreview.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const props = defineProps<{
}>();

const getLastReadedAt = (): number | null => {
return miLocalStorage.getItemAsJson(`channelLastReadedAt:${props.channel.id}`) ?? null;
return miLocalStorage.getItemAsJson('channelsLastReadedAt')[props.channel.id] ?? null;
};

const lastReadedAt = ref(getLastReadedAt());
Expand Down
3 changes: 2 additions & 1 deletion packages/frontend/src/local-storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ export type Keys = (
`aiscript:${string}` |
'lastEmojisFetchedAt' | // DEPRECATED, stored in indexeddb (13.9.0~)
'emojis' | // DEPRECATED, stored in indexeddb (13.9.0~);
`channelLastReadedAt:${string}` |
`channelLastReadedAt:${string}` | // DEPRECATED, stored channelsLastReadedAt and registry
'channelsLastReadedAt' |
`idbfallback::${string}`
);

Expand Down
18 changes: 16 additions & 2 deletions packages/frontend/src/pages/channel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ import { notesSearchAvailable } from '@/utility/check-permissions.js';
import { miLocalStorage } from '@/local-storage.js';
import { useRouter } from '@/router.js';
import { Paginator } from '@/utility/paginator.js';
import { miRegistoryItem } from '@/registry-item';

const router = useRouter();

Expand Down Expand Up @@ -139,15 +140,28 @@ watch(() => props.channelId, async () => {
}

if ((favorited.value || channel.value.isFollowing) && channel.value.lastNotedAt) {
const lastReadedAt: number = miLocalStorage.getItemAsJson(`channelLastReadedAt:${channel.value.id}`) ?? 0;
const lastReadedAt = miLocalStorage.getItemAsJson('channelsLastReadedAt')[channel.value.id] ?? undefined;
const lastNotedAt = Date.parse(channel.value.lastNotedAt);

if (!lastReadedAt) {
saveLastReadedAt();
return;
}

if (lastNotedAt > lastReadedAt) {
miLocalStorage.setItemAsJson(`channelLastReadedAt:${channel.value.id}`, lastNotedAt);
saveLastReadedAt();
}
}
}, { immediate: true });

async function saveLastReadedAt() {
if (!channel.value) return;
const tmp = await miRegistoryItem.get('channelsLastReadedAt');
tmp[channel.value.id] = Date.now();
await miRegistoryItem.set('channelsLastReadedAt', tmp);
miLocalStorage.setItemAsJson('channelsLastReadedAt', tmp);
}

function edit() {
router.push('/channels/:channelId/edit', {
params: {
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/pages/timeline.vue
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ async function chooseChannel(ev: MouseEvent): Promise<void> {
const channels = await favoritedChannelsCache.fetch();
const items: (MenuItem | undefined)[] = [
...channels.map(channel => {
const lastReadedAt = miLocalStorage.getItemAsJson(`channelLastReadedAt:${channel.id}`) ?? null;
const lastReadedAt = miLocalStorage.getItemAsJson('channelsLastReadedAt')[channel.id] ?? null;
const hasUnreadNote = (lastReadedAt && channel.lastNotedAt) ? Date.parse(channel.lastNotedAt) > lastReadedAt : !!(!lastReadedAt && channel.lastNotedAt);

return {
Expand Down
25 changes: 25 additions & 0 deletions packages/frontend/src/registry-item.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* SPDX-FileCopyrightText: syuilo and misskey-project
* SPDX-License-Identifier: AGPL-3.0-only
*/

import { misskeyApi } from '@/utility/misskey-api.js';

export type Keys =
'channelsLastReadedAt' | // DEPRECATED, stored registory(2025.1.xxx)
'somethingElse';

export const miRegistoryItem = {
async get(key: Keys) {
try {
return JSON.parse(await misskeyApi('i/registry/get', { scope: ['client'], key }));
} catch (err) {
if (err.code === 'NO_SUCH_KEY') return {};
throw err;
}
},
async set(key: Keys, payload) {
await misskeyApi('i/registry/set', { scope: ['client'], key, value: JSON.stringify(payload) });
},
};

Loading