* fix: notifications-groupedのinclude/exclude typesに:groupedを指定できてしまう問題 * refactor: 通知の取得処理を Notification Service に移動 * feat: add function to parse additional part of id * fix: 通知のページネーションが正しく動かない問題 Redisにのページネーションで使用する時間及びidとRedis上のものが混同されていたので、Misskeyが生成するものに寄せました。 * pnpm run build-misskey-js-with-types * chore: XADDをretryするように * fix: notifications-groupedでxrevrangeしているのを消し忘れていた
53 lines
1.1 KiB
TypeScript
53 lines
1.1 KiB
TypeScript
/*
|
|
* SPDX-FileCopyrightText: syuilo and misskey-project
|
|
* SPDX-License-Identifier: AGPL-3.0-only
|
|
*/
|
|
|
|
import { parseBigInt16 } from '@/misc/bigint.js';
|
|
|
|
const CHARS = '0123456789abcdef';
|
|
|
|
// 4bit Fixed hex value 'g'
|
|
// 44bit UNIX Time ms in Hex
|
|
// 48bit Random value in Hex
|
|
export const meidgRegExp = /^g[0-9a-f]{23}$/;
|
|
|
|
function getTime(time: number) {
|
|
if (time < 0) time = 0;
|
|
if (time === 0) {
|
|
return CHARS[0];
|
|
}
|
|
|
|
return time.toString(16).padStart(11, CHARS[0]);
|
|
}
|
|
|
|
function getRandom() {
|
|
let str = '';
|
|
|
|
for (let i = 0; i < 12; i++) {
|
|
str += CHARS[Math.floor(Math.random() * CHARS.length)];
|
|
}
|
|
|
|
return str;
|
|
}
|
|
|
|
export function genMeidg(t: number): string {
|
|
return 'g' + getTime(t) + getRandom();
|
|
}
|
|
|
|
export function parseMeidg(id: string): { date: Date; } {
|
|
return {
|
|
date: new Date(parseInt(id.slice(1, 12), 16)),
|
|
};
|
|
}
|
|
|
|
export function parseMeidgFull(id: string): { date: number; additional: bigint; } {
|
|
return {
|
|
date: parseInt(id.slice(1, 12), 16),
|
|
additional: parseBigInt16(id.slice(12, 24)),
|
|
};
|
|
}
|
|
|
|
export function isSafeMeidgT(t: number): boolean {
|
|
return t > 0;
|
|
}
|