now loading status in user profile

This commit is contained in:
Nicolas Constant 2018-11-01 00:44:58 -04:00
parent 8f160d71e5
commit c3fedcd1de
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
4 changed files with 51 additions and 2 deletions

View File

@ -10,4 +10,11 @@
<app-databinded-text class="status__content" [textIsSelectable]="false" [text]="account.note" (accountSelected)="accountSelected($event)"
(hashtagSelected)="hashtagSelected($event)"></app-databinded-text>
<!-- <p innerHTML="{{account.note}}"></p> -->
</div>
<div class="profile-statuses">
<app-waiting-animation *ngIf="statusLoading" class="waiting-icon"></app-waiting-animation>
<div *ngFor="let statusWrapper of statuses">
<app-status [statusWrapper]="statusWrapper" (browseAccount)="browseAccount($event)"></app-status>
</div>
</div>

View File

@ -1,4 +1,6 @@
@import "variables";
@import "commons";
.profile-header {
background-size: cover;
position: relative;

View File

@ -1,5 +1,8 @@
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Account } from "../../../services/models/mastodon.interfaces";
import { Account, Status } from "../../../services/models/mastodon.interfaces";
import { MastodonService } from '../../../services/mastodon.service';
import { ToolsService } from '../../../services/tools.service';
import { StatusWrapper } from '../stream.component';
@Component({
selector: 'app-user-profile',
@ -10,6 +13,9 @@ export class UserProfileComponent implements OnInit {
account: Account;
hasNote: boolean;
statusLoading: boolean;
statuses: StatusWrapper[] = [];
@Output() browseAccount = new EventEmitter<string>();
@Output() browseHashtag = new EventEmitter<string>();
@ -19,9 +25,12 @@ export class UserProfileComponent implements OnInit {
this.hasNote = account && account.note && account.note !== '<p></p>';
console.warn('currentAccount');
console.warn(account);
this.getStatuses(account);
}
constructor() { }
constructor(
private readonly mastodonService: MastodonService,
private readonly toolsService: ToolsService) { }
ngOnInit() {
}
@ -33,4 +42,24 @@ export class UserProfileComponent implements OnInit {
hashtagSelected(hashtag: string): void {
this.browseHashtag.next(hashtag);
}
private getStatuses(account: Account): void {
let selectedAccounts = this.toolsService.getSelectedAccounts();
if (selectedAccounts.length === 0) return;
this.statusLoading = true;
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);
}
})
.catch(err => {
})
.then(() => {
this.statusLoading = false;
});
}
}

View File

@ -117,6 +117,17 @@ export class MastodonService {
return this.httpClient.get<Results>(route, { headers: headers }).toPromise()
}
getAccountStatuses(account: AccountInfo, targetAccountId: number, onlyMedia: boolean, onlyPinned: boolean, excludeReplies: boolean, maxId: string, sinceId: string, limit: number = 20): Promise<Status[]>{
const route = `https://${account.instance}${this.apiRoutes.getAccountStatuses}`.replace('{0}', targetAccountId.toString());
let params = `?only_media=${onlyMedia}&pinned=${onlyPinned}&exclude_replies=${excludeReplies}&limit=${limit}`;
if(maxId) params += `&max_id=${maxId}`;
if(sinceId) params += `&since_id=${sinceId}`;
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
return this.httpClient.get<Status[]>(route+params, { headers: headers }).toPromise();
}
searchAccount(account: AccountInfo, query: string, limit: number = 40, following: boolean = false): Promise<Account[]>{
const route = `https://${account.instance}${this.apiRoutes.searchForAccounts}?q=${query}&limit=${limit}&following=${following}`;
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });