From 62baf8474dd65d3f3b46e467a9fb4ff276ca7a16 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 18 May 2019 20:44:36 -0400 Subject: [PATCH 01/35] display lists and add/remove them #46 --- .../direct-messages.component.ts | 1 - .../my-account/my-account.component.html | 19 ++++++++--- .../my-account/my-account.component.ts | 32 +++++++++++++++---- .../stream/hashtag/hashtag.component.ts | 2 +- .../stream-overlay.component.ts | 2 +- .../stream-statuses.component.ts | 4 +-- src/app/services/mastodon.service.ts | 26 +++++++++++---- src/app/services/models/api.settings.ts | 9 ++++++ .../services/models/mastodon.interfaces.ts | 4 +++ src/app/services/streaming.service.ts | 6 ++-- src/app/states/streams.state.ts | 1 + 11 files changed, 82 insertions(+), 24 deletions(-) diff --git a/src/app/components/floating-column/manage-account/direct-messages/direct-messages.component.ts b/src/app/components/floating-column/manage-account/direct-messages/direct-messages.component.ts index 4b287c61..f5caa7be 100644 --- a/src/app/components/floating-column/manage-account/direct-messages/direct-messages.component.ts +++ b/src/app/components/floating-column/manage-account/direct-messages/direct-messages.component.ts @@ -29,7 +29,6 @@ export class DirectMessagesComponent implements OnInit { @Input('account') set account(acc: AccountWrapper) { - console.warn('account'); this._account = acc; this.getDirectMessages(); } diff --git a/src/app/components/floating-column/manage-account/my-account/my-account.component.html b/src/app/components/floating-column/manage-account/my-account/my-account.component.html index 9404680e..813f621a 100644 --- a/src/app/components/floating-column/manage-account/my-account/my-account.component.html +++ b/src/app/components/floating-column/manage-account/my-account/my-account.component.html @@ -1,9 +1,20 @@
- - + + + + \ No newline at end of file diff --git a/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.ts b/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.ts index 3e9df7aa..ee021392 100644 --- a/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.ts +++ b/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.ts @@ -5,7 +5,8 @@ import { StreamWrapper } from '../my-account.component'; import { MastodonService } from '../../../../../services/mastodon.service'; import { AccountWrapper } from '../../../../../models/account.models'; import { NotificationService } from '../../../../../services/notification.service'; -import { Account } from "../../../../../services/models/mastodon.interfaces"; +import { Account, Relationship, Instance } from "../../../../../services/models/mastodon.interfaces"; +import { of } from 'rxjs'; @Component({ selector: 'app-list-editor', @@ -34,15 +35,15 @@ export class ListEditorComponent implements OnInit { this.accountsInList.length = 0; for (const account of accounts) { this.accountsInList.push(new AccountListWrapper(account, true)); - } + } }) .catch(err => { this.notificationService.notifyHttpError(err); }); } - search(){ - if(this.searchPattern === '') + search() { + if (this.searchPattern === '') return this.closeSearch(); this.searchOpen = true; @@ -51,7 +52,8 @@ export class ListEditorComponent implements OnInit { .then((accounts: Account[]) => { this.accountsSearch.length = 0; for (const account of accounts) { - this.accountsSearch.push(new AccountListWrapper(account, false)); + const isInList = this.accountsInList.filter(x => x.account.id === account.id).length > 0; + this.accountsSearch.push(new AccountListWrapper(account, isInList)); } }) .catch(err => { @@ -65,11 +67,69 @@ export class ListEditorComponent implements OnInit { this.accountsSearch.length = 0; return false; } + + addEvent(accountWrapper: AccountListWrapper) { + console.log(accountWrapper); + + accountWrapper.isLoading = true; + this.mastodonService.getInstance(this.account.info.instance) + .then((instance: Instance) => { + console.log(instance); + if (instance.version.toLowerCase().includes('pleroma')) { + return Promise.resolve(true); + } else { + return this.followAccount(accountWrapper); + } + }) + .then(() => { + return this.mastodonService.addAccountToList(this.account.info, this.list.listId, accountWrapper.account.id); + }) + .then(() => { + accountWrapper.isInList = true; + this.accountsInList.push(accountWrapper); + }) + .catch(err => { + this.notificationService.notifyHttpError(err); + }) + .then(() => { + accountWrapper.isLoading = false; + }); + } + + private followAccount(accountWrapper: AccountListWrapper): Promise { + return this.mastodonService.getRelationships(this.account.info, [accountWrapper.account]) + .then((relationships: Relationship[]) => { + var relationship = relationships.filter(x => x.id === accountWrapper.account.id)[0]; + return relationship; + }) + .then((relationship: Relationship) => { + if (relationship.following) { + return Promise.resolve(true); + } else { + return this.mastodonService.follow(this.account.info, accountWrapper.account) + .then((relationship: Relationship) => { + return new Promise((resolve) => setTimeout(resolve, 1500)); + // return Promise.resolve(relationship.following); + }); + } + }) + } + + // private delay(t, v) { + // return new Promise(function(resolve) { + // setTimeout(resolve.bind(null, v), t) + // }); + // } + + removeEvent(accountWrapper: AccountListWrapper) { + console.log(accountWrapper); + } } export class AccountListWrapper { constructor(public account: Account, public isInList: boolean) { } - + isProcessing: boolean; + isLoading: boolean; } diff --git a/src/app/services/mastodon.service.ts b/src/app/services/mastodon.service.ts index 6651e972..600dc7f7 100644 --- a/src/app/services/mastodon.service.ts +++ b/src/app/services/mastodon.service.ts @@ -292,6 +292,13 @@ export class MastodonService { const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); return this.httpClient.get(route, { headers: headers }).toPromise(); } + + addAccountToList(account: AccountInfo, listId: string, accountId: number): Promise { + let route = `https://${account.instance}${this.apiRoutes.addAccountToList}`.replace('{0}', listId); + route += `?account_ids[]=${accountId}`; + const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); + return this.httpClient.post(route, null, { headers: headers }).toPromise(); + } } export enum VisibilityEnum { From f592adc38c050ab6754515bd3fd68cca9c0075cc Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Mon, 20 May 2019 18:42:27 -0400 Subject: [PATCH 17/35] added remove account from list #46 --- .../list-account/list-account.component.ts | 4 ++-- .../list-editor/list-editor.component.html | 2 +- .../my-account/list-editor/list-editor.component.ts | 13 +++++++++++++ src/app/services/mastodon.service.ts | 7 +++++++ 4 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/app/components/floating-column/manage-account/my-account/list-editor/list-account/list-account.component.ts b/src/app/components/floating-column/manage-account/my-account/list-editor/list-account/list-account.component.ts index 31c7bcf2..ec17afc9 100644 --- a/src/app/components/floating-column/manage-account/my-account/list-editor/list-account/list-account.component.ts +++ b/src/app/components/floating-column/manage-account/my-account/list-editor/list-account/list-account.component.ts @@ -24,13 +24,13 @@ export class ListAccountComponent implements OnInit { } add(): boolean { - if(this.accountWrapper.isLoading) return; + if(this.accountWrapper && this.accountWrapper.isLoading) return; this.addEvent.emit(this.accountWrapper); return false; } remove(): boolean { - if(this.accountWrapper.isLoading) return; + if(this.accountWrapper && this.accountWrapper.isLoading) return; this.removeEvent.emit(this.accountWrapper); return false; } diff --git a/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.html b/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.html index e4e04935..9499cc6b 100644 --- a/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.html +++ b/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.html @@ -6,7 +6,7 @@ (keyup.enter)="search()" />
diff --git a/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.ts b/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.ts index ee021392..0c0406df 100644 --- a/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.ts +++ b/src/app/components/floating-column/manage-account/my-account/list-editor/list-editor.component.ts @@ -123,6 +123,19 @@ export class ListEditorComponent implements OnInit { removeEvent(accountWrapper: AccountListWrapper) { console.log(accountWrapper); + + accountWrapper.isLoading = true; + this.mastodonService.removeAccountFromList(this.account.info, this.list.listId, accountWrapper.account.id) + .then(() => { + accountWrapper.isInList = false; + this.accountsInList = this.accountsInList.filter(x => x.account.id !== accountWrapper.account.id); + }) + .catch(err => { + this.notificationService.notifyHttpError(err); + }) + .then(() => { + accountWrapper.isLoading = false; + }); } } diff --git a/src/app/services/mastodon.service.ts b/src/app/services/mastodon.service.ts index 600dc7f7..dce27b31 100644 --- a/src/app/services/mastodon.service.ts +++ b/src/app/services/mastodon.service.ts @@ -299,6 +299,13 @@ export class MastodonService { const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); return this.httpClient.post(route, null, { headers: headers }).toPromise(); } + + removeAccountFromList(account: AccountInfo, listId: string, accountId: number): Promise { + let route = `https://${account.instance}${this.apiRoutes.addAccountToList}`.replace('{0}', listId); + route += `?account_ids[]=${accountId}`; + const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` }); + return this.httpClient.delete(route, { headers: headers }).toPromise(); + } } export enum VisibilityEnum { From a1db774767e9159985b84931ef0caea1966d9f62 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Mon, 20 May 2019 18:59:40 -0400 Subject: [PATCH 18/35] fine tunning list edition color #46 --- .../list-account/list-account.component.html | 4 ++-- .../list-account/list-account.component.scss | 16 ++++++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/app/components/floating-column/manage-account/my-account/list-editor/list-account/list-account.component.html b/src/app/components/floating-column/manage-account/my-account/list-editor/list-account/list-account.component.html index b84bb518..200f8a7c 100644 --- a/src/app/components/floating-column/manage-account/my-account/list-editor/list-account/list-account.component.html +++ b/src/app/components/floating-column/manage-account/my-account/list-editor/list-account/list-account.component.html @@ -1,11 +1,11 @@