Merge commit 'f8bb37e12f96c86bb44a53ac28d06cc522cf7ab9' as 'backend'

This commit is contained in:
2026-04-27 22:44:05 +02:00
44 changed files with 7444 additions and 0 deletions
+33
View File
@@ -0,0 +1,33 @@
import { Types } from "mongoose";
import { Observer, Subject } from "rxjs";
export interface SyncEvent {
type: string
}
class SyncHelper {
private userSubjects = new Map<string, Subject<SyncEvent>>()
public subscribe(uid: Types.ObjectId, observer: Observer<SyncEvent> | ((value: SyncEvent) => void)) {
const uid_s = uid.toString()
if (!this.userSubjects.has(uid_s)) {
this.userSubjects.set(uid_s, new Subject())
}
return this.userSubjects.get(uid_s).asObservable().subscribe(observer)
}
public next(uid: Types.ObjectId, value: SyncEvent) {
const uid_s = uid.toString()
if (this.userSubjects.has(uid_s)) {
this.userSubjects.get(uid_s).next(value)
}
}
nextEach(value: SyncEvent) {
this.userSubjects.forEach(v => {
v.next(value)
})
}
}
export default new SyncHelper();