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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
|
/*
GoToSocial
Copyright (C) GoToSocial Authors admin@gotosocial.org
SPDX-License-Identifier: AGPL-3.0-or-later
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU Affero General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU Affero General Public License for more details.
You should have received a copy of the GNU Affero General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import React, { useMemo } from "react";
import { useLocation } from "wouter";
import { DomainPermSub } from "../../../../lib/types/domain-permission";
import { yesOrNo } from "../../../../lib/util";
export function DomainPermissionSubscriptionHelpText() {
return (
<>
Domain permission subscriptions allow your instance to "subscribe" to a list of block or allows at a given url.
<br/>
Every 24 hours, each subscribed list is fetched by your instance, and any discovered
permissions in each list are loaded into your instance as blocks/allows/drafts.
</>
);
}
export function DomainPermissionSubscriptionDocsLink() {
return (
<a
href="https://docs.gotosocial.org/en/latest/admin/settings/#domain-permission-subscriptions"
target="_blank"
className="docslink"
rel="noreferrer"
>
Learn more about domain permission subscriptions (opens in a new tab)
</a>
);
}
export interface SubscriptionEntryProps {
permSub: DomainPermSub;
linkTo: string;
backLocation: string;
}
export function SubscriptionListEntry({ permSub, linkTo, backLocation }: SubscriptionEntryProps) {
const [ _location, setLocation ] = useLocation();
const permType = permSub.permission_type;
if (!permType) {
throw "permission_type was undefined";
}
const {
priority,
title,
uri,
as_draft: asDraft,
adopt_orphans: adoptOrphans,
content_type: contentType,
fetched_at: fetchedAt,
successfully_fetched_at: successfullyFetchedAt,
count,
} = permSub;
const ariaLabel = useMemo(() => {
let ariaLabel = "";
// Prepend title.
if (title.length !== 0) {
ariaLabel += `${title}, create `;
} else {
ariaLabel += "Create ";
}
// Add perm type.
ariaLabel += permType;
// Alter wording
// if using drafts.
if (asDraft) {
ariaLabel += " drafts from ";
} else {
ariaLabel += "s from ";
}
// Add url.
ariaLabel += uri;
return ariaLabel;
}, [title, permType, asDraft, uri]);
let fetchedAtStr = "never";
if (fetchedAt) {
fetchedAtStr = new Date(fetchedAt).toDateString();
}
let successfullyFetchedAtStr = "never";
if (successfullyFetchedAt) {
successfullyFetchedAtStr = new Date(successfullyFetchedAt).toDateString();
}
return (
<span
className={`pseudolink domain-permission-subscription entry`}
aria-label={ariaLabel}
title={ariaLabel}
onClick={() => {
// When clicking on a subscription, direct
// to the detail view for that subscription.
setLocation(linkTo, {
// Store the back location in history so
// the detail view can use it to return to
// this page (including query parameters).
state: { backLocation: backLocation }
});
}}
role="link"
tabIndex={0}
>
<dl className="info-list">
{ permSub.title !== "" &&
<span className="domain-permission-subscription-title">
{title}
</span>
}
<div className="info-list-entry">
<dt>Priority:</dt>
<dd>{priority}</dd>
</div>
<div className="info-list-entry">
<dt>Permission type:</dt>
<dd className={`permission-type ${permType}`}>
<i
aria-hidden={true}
className={`fa fa-${permType === "allow" ? "check" : "close"}`}
></i>
{permType}
</dd>
</div>
<div className="info-list-entry">
<dt>URL:</dt>
<dd className="text-cutoff">{uri}</dd>
</div>
<div className="info-list-entry">
<dt>Content type:</dt>
<dd>{contentType}</dd>
</div>
<div className="info-list-entry">
<dt>Create as draft:</dt>
<dd>{yesOrNo(asDraft)}</dd>
</div>
<div className="info-list-entry">
<dt>Adopt orphans:</dt>
<dd>{yesOrNo(adoptOrphans)}</dd>
</div>
<div className="info-list-entry">
<dt>Last fetch attempt:</dt>
<dd className="text-cutoff">{fetchedAtStr}</dd>
</div>
<div className="info-list-entry">
<dt>Last successful fetch:</dt>
<dd className="text-cutoff">{successfullyFetchedAtStr}</dd>
</div>
<div className="info-list-entry">
<dt>Discovered {permType}s:</dt>
<dd>{count}</dd>
</div>
</dl>
</span>
);
}
|