チャンネル既読の同期
This commit is contained in:
parent
978289535b
commit
8b61f1a237
|
@ -30,6 +30,7 @@ import { launchPlugins } from '@/plugin.js';
|
||||||
import { updateCurrentAccountPartial } from '@/accounts.js';
|
import { updateCurrentAccountPartial } from '@/accounts.js';
|
||||||
import { signout } from '@/signout.js';
|
import { signout } from '@/signout.js';
|
||||||
import { migrateOldSettings } from '@/pref-migrate.js';
|
import { migrateOldSettings } from '@/pref-migrate.js';
|
||||||
|
import { miRegistoryItem } from '@/registry-item.js';
|
||||||
|
|
||||||
export async function mainBoot() {
|
export async function mainBoot() {
|
||||||
const { isClientUpdated, lastVersion } = await common(async () => {
|
const { isClientUpdated, lastVersion } = await common(async () => {
|
||||||
|
@ -323,6 +324,8 @@ export async function mainBoot() {
|
||||||
// }
|
// }
|
||||||
//}
|
//}
|
||||||
//miLocalStorage.setItem('lastUsed', Date.now().toString());
|
//miLocalStorage.setItem('lastUsed', Date.now().toString());
|
||||||
|
const channelLastReadedAt = await miRegistoryItem.get('channelsLastReadedAt');
|
||||||
|
miLocalStorage.setItemAsJson('channelsLastReadedAt', channelLastReadedAt);
|
||||||
|
|
||||||
const latestDonationInfoShownAt = miLocalStorage.getItem('latestDonationInfoShownAt');
|
const latestDonationInfoShownAt = miLocalStorage.getItem('latestDonationInfoShownAt');
|
||||||
const neverShowDonationInfo = miLocalStorage.getItem('neverShowDonationInfo');
|
const neverShowDonationInfo = miLocalStorage.getItem('neverShowDonationInfo');
|
||||||
|
|
|
@ -56,7 +56,7 @@ const props = defineProps<{
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const getLastReadedAt = (): number | null => {
|
const getLastReadedAt = (): number | null => {
|
||||||
return miLocalStorage.getItemAsJson(`channelLastReadedAt:${props.channel.id}`) ?? null;
|
return miLocalStorage.getItemAsJson('channelsLastReadedAt')[props.channel.id] ?? null;
|
||||||
};
|
};
|
||||||
|
|
||||||
const lastReadedAt = ref(getLastReadedAt());
|
const lastReadedAt = ref(getLastReadedAt());
|
||||||
|
|
|
@ -39,7 +39,8 @@ export type Keys = (
|
||||||
`aiscript:${string}` |
|
`aiscript:${string}` |
|
||||||
'lastEmojisFetchedAt' | // DEPRECATED, stored in indexeddb (13.9.0~)
|
'lastEmojisFetchedAt' | // DEPRECATED, stored in indexeddb (13.9.0~)
|
||||||
'emojis' | // 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}`
|
`idbfallback::${string}`
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
|
@ -96,6 +96,7 @@ import { copyToClipboard } from '@/utility/copy-to-clipboard.js';
|
||||||
import { notesSearchAvailable } from '@/utility/check-permissions.js';
|
import { notesSearchAvailable } from '@/utility/check-permissions.js';
|
||||||
import { miLocalStorage } from '@/local-storage.js';
|
import { miLocalStorage } from '@/local-storage.js';
|
||||||
import { useRouter } from '@/router.js';
|
import { useRouter } from '@/router.js';
|
||||||
|
import { miRegistoryItem } from '@/registry-item';
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
|
||||||
|
@ -122,21 +123,35 @@ watch(() => props.channelId, async () => {
|
||||||
channel.value = await misskeyApi('channels/show', {
|
channel.value = await misskeyApi('channels/show', {
|
||||||
channelId: props.channelId,
|
channelId: props.channelId,
|
||||||
});
|
});
|
||||||
|
if (!channel.value) return;
|
||||||
favorited.value = channel.value.isFavorited ?? false;
|
favorited.value = channel.value.isFavorited ?? false;
|
||||||
if (favorited.value || channel.value.isFollowing) {
|
if (favorited.value || channel.value.isFollowing) {
|
||||||
tab.value = 'timeline';
|
tab.value = 'timeline';
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((favorited.value || channel.value.isFollowing) && channel.value.lastNotedAt) {
|
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);
|
const lastNotedAt = Date.parse(channel.value.lastNotedAt);
|
||||||
|
|
||||||
|
if (!lastReadedAt) {
|
||||||
|
saveLastReadedAt();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (lastNotedAt > lastReadedAt) {
|
if (lastNotedAt > lastReadedAt) {
|
||||||
miLocalStorage.setItemAsJson(`channelLastReadedAt:${channel.value.id}`, lastNotedAt);
|
saveLastReadedAt();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, { immediate: true });
|
}, { 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() {
|
function edit() {
|
||||||
router.push(`/channels/${channel.value?.id}/edit`);
|
router.push(`/channels/${channel.value?.id}/edit`);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,7 +165,7 @@ async function chooseChannel(ev: MouseEvent): Promise<void> {
|
||||||
const channels = await favoritedChannelsCache.fetch();
|
const channels = await favoritedChannelsCache.fetch();
|
||||||
const items: MenuItem[] = [
|
const items: MenuItem[] = [
|
||||||
...channels.map(channel => {
|
...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);
|
const hasUnreadNote = (lastReadedAt && channel.lastNotedAt) ? Date.parse(channel.lastNotedAt) > lastReadedAt : !!(!lastReadedAt && channel.lastNotedAt);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
|
|
@ -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…
Reference in New Issue