added unmute / unblock, fix #341

This commit is contained in:
Nicolas Constant 2023-04-23 19:21:54 -04:00
parent 2bcac4622a
commit 9999944d1f
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
5 changed files with 69 additions and 4 deletions

View File

@ -28,11 +28,17 @@
Unmute conversation
</ng-template>
<ng-template contextMenuItem divider="true"></ng-template>
<ng-template contextMenuItem (execute)="muteAccount()" *ngIf="!isOwnerSelected">
<ng-template contextMenuItem (execute)="muteAccount()" *ngIf="!isOwnerSelected && this.relationship && !this.relationship.muting">
Mute @{{ this.username }}
</ng-template>
<ng-template contextMenuItem (execute)="blockAccount()" *ngIf="!isOwnerSelected">
<ng-template contextMenuItem (execute)="unmuteAccount()" *ngIf="!isOwnerSelected && this.relationship && this.relationship.muting">
Unmute @{{ this.username }}
</ng-template>
<ng-template contextMenuItem (execute)="blockAccount()" *ngIf="!isOwnerSelected && this.relationship && !this.relationship.blocking">
Block @{{ this.username }}
</ng-template>
<ng-template contextMenuItem (execute)="unblockAccount()" *ngIf="!isOwnerSelected && this.relationship && this.relationship.blocking">
Unblock @{{ this.username }}
</ng-template>
<ng-template contextMenuItem (execute)="pinOnProfile()" *ngIf="statusWrapper && isOwnerSelected && !displayedStatus.pinned && displayedStatus.visibility === 'public'">
Pin on profile

View File

@ -4,7 +4,7 @@ import { ContextMenuComponent, ContextMenuService } from 'ngx-contextmenu';
import { Observable, Subscription } from 'rxjs';
import { Store } from '@ngxs/store';
import { Status, Account, Results } from '../../../../../services/models/mastodon.interfaces';
import { Status, Account, Results, Relationship } from '../../../../../services/models/mastodon.interfaces';
import { ToolsService, OpenThreadEvent, InstanceInfo } from '../../../../../services/tools.service';
import { StatusWrapper } from '../../../../../models/common.model';
import { NavigationService } from '../../../../../services/navigation.service';
@ -31,6 +31,7 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
@Input() statusWrapper: StatusWrapper;
@Input() displayedAccount: Account;
@Input() relationship: Relationship;
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@ -183,6 +184,21 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
return false;
}
unmuteAccount(): boolean {
this.loadedAccounts.forEach(acc => {
this.toolsService.findAccount(acc, this.fullHandle)
.then((target: Account) => {
this.mastodonService.unmute(acc, target.id);
return target;
})
.catch(err => {
this.notificationService.notifyHttpError(err, acc);
});
});
return false;
}
blockAccount(): boolean {
this.loadedAccounts.forEach(acc => {
this.toolsService.findAccount(acc, this.fullHandle)
@ -201,6 +217,21 @@ export class StatusUserContextMenuComponent implements OnInit, OnDestroy {
return false;
}
unblockAccount(): boolean {
this.loadedAccounts.forEach(acc => {
this.toolsService.findAccount(acc, this.fullHandle)
.then((target: Account) => {
this.mastodonService.unblock(acc, target.id);
return target;
})
.catch(err => {
this.notificationService.notifyHttpError(err, acc);
});
});
return false;
}
muteConversation(): boolean {
const selectedAccount = this.toolsService.getSelectedAccounts()[0];

View File

@ -107,7 +107,9 @@
</div>
</div>
<app-status-user-context-menu class="profile-header__more" [displayedAccount]="displayedAccount">
<app-status-user-context-menu class="profile-header__more"
[displayedAccount]="displayedAccount"
[relationship]="relationship">
</app-status-user-context-menu>
</div>

View File

@ -379,6 +379,13 @@ export class MastodonWrapperService {
});
}
unmute(account: AccountInfo, accounId: number): Promise<Relationship> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.unmute(refreshedAccount, accounId);
});
}
block(account: AccountInfo, accounId: number): Promise<Relationship> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
@ -386,6 +393,13 @@ export class MastodonWrapperService {
});
}
unblock(account: AccountInfo, accounId: number): Promise<Relationship> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {
return this.mastodonService.unblock(refreshedAccount, accounId);
});
}
pinOnProfile(account: AccountInfo, statusId: string): Promise<Status> {
return this.refreshAccountIfNeeded(account)
.then((refreshedAccount: AccountInfo) => {

View File

@ -486,12 +486,24 @@ export class MastodonService {
return this.httpClient.post<Relationship>(route, null, { headers: headers }).toPromise();
}
unmute(account: AccountInfo, accounId: number): Promise<Relationship> {
let route = `https://${account.instance}${this.apiRoutes.unmute}`.replace('{0}', accounId.toString());
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
return this.httpClient.post<Relationship>(route, null, { headers: headers }).toPromise();
}
block(account: AccountInfo, accounId: number): Promise<Relationship> {
let route = `https://${account.instance}${this.apiRoutes.block}`.replace('{0}', accounId.toString());
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
return this.httpClient.post<Relationship>(route, null, { headers: headers }).toPromise();
}
unblock(account: AccountInfo, accounId: number): Promise<Relationship> {
let route = `https://${account.instance}${this.apiRoutes.unblock}`.replace('{0}', accounId.toString());
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
return this.httpClient.post<Relationship>(route, null, { headers: headers }).toPromise();
}
pinOnProfile(account: AccountInfo, statusId: string): Promise<Status> {
let route = `https://${account.instance}${this.apiRoutes.pinStatus}`.replace('{0}', statusId.toString());
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });