1
0
mirror of https://github.com/NicolasConstant/sengi synced 2025-01-31 10:44:55 +01:00

replying to status functionnal

This commit is contained in:
Nicolas Constant 2018-10-13 11:38:23 -04:00
parent 34e593576d
commit 0d80f56c7c
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
5 changed files with 55 additions and 7 deletions

View File

@ -1,10 +1,10 @@
import { Component, OnInit, OnDestroy, Input, Output, EventEmitter } from '@angular/core';
import { Store } from '@ngxs/store';
import { Observable, Subscription } from 'rxjs';
import { StatusWrapper } from '../../stream.component';
import { MastodonService } from '../../../../services/mastodon.service';
import { AccountInfo } from '../../../../states/accounts.state';
import { Observable, Subscription } from 'rxjs';
import { Status, Results } from '../../../../services/models/mastodon.interfaces';
// import { map } from "rxjs/operators";

View File

@ -1,7 +1,9 @@
import { Component, OnInit, Input } from '@angular/core';
import { Component, OnInit, Input, Output, EventEmitter } from '@angular/core';
import { Store } from '@ngxs/store';
import { MastodonService } from '../../../../services/mastodon.service';
import { MastodonService, VisibilityEnum } from '../../../../services/mastodon.service';
import { AccountInfo } from '../../../../states/accounts.state';
import { StatusWrapper } from '../../stream.component';
import { Status } from '../../../../services/models/mastodon.interfaces';
@Component({
selector: 'app-reply-to-status',
@ -9,7 +11,11 @@ import { AccountInfo } from '../../../../states/accounts.state';
styleUrls: ['./reply-to-status.component.scss']
})
export class ReplyToStatusComponent implements OnInit {
@Input() status: string;
@Input() status: string = '';
@Input() statusReplyingToWrapper: StatusWrapper;
@Output() onClose = new EventEmitter();
private statusReplyingTo: Status;
selectedPrivacy = 'Public';
privacyList: string[] = ['Public', 'Unlisted', 'Follows-only', 'DM'];
@ -19,9 +25,44 @@ export class ReplyToStatusComponent implements OnInit {
private readonly mastodonService: MastodonService) { }
ngOnInit() {
this.statusReplyingTo = this.statusReplyingToWrapper.status;
this.status += `@${this.statusReplyingTo.account.acct} `;
for (const mention of this.statusReplyingTo.mentions) {
this.status += `@${mention.acct} `;
}
}
onSubmit(): boolean {
const accounts = this.getRegisteredAccounts();
const selectedAccounts = accounts.filter(x => x.isSelected);
let visibility: VisibilityEnum = VisibilityEnum.Unknown;
switch (this.selectedPrivacy) {
case 'Public':
visibility = VisibilityEnum.Public;
break;
case 'Unlisted':
visibility = VisibilityEnum.Unlisted;
break;
case 'Follows-only':
visibility = VisibilityEnum.Private;
break;
case 'DM':
visibility = VisibilityEnum.Direct;
break;
}
let spoiler = this.statusReplyingTo.spoiler_text;
for (const acc of selectedAccounts) {
this.mastodonService.postNewStatus(acc, this.status, visibility, spoiler)
.then((res: Status) => {
console.log(res);
this.status = '';
this.onClose.emit();
});
}
return false;
}

View File

@ -20,5 +20,5 @@
<app-action-bar [statusWrapper]="statusWrapper" (replyEvent)="openReply()"></app-action-bar>
<app-reply-to-status *ngIf="replyingToStatus" ></app-reply-to-status>
<app-reply-to-status *ngIf="replyingToStatus" [statusReplyingToWrapper]="statusWrapper" (onClose)="closeReply()"></app-reply-to-status>
</div>

View File

@ -72,4 +72,9 @@ export class StatusComponent implements OnInit {
this.replyingToStatus = !this.replyingToStatus;
return false;
}
closeReply(): boolean {
this.replyingToStatus = false;
return false;
}
}

View File

@ -122,10 +122,12 @@ export interface Status {
spoiler_text: string;
visibility: string;
media_attachments: Attachment[];
mentions: string;
tags: string;
mentions: Mention[];
tags: Tag[];
application: Application;
emojis: any[];
language: string;
pinned: boolean;
}
export interface Tag {
name: string;