fix #31
This commit is contained in:
parent
fbd6e6d412
commit
ef4c252f42
|
@ -6,6 +6,7 @@ import { StatusWrapper } from '../../stream.component';
|
|||
import { MastodonService } from '../../../../services/mastodon.service';
|
||||
import { AccountInfo } from '../../../../states/accounts.state';
|
||||
import { Status, Results } from '../../../../services/models/mastodon.interfaces';
|
||||
import { ToolsService } from '../../../../services/tools.service';
|
||||
// import { map } from "rxjs/operators";
|
||||
|
||||
@Component({
|
||||
|
@ -35,6 +36,7 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
|
||||
constructor(
|
||||
private readonly store: Store,
|
||||
private readonly toolsService: ToolsService,
|
||||
private readonly mastodonService: MastodonService) {
|
||||
|
||||
this.accounts$ = this.store.select(state => state.registeredaccounts.accounts);
|
||||
|
@ -86,23 +88,26 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
}
|
||||
|
||||
boost(): boolean {
|
||||
|
||||
//TODO get rid of that
|
||||
this.selectedAccounts.forEach((account: AccountInfo) => {
|
||||
const isProvider = this.statusWrapper.provider.id === account.id;
|
||||
|
||||
let pipeline: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
||||
const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper);
|
||||
|
||||
if (!isProvider) {
|
||||
pipeline = pipeline.then((foreignStatus: Status) => {
|
||||
const statusUrl = foreignStatus.url;
|
||||
return this.mastodonService.search(account, statusUrl)
|
||||
.then((results: Results) => {
|
||||
//TODO check and type errors
|
||||
return results.statuses[0];
|
||||
});
|
||||
});
|
||||
}
|
||||
// const isProvider = this.statusWrapper.provider.id === account.id;
|
||||
// let pipeline: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
||||
// if (!isProvider) {
|
||||
// pipeline = pipeline.then((foreignStatus: Status) => {
|
||||
// const statusUrl = foreignStatus.url;
|
||||
// return this.mastodonService.search(account, statusUrl)
|
||||
// .then((results: Results) => {
|
||||
// //TODO check and type errors
|
||||
// return results.statuses[0];
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
pipeline
|
||||
usableStatus
|
||||
.then((status: Status) => {
|
||||
if (this.isBoosted) {
|
||||
return this.mastodonService.unreblog(account, status);
|
||||
|
@ -125,22 +130,23 @@ export class ActionBarComponent implements OnInit, OnDestroy {
|
|||
|
||||
favorite(): boolean {
|
||||
this.selectedAccounts.forEach((account: AccountInfo) => {
|
||||
const isProvider = this.statusWrapper.provider.id === account.id;
|
||||
|
||||
const usableStatus = this.toolsService.getStatusUsableByAccount(account, this.statusWrapper);
|
||||
|
||||
let pipeline: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
||||
// const isProvider = this.statusWrapper.provider.id === account.id;
|
||||
// let pipeline: Promise<Status> = Promise.resolve(this.statusWrapper.status);
|
||||
// if (!isProvider) {
|
||||
// pipeline = pipeline.then((foreignStatus: Status) => {
|
||||
// const statusUrl = foreignStatus.url;
|
||||
// return this.mastodonService.search(account, statusUrl)
|
||||
// .then((results: Results) => {
|
||||
// //TODO check and type errors
|
||||
// return results.statuses[0];
|
||||
// });
|
||||
// });
|
||||
// }
|
||||
|
||||
if (!isProvider) {
|
||||
pipeline = pipeline.then((foreignStatus: Status) => {
|
||||
const statusUrl = foreignStatus.url;
|
||||
return this.mastodonService.search(account, statusUrl)
|
||||
.then((results: Results) => {
|
||||
//TODO check and type errors
|
||||
return results.statuses[0];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
pipeline
|
||||
usableStatus
|
||||
.then((status: Status) => {
|
||||
if (this.isFavorited) {
|
||||
return this.mastodonService.unfavorite(account, status);
|
||||
|
|
|
@ -5,6 +5,8 @@ import { MastodonService, VisibilityEnum } from '../../../../services/mastodon.s
|
|||
import { StatusWrapper } from '../../stream.component';
|
||||
import { Status } from '../../../../services/models/mastodon.interfaces';
|
||||
import { ToolsService } from '../../../../services/tools.service';
|
||||
import { NotificationService } from '../../../../services/notification.service';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
@Component({
|
||||
selector: 'app-reply-to-status',
|
||||
|
@ -24,11 +26,12 @@ export class ReplyToStatusComponent implements OnInit {
|
|||
|
||||
constructor(
|
||||
// private readonly store: Store,
|
||||
private readonly notificationService: NotificationService,
|
||||
private readonly toolsService: ToolsService,
|
||||
private readonly mastodonService: MastodonService) { }
|
||||
|
||||
ngOnInit() {
|
||||
if( this.statusReplyingToWrapper.status.reblog){
|
||||
if (this.statusReplyingToWrapper.status.reblog) {
|
||||
this.statusReplyingTo = this.statusReplyingToWrapper.status.reblog;
|
||||
} else {
|
||||
this.statusReplyingTo = this.statusReplyingToWrapper.status;
|
||||
|
@ -39,14 +42,12 @@ export class ReplyToStatusComponent implements OnInit {
|
|||
this.status += `@${mention.acct} `;
|
||||
}
|
||||
|
||||
setTimeout(() => {
|
||||
setTimeout(() => {
|
||||
this.replyElement.nativeElement.focus();
|
||||
}, 0);
|
||||
}
|
||||
|
||||
onSubmit(): boolean {
|
||||
const selectedAccounts = this.toolsService.getSelectedAccounts();
|
||||
|
||||
let visibility: VisibilityEnum = VisibilityEnum.Unknown;
|
||||
switch (this.selectedPrivacy) {
|
||||
case 'Public':
|
||||
|
@ -65,12 +66,21 @@ export class ReplyToStatusComponent implements OnInit {
|
|||
|
||||
let spoiler = this.statusReplyingTo.spoiler_text;
|
||||
|
||||
const selectedAccounts = this.toolsService.getSelectedAccounts();
|
||||
for (const acc of selectedAccounts) {
|
||||
this.mastodonService.postNewStatus(acc, this.status, visibility, spoiler, this.statusReplyingTo.id)
|
||||
|
||||
const usableStatus = this.toolsService.getStatusUsableByAccount(acc, this.statusReplyingToWrapper);
|
||||
usableStatus
|
||||
.then((status: Status) => {
|
||||
return this.mastodonService.postNewStatus(acc, this.status, visibility, spoiler, status.id);
|
||||
})
|
||||
.then((res: Status) => {
|
||||
console.log(res);
|
||||
this.status = '';
|
||||
this.onClose.emit();
|
||||
})
|
||||
.catch((err: HttpErrorResponse) => {
|
||||
this.notificationService.notifyHttpError(err);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import { Injectable } from '@angular/core';
|
||||
import { Subject } from 'rxjs';
|
||||
import { HttpErrorResponse } from '@angular/common/http';
|
||||
|
||||
@Injectable()
|
||||
export class NotificationService {
|
||||
|
@ -12,6 +13,11 @@ export class NotificationService {
|
|||
let newNotification = new NotificatioData(message, isError);
|
||||
this.notifactionStream.next(newNotification);
|
||||
}
|
||||
|
||||
public notifyHttpError(err: HttpErrorResponse){
|
||||
let message = `${err.status}: ${err.message}`;
|
||||
this.notify(message, true);
|
||||
}
|
||||
}
|
||||
|
||||
export class NotificatioData {
|
||||
|
|
|
@ -3,7 +3,8 @@ import { Store } from '@ngxs/store';
|
|||
|
||||
import { AccountInfo } from '../states/accounts.state';
|
||||
import { MastodonService } from './mastodon.service';
|
||||
import { Account, Results } from "./models/mastodon.interfaces";
|
||||
import { Account, Results, Status } from "./models/mastodon.interfaces";
|
||||
import { StatusWrapper } from '../components/stream/stream.component';
|
||||
|
||||
|
||||
@Injectable({
|
||||
|
@ -34,4 +35,22 @@ export class ToolsService {
|
|||
});
|
||||
}
|
||||
|
||||
getStatusUsableByAccount(account: AccountInfo, originalStatus: StatusWrapper): Promise<Status>{
|
||||
const isProvider = originalStatus.provider.id === account.id;
|
||||
|
||||
let statusPromise: Promise<Status> = Promise.resolve(originalStatus.status);
|
||||
|
||||
if (!isProvider) {
|
||||
statusPromise = statusPromise.then((foreignStatus: Status) => {
|
||||
const statusUrl = foreignStatus.url;
|
||||
return this.mastodonService.search(account, statusUrl)
|
||||
.then((results: Results) => {
|
||||
return results.statuses[0];
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
return statusPromise;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue