-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ee35ff5
commit 96925fa
Showing
10 changed files
with
200 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
import { User } from '../../chat' | ||
import { FirebaseService } from './firebase-service' | ||
import { Keys } from './keys' | ||
import { Paths } from './paths' | ||
|
||
export class MuteService { | ||
|
||
private static instance: MuteService | ||
|
||
protected muted: { [key: string]: Date } = {} | ||
|
||
static get shared() { | ||
if (!this.instance) { | ||
this.instance = new MuteService() | ||
} | ||
return this.instance | ||
} | ||
|
||
static add(id: string, until: Date) { | ||
this.shared.muted[id] = until | ||
} | ||
|
||
static remove(id: string) { | ||
delete this.shared.muted[id] | ||
} | ||
|
||
static mute(user: User | string, until?: Date): Promise<void> { | ||
if (typeof user === 'string') { | ||
return FirebaseService.core.mute(Paths.userMutedPath().child(user), { | ||
[Keys.Date]: until != null ? until.getTime() : Number.MAX_SAFE_INTEGER | ||
}) | ||
} else { | ||
return this.mute(user.getId(), until) | ||
} | ||
} | ||
|
||
static unmute(user: User | string): Promise<void> { | ||
if (typeof user === 'string') { | ||
return FirebaseService.core.unmute(Paths.userMutedPath().child(user)) | ||
} else { | ||
return this.unmute(user.getId()) | ||
} | ||
} | ||
|
||
static mutedUntil(user: User | string): Date | undefined { | ||
if (typeof user === 'string') { | ||
return this.shared.muted[user] | ||
} else { | ||
return this.mutedUntil(user.getId()) | ||
} | ||
} | ||
|
||
static isMuted(user: User | string): boolean { | ||
if (typeof user === 'string') { | ||
return this.mutedUntil(user) != null | ||
} else { | ||
return this.isMuted(user.getId()) | ||
} | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters