Make reasons show

* If BE nodeinfo sends a mrf_simple_info and/or quarantined_instances_info, we'll try to get the reason for each instance for each policy and show it in the about page
This commit is contained in:
Ilja 2020-11-22 12:05:10 +01:00
parent 56d85654b1
commit c3ddd0c832
2 changed files with 106 additions and 51 deletions

View file

@ -2,17 +2,18 @@ import { mapState } from 'vuex'
import { get } from 'lodash'
/**
* This function is for backwards compatibility
* We used to get a list of strings for instances that
* are rejected/quarantined/etc. Now we get an object
* `{ "instance": instance, "reason": reason }`
* This is for backwards compatibility. We originally didn't recieve
* extra info like a reason why an instance was rejected/quarantined/etc.
* Because we didn't want to break backwards compatibility it was decided
* to add an extra "info" key.
*/
function toInstanceReasonObject (e) {
if (typeof e === 'object' && e !== null) {
return e
} else {
return { 'instance': e, 'reason': '' }
}
function toInstanceReasonObject (instances, info, key) {
return instances.map(instance => {
if (info[key] && info[key][instance] && info[key][instance]['reason']) {
return { 'instance': instance, 'reason': info[key][instance]['reason'] }
}
return { 'instance': instance, 'reason': '' }
})
}
const MRFTransparencyPanel = {
@ -20,12 +21,36 @@ const MRFTransparencyPanel = {
...mapState({
federationPolicy: state => get(state, 'instance.federationPolicy'),
mrfPolicies: state => get(state, 'instance.federationPolicy.mrf_policies', []),
quarantineInstances: state => get(state, 'instance.federationPolicy.quarantined_instances', []).map(toInstanceReasonObject),
acceptInstances: state => get(state, 'instance.federationPolicy.mrf_simple.accept', []),
rejectInstances: state => get(state, 'instance.federationPolicy.mrf_simple.reject', []),
ftlRemovalInstances: state => get(state, 'instance.federationPolicy.mrf_simple.federated_timeline_removal', []),
mediaNsfwInstances: state => get(state, 'instance.federationPolicy.mrf_simple.media_nsfw', []),
mediaRemovalInstances: state => get(state, 'instance.federationPolicy.mrf_simple.media_removal', []),
quarantineInstances: state => toInstanceReasonObject(
get(state, 'instance.federationPolicy.quarantined_instances', []),
get(state, 'instance.federationPolicy.quarantined_instances_info', []),
'quarantined_instances'
),
acceptInstances: state => toInstanceReasonObject(
get(state, 'instance.federationPolicy.mrf_simple.accept', []),
get(state, 'instance.federationPolicy.mrf_simple_info', []),
'accept'
),
rejectInstances: state => toInstanceReasonObject(
get(state, 'instance.federationPolicy.mrf_simple.reject', []),
get(state, 'instance.federationPolicy.mrf_simple_info', []),
'reject'
),
ftlRemovalInstances: state => toInstanceReasonObject(
get(state, 'instance.federationPolicy.mrf_simple.federated_timeline_removal', []),
get(state, 'instance.federationPolicy.mrf_simple_info', []),
'federated_timeline_removal'
),
mediaNsfwInstances: state => toInstanceReasonObject(
get(state, 'instance.federationPolicy.mrf_simple.media_nsfw', []),
get(state, 'instance.federationPolicy.mrf_simple_info', []),
'media_nsfw'
),
mediaRemovalInstances: state => toInstanceReasonObject(
get(state, 'instance.federationPolicy.mrf_simple.media_removal', []),
get(state, 'instance.federationPolicy.mrf_simple_info', []),
'media_removal'
),
keywordsFtlRemoval: state => get(state, 'instance.federationPolicy.mrf_keyword.federated_timeline_removal', []),
keywordsReject: state => get(state, 'instance.federationPolicy.mrf_keyword.reject', []),
keywordsReplace: state => get(state, 'instance.federationPolicy.mrf_keyword.replace', [])

View file

@ -31,13 +31,19 @@
<p>{{ $t("about.mrf.simple.accept_desc") }}</p>
<ul>
<li
v-for="instance in acceptInstances"
:key="instance"
v-text="instance"
/>
</ul>
<table style="width:100%;text-align: left;">
<tr>
<th>{{ $t("about.mrf.simple.instance") }}</th>
<th>{{ $t("about.mrf.simple.reason") }}</th>
</tr>
<tr
v-for="entry in acceptInstances"
:key="entry"
>
<td>{{ entry.instance }}</td>
<td>{{ entry.reason }}</td>
</tr>
</table>
</div>
<div v-if="rejectInstances.length">
@ -45,13 +51,19 @@
<p>{{ $t("about.mrf.simple.reject_desc") }}</p>
<ul>
<li
v-for="instance in rejectInstances"
:key="instance"
v-text="instance"
/>
</ul>
<table style="width:100%;text-align: left;">
<tr>
<th>{{ $t("about.mrf.simple.instance") }}</th>
<th>{{ $t("about.mrf.simple.reason") }}</th>
</tr>
<tr
v-for="entry in rejectInstances"
:key="entry"
>
<td>{{ entry.instance }}</td>
<td>{{ entry.reason }}</td>
</tr>
</table>
</div>
<div v-if="quarantineInstances.length">
@ -79,13 +91,19 @@
<p>{{ $t("about.mrf.simple.ftl_removal_desc") }}</p>
<ul>
<li
v-for="instance in ftlRemovalInstances"
:key="instance"
v-text="instance"
/>
</ul>
<table style="width:100%;text-align: left;">
<tr>
<th>{{ $t("about.mrf.simple.instance") }}</th>
<th>{{ $t("about.mrf.simple.reason") }}</th>
</tr>
<tr
v-for="entry in ftlRemovalInstances"
:key="entry"
>
<td>{{ entry.instance }}</td>
<td>{{ entry.reason }}</td>
</tr>
</table>
</div>
<div v-if="mediaNsfwInstances.length">
@ -93,13 +111,19 @@
<p>{{ $t("about.mrf.simple.media_nsfw_desc") }}</p>
<ul>
<li
v-for="instance in mediaNsfwInstances"
:key="instance"
v-text="instance"
/>
</ul>
<table style="width:100%;text-align: left;">
<tr>
<th>{{ $t("about.mrf.simple.instance") }}</th>
<th>{{ $t("about.mrf.simple.reason") }}</th>
</tr>
<tr
v-for="entry in mediaNsfwInstances"
:key="entry"
>
<td>{{ entry.instance }}</td>
<td>{{ entry.reason }}</td>
</tr>
</table>
</div>
<div v-if="mediaRemovalInstances.length">
@ -107,13 +131,19 @@
<p>{{ $t("about.mrf.simple.media_removal_desc") }}</p>
<ul>
<li
v-for="instance in mediaRemovalInstances"
:key="instance"
v-text="instance"
/>
</ul>
<table style="width:100%;text-align: left;">
<tr>
<th>{{ $t("about.mrf.simple.instance") }}</th>
<th>{{ $t("about.mrf.simple.reason") }}</th>
</tr>
<tr
v-for="entry in mediaNsfwInstances"
:key="entry"
>
<td>{{ entry.instance }}</td>
<td>{{ entry.reason }}</td>
</tr>
</table>
</div>
<h2 v-if="hasKeywordPolicies">