getting back follow relationship
This commit is contained in:
parent
29a42fcb1d
commit
f447f9c493
|
@ -9,23 +9,24 @@
|
|||
<h2 class="profile-header__display-name">{{account.display_name}}</h2>
|
||||
<h2 class="profile-header__fullhandle"><a href="{{account.url}}" target="_blank">@{{account.acct}}</a></h2>
|
||||
|
||||
<div class="profile-header__follow">
|
||||
<div class="profile-header__follow" *ngIf="relationship">
|
||||
<button class="profile-header__follow--button profile-header__follow--unfollowed" title="follow"
|
||||
(click)="folow()">
|
||||
(click)="folow()" *ngIf="!relationship.following && !relationship.requested">
|
||||
<fa-icon [icon]="faUserRegular"></fa-icon>
|
||||
</button>
|
||||
<button class="profile-header__follow--button profile-header__follow--followed" title="unfollow"
|
||||
(click)="unfolow()">
|
||||
(click)="unfolow()" *ngIf="relationship.following">
|
||||
<fa-icon [icon]="faUserCheck"></fa-icon>
|
||||
</button>
|
||||
<button class="profile-header__follow--button profile-header__follow--followed" title="pending"
|
||||
(click)="unfolow()">
|
||||
(click)="unfolow()" *ngIf="relationship.requested">
|
||||
<fa-icon [icon]="faHourglassHalf"></fa-icon>
|
||||
</button>
|
||||
</div>
|
||||
<div class="profile-header__state">
|
||||
<div class="profile-header__state--data">follows you</div>
|
||||
<div class="profile-header__state--data">blocked</div>
|
||||
<div class="profile-header__state" *ngIf="relationship">
|
||||
<div class="profile-header__state--data" *ngIf="relationship.followed_by">follows you</div>
|
||||
<div class="profile-header__state--data" *ngIf="relationship.blocking">blocked</div>
|
||||
<div class="profile-header__state--data" *ngIf="relationship.muting">muted</div>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
|
|
|
@ -2,12 +2,17 @@ import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
|
|||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
import { faUser, faHourglassHalf, faUserCheck } from "@fortawesome/free-solid-svg-icons";
|
||||
import { faUser as faUserRegular } from "@fortawesome/free-regular-svg-icons";
|
||||
import { Observable, Subscription } from 'rxjs';
|
||||
import { Store } from '@ngxs/store';
|
||||
|
||||
import { Account, Status } from "../../../services/models/mastodon.interfaces";
|
||||
import { Account, Status, Relationship } from "../../../services/models/mastodon.interfaces";
|
||||
import { MastodonService } from '../../../services/mastodon.service';
|
||||
import { ToolsService, OpenThreadEvent } from '../../../services/tools.service';
|
||||
import { StatusWrapper } from '../stream.component';
|
||||
import { NotificationService } from '../../../services/notification.service';
|
||||
import { AccountInfo } from '../../../states/accounts.state';
|
||||
|
||||
|
||||
|
||||
@Component({
|
||||
selector: 'app-user-profile',
|
||||
|
@ -27,10 +32,15 @@ export class UserProfileComponent implements OnInit {
|
|||
statusLoading: boolean;
|
||||
error: string;
|
||||
|
||||
relationship: Relationship;
|
||||
statuses: StatusWrapper[] = [];
|
||||
|
||||
private lastAccountName: string;
|
||||
|
||||
private currentlyUsedAccount: AccountInfo;
|
||||
private accounts$: Observable<AccountInfo[]>;
|
||||
private accountSub: Subscription;
|
||||
|
||||
@Output() browseAccountEvent = new EventEmitter<string>();
|
||||
@Output() browseHashtagEvent = new EventEmitter<string>();
|
||||
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
|
||||
|
@ -43,22 +53,45 @@ export class UserProfileComponent implements OnInit {
|
|||
}
|
||||
|
||||
constructor(
|
||||
private readonly store: Store,
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly mastodonService: MastodonService,
|
||||
private readonly toolsService: ToolsService) { }
|
||||
private readonly toolsService: ToolsService) {
|
||||
|
||||
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
||||
}
|
||||
|
||||
ngOnInit() {
|
||||
// this.currentlyUsedAccount = this.toolsService.getSelectedAccounts()[0];
|
||||
this.accountSub = this.accounts$.subscribe((accounts: AccountInfo[]) => {
|
||||
const userAccount = accounts.filter(x => x.isSelected)[0];
|
||||
// this.load()
|
||||
});
|
||||
}
|
||||
|
||||
ngOnDestroy() {
|
||||
this.accountSub.unsubscribe();
|
||||
}
|
||||
|
||||
private load(accountName: string) {
|
||||
this.statuses.length = 0;
|
||||
this.isLoading = true;
|
||||
|
||||
this.loadAccount(accountName)
|
||||
this.account = null;
|
||||
this.isLoading = true;
|
||||
this.statusLoading = true;
|
||||
|
||||
this.currentlyUsedAccount = this.toolsService.getSelectedAccounts()[0];
|
||||
return this.toolsService.findAccount(this.currentlyUsedAccount, accountName)
|
||||
.then((account: Account) => {
|
||||
this.isLoading = false;
|
||||
|
||||
this.account = account;
|
||||
this.hasNote = account && account.note && account.note !== '<p></p>';
|
||||
return this.getStatuses(this.account);
|
||||
|
||||
const getFollowStatusPromise = this.getFollowStatus(this.currentlyUsedAccount, this.account);
|
||||
const getStatusesPromise = this.getStatuses(this.currentlyUsedAccount, this.account);
|
||||
|
||||
return Promise.all([getFollowStatusPromise, getStatusesPromise]);
|
||||
})
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
|
@ -68,6 +101,26 @@ export class UserProfileComponent implements OnInit {
|
|||
this.statusLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
private getStatuses(userAccount: AccountInfo, account: Account): Promise<void> {
|
||||
this.statusLoading = true;
|
||||
return this.mastodonService.getAccountStatuses(userAccount, account.id, false, false, true, null, null, 40)
|
||||
.then((result: Status[]) => {
|
||||
for (const status of result) {
|
||||
const wrapper = new StatusWrapper(status, userAccount);
|
||||
this.statuses.push(wrapper);
|
||||
}
|
||||
this.statusLoading = false;
|
||||
});
|
||||
}
|
||||
|
||||
private getFollowStatus(userAccount: AccountInfo, account: Account):Promise<void> {
|
||||
this.relationship = null;
|
||||
return this.mastodonService.getRelationships(userAccount, [account])
|
||||
.then((result: Relationship[])=> {
|
||||
this.relationship = result.filter(x => x.id === account.id)[0];
|
||||
});
|
||||
}
|
||||
|
||||
refresh(): any {
|
||||
this.load(this.lastAccountName);
|
||||
|
@ -83,39 +136,5 @@ export class UserProfileComponent implements OnInit {
|
|||
|
||||
browseThread(openThreadEvent: OpenThreadEvent): void {
|
||||
this.browseThreadEvent.next(openThreadEvent);
|
||||
}
|
||||
|
||||
private loadAccount(accountName: string): Promise<Account> {
|
||||
this.account = null;
|
||||
|
||||
let selectedAccounts = this.toolsService.getSelectedAccounts();
|
||||
|
||||
if (selectedAccounts.length === 0) {
|
||||
this.error = 'no user selected';
|
||||
console.error(this.error);
|
||||
return Promise.resolve(null);
|
||||
}
|
||||
|
||||
this.isLoading = true;
|
||||
return this.toolsService.findAccount(selectedAccounts[0], accountName)
|
||||
.then((result) => {
|
||||
this.isLoading = false;
|
||||
return result;
|
||||
});
|
||||
}
|
||||
|
||||
private getStatuses(account: Account): Promise<void> {
|
||||
let selectedAccounts = this.toolsService.getSelectedAccounts();
|
||||
if (selectedAccounts.length === 0) return;
|
||||
|
||||
this.statusLoading = true;
|
||||
return this.mastodonService.getAccountStatuses(selectedAccounts[0], account.id, false, false, true, null, null, 40)
|
||||
.then((result: Status[]) => {
|
||||
for (const status of result) {
|
||||
const wrapper = new StatusWrapper(status, selectedAccounts[0]);
|
||||
this.statuses.push(wrapper);
|
||||
}
|
||||
this.statusLoading = false;
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,14 +2,14 @@ import { Injectable } from '@angular/core';
|
|||
import { HttpHeaders, HttpClient } from '@angular/common/http';
|
||||
|
||||
import { ApiRoutes } from './models/api.settings';
|
||||
import { Account, Status, Results, Context } from "./models/mastodon.interfaces";
|
||||
import { Account, Status, Results, Context, Relationship } from "./models/mastodon.interfaces";
|
||||
import { AccountInfo } from '../states/accounts.state';
|
||||
import { StreamTypeEnum } from '../states/streams.state';
|
||||
import { stat } from 'fs';
|
||||
import { forEach } from '@angular/router/src/utils/collection';
|
||||
|
||||
@Injectable()
|
||||
export class MastodonService {
|
||||
|
||||
export class MastodonService {
|
||||
private apiRoutes = new ApiRoutes();
|
||||
|
||||
constructor(private readonly httpClient: HttpClient) { }
|
||||
|
@ -166,6 +166,18 @@ export class MastodonService {
|
|||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.post<Status>(route, null, { headers: headers }).toPromise()
|
||||
}
|
||||
|
||||
getRelationships(account: AccountInfo, accountsToRetrieve: Account[]): Promise<Relationship[]> {
|
||||
let params = "?";
|
||||
accountsToRetrieve.forEach(x => {
|
||||
if(params.includes('id')) params += '&';
|
||||
params += `id[]=${x.id}`;
|
||||
});
|
||||
|
||||
const route = `https://${account.instance}${this.apiRoutes.getAccountRelationships}${params}`;
|
||||
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
|
||||
return this.httpClient.get<Relationship[]>(route, { headers: headers }).toPromise();
|
||||
}
|
||||
}
|
||||
|
||||
export enum VisibilityEnum {
|
||||
|
|
|
@ -85,12 +85,12 @@ export interface Notification {
|
|||
}
|
||||
|
||||
export interface Relationship {
|
||||
id: string;
|
||||
following: string;
|
||||
followed_by: string;
|
||||
blocking: string;
|
||||
muting: string;
|
||||
requested: string;
|
||||
id: number;
|
||||
following: boolean;
|
||||
followed_by: boolean;
|
||||
blocking: boolean;
|
||||
muting: boolean;
|
||||
requested: boolean;
|
||||
}
|
||||
|
||||
export interface Report {
|
||||
|
|
Loading…
Reference in New Issue