-
-
Notifications
You must be signed in to change notification settings - Fork 33
Expand file tree
/
Copy pathquote.component.ts
More file actions
158 lines (129 loc) · 5.13 KB
/
quote.component.ts
File metadata and controls
158 lines (129 loc) · 5.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
import { Component, OnInit, Input, Output, EventEmitter, ApplicationRef } from '@angular/core';
import { faCircle } from '@fortawesome/free-solid-svg-icons';
import { Status, Account, Quote, ShallowQuote } from '../../../../services/models/mastodon.interfaces';
import { EmojiConverter, EmojiTypeEnum } from '../../../../tools/emoji.tools';
import { OpenThreadEvent, ToolsService } from '../../../../services/tools.service';
import { SettingsService } from '../../../../services/settings.service';
import { AccountInfo } from '../../../../states/accounts.state';
import { MastodonWrapperService } from '../../../../services/mastodon-wrapper.service';
import { StatusWrapper } from '../../../../models/common.model';
@Component({
selector: 'app-quote',
templateUrl: './quote.component.html',
styleUrls: ['./quote.component.scss']
})
export class QuoteComponent implements OnInit {
private emojiConverter = new EmojiConverter();
faCircle = faCircle;
displayStatus: Status;
displayStatusWrapper: StatusWrapper;
quoteState: 'pending' | 'accepted' | 'rejected' | 'revoked' | 'deleted' | 'unauthorized' | 'blocked_account' | 'blocked_domain' | 'muted_account';
error: string;
private quote: Quote;
private shallowQuote: ShallowQuote;
@Output() browseAccountEvent = new EventEmitter<string>();
@Output() browseHashtagEvent = new EventEmitter<string>();
@Output() browseThreadEvent = new EventEmitter<OpenThreadEvent>();
@Input() accountInfo: AccountInfo;
@Input('quote')
set setQuote(value: Quote | ShallowQuote) {
this.quoteState = value.state;
//this.quoteState = "revoked";
let quoteValue = <Quote>value;
if (quoteValue.quoted_status) { // Quote
this.quote = quoteValue;
this.displayStatus = quoteValue.quoted_status;
if (!this.displayStatus.account.display_name) {
this.displayStatus.account.display_name = this.displayStatus.account.username;
}
const statusContent = this.emojiConverter.applyEmojis(this.displayStatus.emojis, this.displayStatus.content, EmojiTypeEnum.medium);
this.statusContent = this.ensureMentionAreDisplayed(statusContent);
} else { // ShallowQuote
this.shallowQuote = <ShallowQuote>value;
this.mastodonService.getStatus(this.accountInfo, this.shallowQuote.quoted_status_id)
.then(status => {
this.displayStatus = status;
this.appRef.tick();
})
.catch(err => {
console.error(err);
this.error = "Error retrieving status.";
this.appRef.tick();
});
}
this.displayStatusWrapper = new StatusWrapper(this.displayStatus, this.accountInfo, false, false);
}
statusContent: string;
private freezeAvatarEnabled: boolean;
constructor(
private appRef: ApplicationRef,
private readonly settingsService: SettingsService,
private readonly toolsService: ToolsService,
private readonly mastodonService: MastodonWrapperService) {
this.freezeAvatarEnabled = this.settingsService.getSettings().enableFreezeAvatar;
}
ngOnInit() {
}
// TODO: refactorise this
private ensureMentionAreDisplayed(data: string): string {
const mentions = this.displayStatus.mentions;
if (!mentions || mentions.length === 0) {
return data;
}
let textMentions = '';
for (const m of mentions) {
if (!data.includes(m.url)) {
textMentions += `<span class="h-card">
<a class="u-url mention" data-user="${m.id}" href="${m.url}" rel="ugc">@
<span>${m.username}</span>
</a>
</span> `;
}
}
if (textMentions !== '') {
data = textMentions + data;
}
return data;
}
getReadableStatus(state: 'pending' | 'accepted' | 'rejected' | 'revoked' | 'deleted' | 'unauthorized' | 'blocked_account' | 'blocked_domain' | 'muted_account'): string {
switch (state) {
case "pending": return "Waiting for author authorization."
case "rejected": return "Author rejected quote, can't be displayed."
case "revoked": return "Author revoked quote, can't be displayed.";
case "deleted": return "Post deleted.";
case "unauthorized": return "Not authorized.";
case "blocked_account": return "Blocked account.";
case "blocked_domain": return "Blocked domain.";
case "muted_account": return "Muted account.";
}
return "";
}
accountSelected(accountName: string): void {
this.browseAccountEvent.next(accountName);
}
hashtagSelected(hashtag: string): void {
this.browseHashtagEvent.next(hashtag);
}
textSelected(): boolean {
let status = this.displayStatus;
const accountInfo = this.accountInfo;
if (status.reblog) {
status = status.reblog;
}
const openThread = new OpenThreadEvent(status, accountInfo);
this.browseThreadEvent.next(openThread);
return false;
}
getAvatar(acc: Account): string {
if (this.freezeAvatarEnabled) {
return acc.avatar_static;
} else {
return acc.avatar;
}
}
openAccount(account: Account): boolean {
let accountName = this.toolsService.getAccountFullHandle(account);
this.browseAccountEvent.emit(accountName);
return false;
}
}