Update friends data after 10 minutes if the requested user isn't friends with the authenticated user

This commit is contained in:
Samuel Elliott 2022-11-16 12:44:04 +00:00
parent 19cb8c8775
commit fa877d5bd7
No known key found for this signature in database
GPG Key ID: 8420C7CDE43DC4D6

View File

@ -15,7 +15,7 @@ import { getBulletToken, SavedBulletToken } from '../common/auth/splatnet3.js';
import SplatNet3Api from '../api/splatnet3.js';
import { ErrorResponse } from '../api/util.js';
import { EventStreamResponse, HttpServer, ResponseError } from './util/http-server.js';
import { getTitleIdFromEcUrl } from '../index.js';
import { getTitleIdFromEcUrl } from '../util/misc.js';
const debug = createDebug('cli:presence-server');
@ -200,6 +200,8 @@ export class SplatNet3User {
class Server extends HttpServer {
allow_all_users = false;
update_interval = 30 * 1000;
/** Interval coral friends data should be updated if the requested user isn't friends with the authenticated user */
update_interval_unknown_friends = 10 * 60 * 1000; // 10 minutes
app: express.Express;
@ -346,7 +348,9 @@ class Server extends HttpServer {
user.update_interval = this.update_interval;
const has_friend = user.friends.result.friends.find(f => f.nsaId === presence_user_nsaid);
if (!has_friend) continue;
const skip_update_unknown_friends =
(user.updated.friends + this.update_interval_unknown_friends) > Date.now();
if (!has_friend && skip_update_unknown_friends) continue;
const friends = await user.getFriends();
const friend = friends.find(f => f.nsaId === presence_user_nsaid);