From 0d80f56c7cb9f6a02fa10de2c58f767fb69610cd Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sat, 13 Oct 2018 11:38:23 -0400 Subject: [PATCH] replying to status functionnal --- .../status/action-bar/action-bar.component.ts | 2 +- .../reply-to-status.component.ts | 47 +++++++++++++++++-- .../stream/status/status.component.html | 2 +- .../stream/status/status.component.ts | 5 ++ .../services/models/mastodon.interfaces.ts | 6 ++- 5 files changed, 55 insertions(+), 7 deletions(-) diff --git a/src/app/components/stream/status/action-bar/action-bar.component.ts b/src/app/components/stream/status/action-bar/action-bar.component.ts index 84828ec6..84005dad 100644 --- a/src/app/components/stream/status/action-bar/action-bar.component.ts +++ b/src/app/components/stream/status/action-bar/action-bar.component.ts @@ -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"; diff --git a/src/app/components/stream/status/reply-to-status/reply-to-status.component.ts b/src/app/components/stream/status/reply-to-status/reply-to-status.component.ts index 44c9856b..81aee556 100644 --- a/src/app/components/stream/status/reply-to-status/reply-to-status.component.ts +++ b/src/app/components/stream/status/reply-to-status/reply-to-status.component.ts @@ -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; } diff --git a/src/app/components/stream/status/status.component.html b/src/app/components/stream/status/status.component.html index 005bba5f..38d2c624 100644 --- a/src/app/components/stream/status/status.component.html +++ b/src/app/components/stream/status/status.component.html @@ -20,5 +20,5 @@ - + \ No newline at end of file diff --git a/src/app/components/stream/status/status.component.ts b/src/app/components/stream/status/status.component.ts index 0f62c46a..b9a452b2 100644 --- a/src/app/components/stream/status/status.component.ts +++ b/src/app/components/stream/status/status.component.ts @@ -72,4 +72,9 @@ export class StatusComponent implements OnInit { this.replyingToStatus = !this.replyingToStatus; return false; } + + closeReply(): boolean { + this.replyingToStatus = false; + return false; + } } diff --git a/src/app/services/models/mastodon.interfaces.ts b/src/app/services/models/mastodon.interfaces.ts index e2b50740..c07620cc 100644 --- a/src/app/services/models/mastodon.interfaces.ts +++ b/src/app/services/models/mastodon.interfaces.ts @@ -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;