Sengi-Windows-MacOS-Linux/src/app/components/stream/status/status.component.ts

83 lines
2.3 KiB
TypeScript
Raw Normal View History

2018-12-12 06:10:25 +01:00
import { Component, OnInit, Input, Output, EventEmitter } from "@angular/core";
2018-10-27 02:20:01 +02:00
import { Status, Account } from "../../../services/models/mastodon.interfaces";
import { StatusWrapper } from "../stream.component";
@Component({
2018-09-19 07:03:07 +02:00
selector: "app-status",
templateUrl: "./status.component.html",
styleUrls: ["./status.component.scss"]
})
export class StatusComponent implements OnInit {
2018-09-21 04:51:18 +02:00
displayedStatus: Status;
reblog: boolean;
2018-09-21 05:27:04 +02:00
hasAttachments: boolean;
2018-10-13 07:10:43 +02:00
replyingToStatus: boolean;
2018-09-21 04:51:18 +02:00
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<string>();
private _statusWrapper: StatusWrapper;
status: Status;
@Input('statusWrapper')
set statusWrapper(value: StatusWrapper) {
this._statusWrapper = value;
this.status = value.status;
2018-09-21 04:51:18 +02:00
2018-10-27 02:20:01 +02:00
if (this.status.reblog) {
2018-09-21 04:51:18 +02:00
this.reblog = true;
this.displayedStatus = this.status.reblog;
2018-09-21 04:51:18 +02:00
} else {
this.displayedStatus = this.status;
2018-09-21 04:51:18 +02:00
}
2018-10-27 02:20:01 +02:00
if (!this.displayedStatus.account.display_name) {
2018-09-21 04:51:18 +02:00
this.displayedStatus.account.display_name = this.displayedStatus.account.username;
}
2018-10-27 02:20:01 +02:00
if (this.displayedStatus.media_attachments && this.displayedStatus.media_attachments.length > 0) {
2018-09-21 05:27:04 +02:00
this.hasAttachments = true;
}
2018-10-27 02:20:01 +02:00
}
get statusWrapper(): StatusWrapper {
return this._statusWrapper;
2018-09-21 04:51:18 +02:00
}
2018-10-27 02:20:01 +02:00
2018-12-12 06:10:25 +01:00
constructor() { }
2018-10-27 02:20:01 +02:00
ngOnInit() {
}
openAccount(account: Account): boolean {
let accountName = account.acct;
if(!accountName.includes('@'))
accountName += `@${account.url.replace('https://', '').split('/')[0]}`;
this.browseAccountEvent.next(accountName);
return false;
}
2018-10-27 02:20:01 +02:00
openReply(): boolean {
2018-10-13 07:10:43 +02:00
this.replyingToStatus = !this.replyingToStatus;
2018-10-27 02:20:01 +02:00
2018-10-13 07:10:43 +02:00
return false;
}
2018-10-13 17:38:23 +02:00
closeReply(): boolean {
this.replyingToStatus = false;
return false;
}
2018-10-27 02:20:01 +02:00
accountSelected(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
hashtagSelected(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
textSelected(): void {
this.browseThreadEvent.next(this._statusWrapper.status.uri);
2018-10-27 02:20:01 +02:00
}
}