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

92 lines
2.7 KiB
TypeScript
Raw Normal View History

import { Component, OnInit, Input, Output, Inject, LOCALE_ID, ElementRef, EventEmitter } from "@angular/core";
2018-10-22 08:01:38 +02:00
import { Status, Account} from "../../../services/models/mastodon.interfaces";
2018-09-19 07:03:07 +02:00
import { formatDate } from '@angular/common';
2018-09-21 04:51:18 +02:00
import { stateNameErrorMessage } from "@ngxs/store/src/decorators/state";
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() browseAccount = new EventEmitter<Account>();
@Output() browseHashtag = new EventEmitter<string>();
@Output() browseThread = 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
if(this.status.reblog){
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
}
if(!this.displayedStatus.account.display_name){
this.displayedStatus.account.display_name = this.displayedStatus.account.username;
}
2018-09-21 05:27:04 +02:00
if(this.displayedStatus.media_attachments && this.displayedStatus.media_attachments.length > 0){
this.hasAttachments = true;
}
2018-09-21 04:51:18 +02:00
}
get statusWrapper(): StatusWrapper{
return this._statusWrapper;
2018-09-21 04:51:18 +02:00
}
constructor(
@Inject(LOCALE_ID) private locale: string) { }
2018-09-21 04:51:18 +02:00
ngOnInit() {
2018-09-19 07:03:07 +02:00
}
openAccount(account: Account): boolean{
this.browseAccount.next(account);
return false;
}
2018-09-19 07:03:07 +02:00
getCompactRelativeTime(d: string): string {
const date = (new Date(d)).getTime();
const now = Date.now();
2018-09-19 07:23:19 +02:00
const timeDelta = (now - date) / (1000);
2018-09-19 07:03:07 +02:00
if (timeDelta < 60) {
2018-09-19 07:23:19 +02:00
return `${timeDelta | 0}s`;
2018-09-19 07:23:50 +02:00
} else if (timeDelta < 60 * 60) {
2018-09-19 07:23:19 +02:00
return `${timeDelta / 60 | 0}m`;
} else if (timeDelta < 60 * 60 * 24) {
return `${timeDelta / (60 * 60)| 0}h`;
} else if (timeDelta < 60 * 60 * 24 * 31) {
return `${timeDelta / (60 * 60 * 24) | 0}d`;
2018-09-19 07:03:07 +02:00
}
return formatDate(date, 'MM/dd', this.locale);
}
2018-10-13 07:10:43 +02:00
openReply(): boolean{
this.replyingToStatus = !this.replyingToStatus;
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;
}
}