2019-02-24 22:54:01 +01:00
|
|
|
import { Component, OnInit, Input, Output, EventEmitter, ViewChild } from "@angular/core";
|
2019-06-14 02:57:05 +02:00
|
|
|
import { faStar, faRetweet, faList } from "@fortawesome/free-solid-svg-icons";
|
2019-04-02 05:32:07 +02:00
|
|
|
|
2018-10-27 02:20:01 +02:00
|
|
|
import { Status, Account } from "../../../services/models/mastodon.interfaces";
|
2019-04-14 05:04:19 +02:00
|
|
|
import { OpenThreadEvent, ToolsService } from "../../../services/tools.service";
|
2019-02-24 22:54:01 +01:00
|
|
|
import { ActionBarComponent } from "./action-bar/action-bar.component";
|
2019-03-06 04:46:50 +01:00
|
|
|
import { StatusWrapper } from '../../../models/common.model';
|
2019-04-14 05:04:19 +02:00
|
|
|
import { EmojiConverter, EmojiTypeEnum } from '../../../tools/emoji.tools';
|
2019-06-16 02:41:21 +02:00
|
|
|
import { TrustedString } from '@angular/core/src/sanitization/bypass';
|
2018-09-16 04:08:59 +02:00
|
|
|
|
|
|
|
@Component({
|
2018-09-19 07:03:07 +02:00
|
|
|
selector: "app-status",
|
|
|
|
templateUrl: "./status.component.html",
|
|
|
|
styleUrls: ["./status.component.scss"]
|
2018-09-16 04:08:59 +02:00
|
|
|
})
|
|
|
|
export class StatusComponent implements OnInit {
|
2019-04-14 05:04:19 +02:00
|
|
|
private emojiConverter = new EmojiConverter();
|
|
|
|
|
2019-04-02 05:32:07 +02:00
|
|
|
faStar = faStar;
|
|
|
|
faRetweet = faRetweet;
|
2019-06-14 02:57:05 +02:00
|
|
|
faList = faList;
|
2019-04-02 05:32:07 +02:00
|
|
|
|
2018-09-21 04:51:18 +02:00
|
|
|
displayedStatus: Status;
|
2019-06-23 21:12:43 +02:00
|
|
|
displayedStatusWrapper: StatusWrapper;
|
2019-04-14 05:04:19 +02:00
|
|
|
|
2019-04-25 22:52:14 +02:00
|
|
|
// statusAccountName: string;
|
2019-04-14 05:04:19 +02:00
|
|
|
statusContent: string;
|
|
|
|
|
2018-09-21 04:51:18 +02:00
|
|
|
reblog: boolean;
|
2018-09-21 05:27:04 +02:00
|
|
|
hasAttachments: boolean;
|
2018-10-13 07:10:43 +02:00
|
|
|
replyingToStatus: boolean;
|
2019-02-24 08:01:44 +01:00
|
|
|
isCrossPoster: boolean;
|
2019-02-24 20:49:02 +01:00
|
|
|
isThread: boolean;
|
2019-06-18 03:49:18 +02:00
|
|
|
isOld: boolean;
|
2019-02-24 20:34:15 +01:00
|
|
|
isContentWarned: boolean;
|
2019-03-01 06:59:12 +01:00
|
|
|
hasReply: boolean;
|
2019-02-24 20:34:15 +01:00
|
|
|
contentWarningText: string;
|
2018-09-21 04:51:18 +02:00
|
|
|
|
2018-12-12 07:08:29 +01:00
|
|
|
@Output() browseAccountEvent = new EventEmitter<string>();
|
|
|
|
@Output() browseHashtagEvent = new EventEmitter<string>();
|
2019-02-19 04:44:21 +01:00
|
|
|
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
|
2019-02-24 22:54:01 +01:00
|
|
|
@ViewChild('appActionBar') appActionBar: ActionBarComponent;
|
2018-10-22 07:41:54 +02:00
|
|
|
|
2019-03-09 07:17:52 +01:00
|
|
|
@Input() isThreadDisplay: boolean;
|
|
|
|
|
2019-06-14 03:08:29 +02:00
|
|
|
@Input() notificationType: 'mention' | 'reblog' | 'favourite' | 'poll';
|
2019-04-02 05:32:07 +02:00
|
|
|
@Input() notificationAccount: Account;
|
|
|
|
|
2018-10-02 05:46:12 +02:00
|
|
|
private _statusWrapper: StatusWrapper;
|
|
|
|
status: Status;
|
|
|
|
@Input('statusWrapper')
|
|
|
|
set statusWrapper(value: StatusWrapper) {
|
|
|
|
this._statusWrapper = value;
|
2019-05-02 12:26:12 +02:00
|
|
|
// console.warn(value.status);
|
2019-03-02 06:55:49 +01:00
|
|
|
this.status = value.status;
|
2019-02-24 08:01:44 +01:00
|
|
|
|
2018-10-27 02:20:01 +02:00
|
|
|
if (this.status.reblog) {
|
2018-09-21 04:51:18 +02:00
|
|
|
this.reblog = true;
|
2018-10-02 05:46:12 +02:00
|
|
|
this.displayedStatus = this.status.reblog;
|
2018-09-21 04:51:18 +02:00
|
|
|
} else {
|
2018-10-02 05:46:12 +02:00
|
|
|
this.displayedStatus = this.status;
|
2018-09-21 04:51:18 +02:00
|
|
|
}
|
2019-03-02 06:55:49 +01:00
|
|
|
|
2019-06-23 21:12:43 +02:00
|
|
|
this.displayedStatusWrapper = new StatusWrapper(this.displayedStatus, value.provider);
|
|
|
|
|
2019-03-01 06:59:12 +01:00
|
|
|
this.checkLabels(this.displayedStatus);
|
|
|
|
this.checkContentWarning(this.displayedStatus);
|
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;
|
|
|
|
}
|
2019-04-14 05:04:19 +02:00
|
|
|
|
|
|
|
// const instanceUrl = 'https://' + this.status.uri.split('https://')[1].split('/')[0];
|
2019-04-25 22:52:14 +02:00
|
|
|
// this.statusAccountName = this.emojiConverter.applyEmojis(this.displayedStatus.account.emojis, this.displayedStatus.account.display_name, EmojiTypeEnum.small);
|
|
|
|
this.statusContent = this.emojiConverter.applyEmojis(this.displayedStatus.emojis, this.displayedStatus.content, EmojiTypeEnum.medium);
|
2018-10-27 02:20:01 +02:00
|
|
|
}
|
|
|
|
get statusWrapper(): StatusWrapper {
|
2018-10-02 05:46:12 +02:00
|
|
|
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-09-16 04:08:59 +02:00
|
|
|
|
2018-10-27 02:20:01 +02:00
|
|
|
ngOnInit() {
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:34:15 +01:00
|
|
|
private checkContentWarning(status: Status) {
|
2019-02-24 20:49:02 +01:00
|
|
|
if (status.sensitive || status.spoiler_text) {
|
2019-02-24 20:34:15 +01:00
|
|
|
this.isContentWarned = true;
|
|
|
|
this.contentWarningText = status.spoiler_text;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
removeContentWarning(): boolean {
|
|
|
|
this.isContentWarned = false;
|
2019-02-24 22:54:01 +01:00
|
|
|
this.appActionBar.showContent();
|
2019-02-24 20:34:15 +01:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-03-01 06:59:12 +01:00
|
|
|
changeCw(cwIsActive: boolean) {
|
2019-02-24 22:54:01 +01:00
|
|
|
this.isContentWarned = cwIsActive;
|
|
|
|
}
|
|
|
|
|
2019-02-24 20:49:02 +01:00
|
|
|
private checkLabels(status: Status) {
|
2019-02-24 08:01:44 +01:00
|
|
|
//since API is limited with federated status...
|
2019-03-02 06:55:49 +01:00
|
|
|
if (!status.account.bot) {
|
|
|
|
if (status.uri.includes('birdsite.link')) {
|
2019-02-24 08:01:44 +01:00
|
|
|
this.isCrossPoster = true;
|
|
|
|
}
|
2019-03-02 06:55:49 +01:00
|
|
|
else if (status.application) {
|
|
|
|
const usedApp = status.application.name.toLowerCase();
|
|
|
|
if (usedApp && (usedApp.includes('moa') || usedApp.includes('birdsite') || usedApp.includes('twitter'))) {
|
|
|
|
this.isCrossPoster = true;
|
|
|
|
}
|
|
|
|
}
|
2019-02-24 08:01:44 +01:00
|
|
|
}
|
2019-02-24 20:49:02 +01:00
|
|
|
|
2019-04-02 05:32:07 +02:00
|
|
|
if (this.isThreadDisplay) return;
|
2019-03-09 07:17:52 +01:00
|
|
|
|
2019-03-01 06:59:12 +01:00
|
|
|
if (status.in_reply_to_account_id && status.in_reply_to_account_id === status.account.id) {
|
2019-02-24 20:49:02 +01:00
|
|
|
this.isThread = true;
|
|
|
|
}
|
2019-03-01 06:59:12 +01:00
|
|
|
|
|
|
|
this.hasReply = status.replies_count > 0;
|
2019-06-18 03:49:18 +02:00
|
|
|
|
|
|
|
let createdAt = new Date(status.created_at);
|
|
|
|
let now = new Date();
|
|
|
|
now.setMonth(now.getMonth() - 3);
|
|
|
|
if (now > createdAt) {
|
|
|
|
this.isOld = true;
|
|
|
|
}
|
2019-02-24 08:01:44 +01:00
|
|
|
}
|
|
|
|
|
2018-10-27 02:20:01 +02:00
|
|
|
openAccount(account: Account): boolean {
|
2019-01-28 05:08:43 +01:00
|
|
|
let accountName = account.acct;
|
|
|
|
if (!accountName.includes('@'))
|
|
|
|
accountName += `@${account.url.replace('https://', '').split('/')[0]}`;
|
2018-10-31 05:02:03 +01:00
|
|
|
|
2018-12-12 07:08:29 +01:00
|
|
|
this.browseAccountEvent.next(accountName);
|
2018-10-22 07:41:54 +02:00
|
|
|
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
|
|
|
|
2018-10-31 04:27:20 +01:00
|
|
|
accountSelected(accountName: string): void {
|
2018-12-12 07:08:29 +01:00
|
|
|
this.browseAccountEvent.next(accountName);
|
2018-10-31 04:27:20 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
hashtagSelected(hashtag: string): void {
|
2018-12-12 07:08:29 +01:00
|
|
|
this.browseHashtagEvent.next(hashtag);
|
2018-10-31 04:27:20 +01:00
|
|
|
}
|
|
|
|
|
2019-05-16 06:41:17 +02:00
|
|
|
textSelected(): boolean {
|
2019-01-28 05:08:43 +01:00
|
|
|
const status = this._statusWrapper.status;
|
2019-02-19 04:44:21 +01:00
|
|
|
const accountInfo = this._statusWrapper.provider;
|
2019-01-28 05:08:43 +01:00
|
|
|
|
2019-02-19 04:44:21 +01:00
|
|
|
let openThread: OpenThreadEvent;
|
2019-02-24 08:01:44 +01:00
|
|
|
if (status.reblog) {
|
|
|
|
openThread = new OpenThreadEvent(status.reblog, accountInfo);
|
2019-01-28 05:08:43 +01:00
|
|
|
} else {
|
2019-02-19 04:44:21 +01:00
|
|
|
openThread = new OpenThreadEvent(status, accountInfo);
|
2019-01-28 05:08:43 +01:00
|
|
|
}
|
2019-02-19 04:44:21 +01:00
|
|
|
|
|
|
|
this.browseThreadEvent.next(openThread);
|
2019-05-16 06:41:17 +02:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2019-06-16 02:41:21 +02:00
|
|
|
openUrl(url: string): boolean {
|
2019-05-16 06:41:17 +02:00
|
|
|
event.preventDefault();
|
2019-06-16 02:41:21 +02:00
|
|
|
window.open(url, "_blank");
|
2019-05-16 06:41:17 +02:00
|
|
|
return false;
|
2018-10-27 02:20:01 +02:00
|
|
|
}
|
2018-09-16 04:08:59 +02:00
|
|
|
}
|