0
0
Fork 0

アラート機能の全面的な書き直し

close #67
This commit is contained in:
Xeltica 2023-02-23 19:37:10 +09:00
parent 6cecc7bec7
commit d2b3b4b9e7
13 changed files with 207 additions and 118 deletions

View file

@ -1,25 +1,17 @@
import { User } from '../models/entities/user';
import { Score } from '../../common/types/score';
import { api } from '../services/misskey';
import { toSignedString } from '../../common/functions/to-signed-string';
import {Count} from '../models/count';
/**
*
*
* @param user
* @returns
* @param count
* @returns
*/
export const getScores = async (user: User): Promise<Score> => {
// TODO 毎回取ってくるのも微妙なので、ある程度キャッシュしたいかも
const miUser = await api<Record<string, number>>(user.host, 'users/show', { username: user.username }, user.token);
if (miUser.error) {
throw miUser.error;
}
export const getDelta = (user: User, count: Count) => {
return {
notesCount: miUser.notesCount,
followingCount: miUser.followingCount,
followersCount: miUser.followersCount,
notesDelta: toSignedString(miUser.notesCount - user.prevNotesCount),
followingDelta: toSignedString(miUser.followingCount - user.prevFollowingCount),
followersDelta: toSignedString(miUser.followersCount - user.prevFollowersCount),
notesDelta: toSignedString(count.notesCount - user.prevNotesCount),
followingDelta: toSignedString(count.followingCount - user.prevFollowingCount),
followersDelta: toSignedString(count.followersCount - user.prevFollowersCount),
};
};