Setting a variable to undefined now removes it from server-side storage.

This commit is contained in:
David Négrier 2021-07-19 18:46:33 +02:00
parent d955ddfe82
commit ac3d1240ae
3 changed files with 29 additions and 8 deletions

View file

@ -8,12 +8,16 @@ import { VariablesRepositoryInterface } from "./VariablesRepositoryInterface";
export class RedisVariablesRepository implements VariablesRepositoryInterface {
private readonly hgetall: OmitThisParameter<(arg1: string) => Promise<{ [p: string]: string }>>;
private readonly hset: OmitThisParameter<(arg1: [string, ...string[]]) => Promise<number>>;
private readonly hdel: OmitThisParameter<(arg1: string, arg2: string) => Promise<number>>;
constructor(redisClient: RedisClient) {
constructor(private redisClient: RedisClient) {
// @eslint-disable-next-line @typescript-eslint/unbound-method
this.hgetall = promisify(redisClient.hgetall).bind(redisClient);
// @eslint-disable-next-line @typescript-eslint/unbound-method
this.hset = promisify(redisClient.hset).bind(redisClient);
// @eslint-disable-next-line @typescript-eslint/unbound-method
this.hdel = promisify(redisClient.hdel).bind(redisClient);
}
/**
@ -26,11 +30,13 @@ export class RedisVariablesRepository implements VariablesRepositoryInterface {
}
async saveVariable(roomUrl: string, key: string, value: string): Promise<number> {
// TODO: handle the case for "undefined"
// TODO: handle the case for "undefined"
// TODO: handle the case for "undefined"
// TODO: handle the case for "undefined"
// TODO: handle the case for "undefined"
// The value is passed to JSON.stringify client side. If value is "undefined", JSON.stringify returns "undefined"
// which is translated to empty string when fetching the value in the pusher.
// Therefore, empty string server side == undefined client side.
if (value === '') {
return this.hdel(roomUrl, key);
}
// TODO: SLOW WRITING EVERY 2 SECONDS WITH A TIMEOUT