starting wirering status creation to mastodon service
This commit is contained in:
parent
c7a507fe94
commit
37e08669a9
|
@ -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>
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue