starting wirering status creation to mastodon service

This commit is contained in:
Nicolas Constant 2018-09-25 21:10:16 -04:00
parent c7a507fe94
commit 37e08669a9
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
3 changed files with 51 additions and 7 deletions

View File

@ -3,9 +3,9 @@
<form (ngSubmit)="onSubmit()"> <form (ngSubmit)="onSubmit()">
<!-- <label>Please provide your account:</label> --> <!-- <label>Please provide your account:</label> -->
<input type="text" class="form-control form-control-sm" [(ngModel)]="titleHandle" name="titleHandle" autocomplete="off" placeholder="Title (optional)" /> <input [(ngModel)]="titleHandle" type="text" class="form-control form-control-sm" name="titleHandle" autocomplete="off" placeholder="Title (optional)" />
<!-- <textarea rows="4" cols="50"> --> <!-- <textarea rows="4" cols="50"> -->
<textarea class="form-control form-control-sm" style="min-width: 100%" rows="5" [(ngModel)]="statusHandle" placeholder="What's in your mind?"></textarea> <textarea [(ngModel)]="statusHandle" name="statusHandle" class="form-control form-control-sm" style="min-width: 100%" rows="5" required placeholder="What's in your mind?"></textarea>
<select class="form-control form-control-sm form-control--privacy" id="privacyHandle"> <select class="form-control form-control-sm form-control--privacy" id="privacyHandle">
<option>Public</option> <option>Public</option>
<option>Unlisted</option> <option>Unlisted</option>

View File

@ -1,4 +1,9 @@
import { Component, OnInit, Input } from '@angular/core'; import { Component, OnInit, Input } from '@angular/core';
import { Store } from '@ngxs/store';
import { AccountInfo } from '../../../states/accounts.state';
import { MastodonService } from '../../../services/mastodon.service';
import { Status } from '../../../services/models/mastodon.interfaces';
import { FormsModule } from '@angular/forms';
@Component({ @Component({
selector: 'app-add-new-status', selector: 'app-add-new-status',
@ -6,15 +11,34 @@ import { Component, OnInit, Input } from '@angular/core';
styleUrls: ['./add-new-status.component.scss'] styleUrls: ['./add-new-status.component.scss']
}) })
export class AddNewStatusComponent implements OnInit { export class AddNewStatusComponent implements OnInit {
@Input() titleHandle: string; @Input() titleHandle: string;
@Input() statusHandle: string; @Input() statusHandle: string;
constructor() { } constructor(private readonly store: Store,
private readonly mastodonService: MastodonService) { }
ngOnInit() { ngOnInit() {
} }
onSubmit(): boolean{ onSubmit(): boolean {
const accounts = this.getRegisteredAccounts();
const selectedAccounts = accounts.filter(x => x.isSelected);
console.warn(`selectedAccounts ${selectedAccounts.length}`);
console.warn(`statusHandle ${this.statusHandle}`);
for (const acc of selectedAccounts) {
this.mastodonService.postNewStatus(acc, this.statusHandle)
.then((res: Status) => {
console.log(res);
});
}
return false; return false;
} }
private getRegisteredAccounts(): AccountInfo[] {
var regAccounts = <AccountInfo[]>this.store.snapshot().registeredaccounts.accounts;
return regAccounts;
}
} }

View File

@ -67,4 +67,24 @@ export class MastodonService {
var regEx = new RegExp("^[" + charToTrim + "]+|[" + charToTrim + "]+$", "g"); var regEx = new RegExp("^[" + charToTrim + "]+|[" + charToTrim + "]+$", "g");
return origString.replace(regEx, ""); return origString.replace(regEx, "");
}; };
postNewStatus(account: AccountInfo, status:string): Promise<Status>{
const url = `https://${account.instance}${this.apiRoutes.postNewStatus}`;
const formData = new FormData();
formData.append('status', status);
// formData.append('in_reply_to_id', in_reply_to_id);
// formData.append('media_ids', media_ids);
// formData.append('sensitive', sensitive);
// formData.append('sensitive', sensitive);
// formData.append('spoiler_text', spoiler_text);
formData.append('visibility', 'direct');
// formData.append('language', '');
const headers = new HttpHeaders({ 'Authorization': `Bearer ${account.token.access_token}` });
return this.httpClient.post<Status>(url, formData, { headers: headers }).toPromise();
}
} }