removing deleted status from account and thread

This commit is contained in:
Nicolas Constant 2019-07-05 23:41:03 -04:00
parent b8fcfb6cb5
commit 2d01b3297e
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
4 changed files with 71 additions and 10 deletions

View File

@ -8,7 +8,7 @@ import { ContextMenuComponent, ContextMenuService } from 'ngx-contextmenu';
import { MastodonService } from '../../../../services/mastodon.service';
import { AccountInfo } from '../../../../states/accounts.state';
import { Status, Account } from '../../../../services/models/mastodon.interfaces';
import { Status, Account, Results } from '../../../../services/models/mastodon.interfaces';
import { ToolsService, OpenThreadEvent } from '../../../../services/tools.service';
import { NotificationService } from '../../../../services/notification.service';
import { StatusWrapper } from '../../../../models/common.model';
@ -60,7 +60,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
username: string;
displayedStatus: Status;
private fullHandle: string;
private fullHandle: string;
private loadedAccounts: AccountInfo[];
private favoriteStatePerAccountId: { [id: string]: boolean; } = {};
@ -96,7 +96,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
this.displayedStatus = status;
}
if(this.displayedStatus.visibility === 'direct'){
if (this.displayedStatus.visibility === 'direct') {
this.isDM = true;
}
@ -125,7 +125,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
this.selectedAccounts = accounts.filter(x => x.isSelected);
this.isProviderSelected = this.selectedAccounts.filter(x => x.id === provider.id).length > 0;
this.isOwnerSelected = this.selectedAccounts[0].username === this.displayedStatus.account.username
this.isOwnerSelected = this.selectedAccounts[0].username === this.displayedStatus.account.username
&& this.selectedAccounts[0].instance === this.displayedStatus.account.url.replace('https://', '').split('/')[0];
if (status.visibility === 'direct' || status.visibility === 'private') {
@ -331,7 +331,11 @@ export class ActionBarComponent implements OnInit, OnDestroy {
muteConversation(): boolean {
const selectedAccount = this.selectedAccounts[0];
this.mastodonService.muteConversation(selectedAccount, this.displayedStatus.id)
this.getStatus(selectedAccount)
.then((status: Status) => {
return this.mastodonService.muteConversation(selectedAccount, status.id)
})
.then((status: Status) => {
this.displayedStatus.muted = status.muted;
})
@ -344,7 +348,11 @@ export class ActionBarComponent implements OnInit, OnDestroy {
unmuteConversation(): boolean {
const selectedAccount = this.selectedAccounts[0];
this.mastodonService.unmuteConversation(selectedAccount, this.displayedStatus.id)
this.getStatus(selectedAccount)
.then((status: Status) => {
return this.mastodonService.unmuteConversation(selectedAccount, status.id)
})
.then((status: Status) => {
this.displayedStatus.muted = status.muted;
})
@ -357,7 +365,11 @@ export class ActionBarComponent implements OnInit, OnDestroy {
pinOnProfile(): boolean {
const selectedAccount = this.selectedAccounts[0];
this.mastodonService.pinOnProfile(selectedAccount, this.displayedStatus.id)
this.getStatus(selectedAccount)
.then((status: Status) => {
return this.mastodonService.pinOnProfile(selectedAccount, status.id)
})
.then((status: Status) => {
this.displayedStatus.pinned = status.pinned;
})
@ -370,7 +382,11 @@ export class ActionBarComponent implements OnInit, OnDestroy {
unpinFromProfile(): boolean {
const selectedAccount = this.selectedAccounts[0];
this.mastodonService.unpinFromProfile(selectedAccount, this.displayedStatus.id)
this.getStatus(selectedAccount)
.then((status: Status) => {
return this.mastodonService.unpinFromProfile(selectedAccount, status.id)
})
.then((status: Status) => {
this.displayedStatus.pinned = status.pinned;
})
@ -383,9 +399,16 @@ export class ActionBarComponent implements OnInit, OnDestroy {
delete(redraft: boolean): boolean {
const selectedAccount = this.selectedAccounts[0];
this.mastodonService.deleteStatus(selectedAccount, this.displayedStatus.id)
this.getStatus(selectedAccount)
.then((status: Status) => {
return this.mastodonService.deleteStatus(selectedAccount, status.id);
})
.then(() => {
if(redraft){
const deletedStatus = new StatusWrapper(this.displayedStatus, selectedAccount);
this.notificationService.deleteStatus(deletedStatus);
if (redraft) {
//TODO
}
})
@ -395,4 +418,17 @@ export class ActionBarComponent implements OnInit, OnDestroy {
return false;
}
private getStatus(account: AccountInfo): Promise<Status> {
let statusPromise: Promise<Status> = Promise.resolve(this.statusWrapper.status);
if (account.id !== this.statusWrapper.provider.id) {
statusPromise = this.mastodonService.search(account, this.statusWrapper.status.url, true)
.then((result: Results) => {
return result.statuses[0];
});
}
return statusPromise;
}
}

View File

@ -40,6 +40,7 @@ export class ThreadComponent implements OnInit, OnDestroy {
private newPostSub: Subscription;
private hideAccountSubscription: Subscription;
private deleteStatusSubscription: Subscription;
constructor(
private readonly notificationService: NotificationService,
@ -82,11 +83,20 @@ export class ThreadComponent implements OnInit, OnDestroy {
});
}
});
this.deleteStatusSubscription = this.notificationService.deletedStatusStream.subscribe((status: StatusWrapper) => {
if(status){
this.statuses = this.statuses.filter(x => {
return !(x.status.url.replace('https://','').split('/')[0] === status.provider.instance && x.status.id === status.status.id);
});
}
});
}
ngOnDestroy(): void {
if (this.newPostSub) this.newPostSub.unsubscribe();
if (this.hideAccountSubscription) this.hideAccountSubscription.unsubscribe();
if (this.deleteStatusSubscription) this.deleteStatusSubscription.unsubscribe();
}
private getThread(openThreadEvent: OpenThreadEvent) {

View File

@ -47,6 +47,7 @@ export class UserProfileComponent implements OnInit {
private currentlyUsedAccount: AccountInfo;
private accounts$: Observable<AccountInfo[]>;
private accountSub: Subscription;
private deleteStatusSubscription: Subscription;
@ViewChild('statusstream') public statustream: ElementRef;
@ -83,10 +84,19 @@ export class UserProfileComponent implements OnInit {
});
}
});
this.deleteStatusSubscription = this.notificationService.deletedStatusStream.subscribe((status: StatusWrapper) => {
if(status){
this.statuses = this.statuses.filter(x => {
return !(x.status.url.replace('https://','').split('/')[0] === status.provider.instance && x.status.id === status.status.id);
});
}
});
}
ngOnDestroy() {
this.accountSub.unsubscribe();
this.deleteStatusSubscription.unsubscribe();
}
private load(accountName: string) {

View File

@ -9,6 +9,7 @@ export class NotificationService {
public notifactionStream = new Subject<NotificatioData>();
public newRespondPostedStream = new Subject<NewReplyData>();
public hideAccountUrlStream = new Subject<string>();
public deletedStatusStream = new Subject<StatusWrapper>();
constructor() {
}
@ -36,6 +37,10 @@ export class NotificationService {
public hideAccount(account: Account){
this.hideAccountUrlStream.next(account.url);
}
public deleteStatus(status: StatusWrapper){
this.deletedStatusStream.next(status);
}
}
export class NotificatioData {