2020-02-16 07:39:45 +01:00
|
|
|
import { Injectable } from '@angular/core';
|
|
|
|
|
|
|
|
import { Subject } from 'rxjs';
|
|
|
|
|
|
|
|
@Injectable({
|
|
|
|
providedIn: 'root'
|
|
|
|
})
|
|
|
|
export class StatusesStateService {
|
|
|
|
private cachedStatusStates: { [statusId: string]: { [accountId: string]: StatusState } } = {};
|
|
|
|
public stateNotification = new Subject<StatusState>();
|
|
|
|
|
|
|
|
constructor() { }
|
|
|
|
|
2020-02-19 05:51:34 +01:00
|
|
|
getStateForStatus(statusId: string): StatusState[] {
|
|
|
|
if(!this.cachedStatusStates[statusId])
|
2020-02-16 07:39:45 +01:00
|
|
|
return null;
|
|
|
|
|
2020-02-19 05:51:34 +01:00
|
|
|
let results: StatusState[] = [];
|
|
|
|
Object.entries(this.cachedStatusStates[statusId]).forEach(
|
|
|
|
([key, value]) => {
|
|
|
|
results.push(value);
|
|
|
|
}
|
|
|
|
);
|
|
|
|
return results;
|
2020-02-16 07:39:45 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
statusFavoriteStatusChanged(statusId: string, accountId: string, isFavorited: boolean) {
|
|
|
|
if (!this.cachedStatusStates[statusId])
|
|
|
|
this.cachedStatusStates[statusId] = {};
|
|
|
|
|
|
|
|
if (!this.cachedStatusStates[statusId][accountId]) {
|
|
|
|
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, isFavorited, false);
|
|
|
|
} else {
|
|
|
|
this.cachedStatusStates[statusId][accountId].isFavorited = isFavorited;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.stateNotification.next(this.cachedStatusStates[statusId][accountId]);
|
|
|
|
}
|
|
|
|
|
|
|
|
statusReblogStatusChanged(statusId: string, accountId: string, isRebloged: boolean) {
|
|
|
|
if (!this.cachedStatusStates[statusId])
|
|
|
|
this.cachedStatusStates[statusId] = {};
|
|
|
|
|
|
|
|
if (!this.cachedStatusStates[statusId][accountId]) {
|
|
|
|
this.cachedStatusStates[statusId][accountId] = new StatusState(statusId, accountId, false, isRebloged);
|
|
|
|
} else {
|
|
|
|
this.cachedStatusStates[statusId][accountId].isRebloged = isRebloged;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.stateNotification.next(this.cachedStatusStates[statusId][accountId]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-02-19 05:51:34 +01:00
|
|
|
export class StatusState {
|
|
|
|
constructor(
|
|
|
|
public statusId: string,
|
|
|
|
public accountId: string,
|
|
|
|
public isFavorited: boolean,
|
|
|
|
public isRebloged: boolean) {
|
2020-02-16 07:39:45 +01:00
|
|
|
}
|
|
|
|
}
|