fix reblog and fav state to be global
This commit is contained in:
parent
21bade1dc9
commit
71e6e1ed18
|
@ -11,6 +11,7 @@ import { Status, Account, Results } from '../../../../services/models/mastodon.i
|
||||||
import { ToolsService, OpenThreadEvent } from '../../../../services/tools.service';
|
import { ToolsService, OpenThreadEvent } from '../../../../services/tools.service';
|
||||||
import { NotificationService } from '../../../../services/notification.service';
|
import { NotificationService } from '../../../../services/notification.service';
|
||||||
import { StatusWrapper } from '../../../../models/common.model';
|
import { StatusWrapper } from '../../../../models/common.model';
|
||||||
|
import { StatusesStateService, StatusState } from '../../../../services/statuses-state.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-action-bar',
|
selector: 'app-action-bar',
|
||||||
|
@ -43,7 +44,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
favoriteIsLoading: boolean;
|
favoriteIsLoading: boolean;
|
||||||
boostIsLoading: boolean;
|
boostIsLoading: boolean;
|
||||||
|
|
||||||
isContentWarningActive: boolean = false;
|
isContentWarningActive: boolean = false;
|
||||||
|
|
||||||
displayedStatus: Status;
|
displayedStatus: Status;
|
||||||
|
|
||||||
|
@ -55,10 +56,12 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
|
|
||||||
private accounts$: Observable<AccountInfo[]>;
|
private accounts$: Observable<AccountInfo[]>;
|
||||||
private accountSub: Subscription;
|
private accountSub: Subscription;
|
||||||
|
private statusStateSub: Subscription;
|
||||||
|
|
||||||
constructor(
|
constructor(
|
||||||
private readonly store: Store,
|
private readonly store: Store,
|
||||||
private readonly toolsService: ToolsService,
|
private readonly toolsService: ToolsService,
|
||||||
|
private readonly statusStateService: StatusesStateService,
|
||||||
private readonly mastodonService: MastodonWrapperService,
|
private readonly mastodonService: MastodonWrapperService,
|
||||||
private readonly notificationService: NotificationService) {
|
private readonly notificationService: NotificationService) {
|
||||||
|
|
||||||
|
@ -79,6 +82,8 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
this.displayedStatus = status;
|
this.displayedStatus = status;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.analyseMemoryStatus();
|
||||||
|
|
||||||
if (this.displayedStatus.visibility === 'direct') {
|
if (this.displayedStatus.visibility === 'direct') {
|
||||||
this.isDM = true;
|
this.isDM = true;
|
||||||
}
|
}
|
||||||
|
@ -86,10 +91,31 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
||||||
this.checkStatus(accounts);
|
this.checkStatus(accounts);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.statusStateSub = this.statusStateService.stateNotification.subscribe((state: StatusState) => {
|
||||||
|
if (state && state.statusId === this.displayedStatus.url) {
|
||||||
|
this.favoriteStatePerAccountId[state.accountId] = state.isFavorited;
|
||||||
|
this.bootedStatePerAccountId[state.accountId] = state.isRebloged;
|
||||||
|
|
||||||
|
this.checkIfFavorited();
|
||||||
|
this.checkIfBoosted();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
ngOnDestroy(): void {
|
ngOnDestroy(): void {
|
||||||
this.accountSub.unsubscribe();
|
this.accountSub.unsubscribe();
|
||||||
|
this.statusStateSub.unsubscribe();
|
||||||
|
}
|
||||||
|
|
||||||
|
private analyseMemoryStatus() {
|
||||||
|
let memoryStatusState = this.statusStateService.getStateForStatus(this.displayedStatus.url);
|
||||||
|
if (!memoryStatusState) return;
|
||||||
|
|
||||||
|
memoryStatusState.forEach((state: StatusState) => {
|
||||||
|
this.favoriteStatePerAccountId[state.accountId] = state.isFavorited;
|
||||||
|
this.bootedStatePerAccountId[state.accountId] = state.isRebloged;
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private checkStatus(accounts: AccountInfo[]): void {
|
private checkStatus(accounts: AccountInfo[]): void {
|
||||||
|
@ -156,7 +182,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
this.bootedStatePerAccountId[account.id] = boostedStatus.reblog !== null; //FIXME: when Pleroma will return the good status
|
this.bootedStatePerAccountId[account.id] = boostedStatus.reblog !== null; //FIXME: when Pleroma will return the good status
|
||||||
} else {
|
} else {
|
||||||
let reblogged = boostedStatus.reblogged; //FIXME: when pixelfed will return the good status
|
let reblogged = boostedStatus.reblogged; //FIXME: when pixelfed will return the good status
|
||||||
if(reblogged === null){
|
if (reblogged === null) {
|
||||||
reblogged = !this.bootedStatePerAccountId[account.id];
|
reblogged = !this.bootedStatePerAccountId[account.id];
|
||||||
}
|
}
|
||||||
this.bootedStatePerAccountId[account.id] = reblogged;
|
this.bootedStatePerAccountId[account.id] = reblogged;
|
||||||
|
@ -168,6 +194,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
this.notificationService.notifyHttpError(err, account);
|
this.notificationService.notifyHttpError(err, account);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this.statusStateService.statusReblogStatusChanged(this.displayedStatus.url, account.id, this.bootedStatePerAccountId[account.id]);
|
||||||
this.boostIsLoading = false;
|
this.boostIsLoading = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -192,7 +219,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
})
|
})
|
||||||
.then((favoritedStatus: Status) => {
|
.then((favoritedStatus: Status) => {
|
||||||
let favourited = favoritedStatus.favourited; //FIXME: when pixelfed will return the good status
|
let favourited = favoritedStatus.favourited; //FIXME: when pixelfed will return the good status
|
||||||
if(favourited === null){
|
if (favourited === null) {
|
||||||
favourited = !this.favoriteStatePerAccountId[account.id];
|
favourited = !this.favoriteStatePerAccountId[account.id];
|
||||||
}
|
}
|
||||||
this.favoriteStatePerAccountId[account.id] = favourited;
|
this.favoriteStatePerAccountId[account.id] = favourited;
|
||||||
|
@ -202,6 +229,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
this.notificationService.notifyHttpError(err, account);
|
this.notificationService.notifyHttpError(err, account);
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this.statusStateService.statusFavoriteStatusChanged(this.displayedStatus.url, account.id, this.favoriteStatePerAccountId[account.id]);
|
||||||
this.favoriteIsLoading = false;
|
this.favoriteIsLoading = false;
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -225,9 +253,9 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
||||||
} else {
|
} else {
|
||||||
this.isFavorited = false;
|
this.isFavorited = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
browseThread(event: OpenThreadEvent){
|
browseThread(event: OpenThreadEvent) {
|
||||||
this.browseThreadEvent.next(event);
|
this.browseThreadEvent.next(event);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,7 @@ describe('StatusesStateService', () => {
|
||||||
|
|
||||||
const service: StatusesStateService = TestBed.get(StatusesStateService);
|
const service: StatusesStateService = TestBed.get(StatusesStateService);
|
||||||
service.statusFavoriteStatusChanged(statusId, accountId, true);
|
service.statusFavoriteStatusChanged(statusId, accountId, true);
|
||||||
let result = service.getStateForStatus(statusId, accountId);
|
let result = service.getStateForStatus(statusId).find(x => x.accountId === accountId);
|
||||||
|
|
||||||
expect(result.isFavorited).toBeTruthy();
|
expect(result.isFavorited).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
@ -28,7 +28,7 @@ describe('StatusesStateService', () => {
|
||||||
|
|
||||||
const service: StatusesStateService = TestBed.get(StatusesStateService);
|
const service: StatusesStateService = TestBed.get(StatusesStateService);
|
||||||
service.statusReblogStatusChanged(statusId, accountId, true);
|
service.statusReblogStatusChanged(statusId, accountId, true);
|
||||||
let result = service.getStateForStatus(statusId, accountId);
|
let result = service.getStateForStatus(statusId).find(x => x.accountId === accountId);
|
||||||
|
|
||||||
expect(result.isRebloged).toBeTruthy();
|
expect(result.isRebloged).toBeTruthy();
|
||||||
});
|
});
|
||||||
|
@ -40,7 +40,7 @@ describe('StatusesStateService', () => {
|
||||||
const service: StatusesStateService = TestBed.get(StatusesStateService);
|
const service: StatusesStateService = TestBed.get(StatusesStateService);
|
||||||
service.statusFavoriteStatusChanged(statusId, accountId, true);
|
service.statusFavoriteStatusChanged(statusId, accountId, true);
|
||||||
service.statusFavoriteStatusChanged(statusId, accountId, false);
|
service.statusFavoriteStatusChanged(statusId, accountId, false);
|
||||||
let result = service.getStateForStatus(statusId, accountId);
|
let result = service.getStateForStatus(statusId).find(x => x.accountId === accountId);
|
||||||
|
|
||||||
expect(result.isFavorited).toBeFalsy();
|
expect(result.isFavorited).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
@ -52,7 +52,7 @@ describe('StatusesStateService', () => {
|
||||||
const service: StatusesStateService = TestBed.get(StatusesStateService);
|
const service: StatusesStateService = TestBed.get(StatusesStateService);
|
||||||
service.statusReblogStatusChanged(statusId, accountId, true);
|
service.statusReblogStatusChanged(statusId, accountId, true);
|
||||||
service.statusReblogStatusChanged(statusId, accountId, false);
|
service.statusReblogStatusChanged(statusId, accountId, false);
|
||||||
let result = service.getStateForStatus(statusId, accountId);
|
let result = service.getStateForStatus(statusId).find(x => x.accountId === accountId);
|
||||||
|
|
||||||
expect(result.isRebloged).toBeFalsy();
|
expect(result.isRebloged).toBeFalsy();
|
||||||
});
|
});
|
||||||
|
|
|
@ -11,11 +11,17 @@ export class StatusesStateService {
|
||||||
|
|
||||||
constructor() { }
|
constructor() { }
|
||||||
|
|
||||||
getStateForStatus(statusId: string, accountId: string): StatusState {
|
getStateForStatus(statusId: string): StatusState[] {
|
||||||
if(!this.cachedStatusStates[statusId] || !this.cachedStatusStates[statusId][accountId])
|
if(!this.cachedStatusStates[statusId])
|
||||||
return null;
|
return null;
|
||||||
|
|
||||||
return this.cachedStatusStates[statusId][accountId];
|
let results: StatusState[] = [];
|
||||||
|
Object.entries(this.cachedStatusStates[statusId]).forEach(
|
||||||
|
([key, value]) => {
|
||||||
|
results.push(value);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
return results;
|
||||||
}
|
}
|
||||||
|
|
||||||
statusFavoriteStatusChanged(statusId: string, accountId: string, isFavorited: boolean) {
|
statusFavoriteStatusChanged(statusId: string, accountId: string, isFavorited: boolean) {
|
||||||
|
@ -45,8 +51,11 @@ export class StatusesStateService {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export class StatusState {
|
||||||
class StatusState {
|
constructor(
|
||||||
constructor(public statusId: string, public accountId: string, public isFavorited: boolean, public isRebloged: boolean) {
|
public statusId: string,
|
||||||
|
public accountId: string,
|
||||||
|
public isFavorited: boolean,
|
||||||
|
public isRebloged: boolean) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue