Browse Source

Add support for Mastodon content warnings and image descriptions.

Syfaro 2 months ago
parent
commit
a8974b6841

+ 12
- 3
src/sites/mastodon.py View File

@@ -161,12 +161,21 @@ class Mastodon(Site):
161 161
 
162 162
         noimage = self.account['twitter_noimage']
163 163
 
164
+        content_warning: str = extra.get('mastodon-warning', None)
165
+        image_desc: str = extra.get('mastodon-image-desc', None)
166
+
167
+        if content_warning == '':
168
+            content_warning = None
169
+
170
+        if image_desc == '':
171
+            image_desc = None
172
+
164 173
         if submission.rating == Rating.explicit and (
165 174
             noimage and noimage.val == 'yes'
166 175
         ):
167
-            status = api.status_post(status=status, sensitive=is_sensitive, visibility='public')
176
+            status = api.status_post(status=status, sensitive=is_sensitive, visibility='public', spoiler_text=content_warning)
168 177
         else:
169
-            media = api.media_post(submission.image_bytes, mime_type=submission.image_mimetype)
170
-            status = api.status_post(status=status, sensitive=is_sensitive, visibility='public', media_ids=media)
178
+            media = api.media_post(submission.image_bytes, mime_type=submission.image_mimetype, description=image_desc)
179
+            status = api.status_post(status=status, sensitive=is_sensitive, visibility='public', media_ids=media, spoiler_text=content_warning)
171 180
 
172 181
         return status['url']

+ 19
- 0
src/static/js/sites/mastodon.js View File

@@ -0,0 +1,19 @@
1
+const siteInputs = Array.from(document.querySelectorAll('input[name="account"]'));
2
+const mastodonItems = document.querySelector('.mastodon-link');
3
+function updateMastodonLinks() {
4
+    let hasMastodonSelected = false;
5
+    siteInputs.forEach(site => {
6
+        if (site.dataset.site === '101' && site.checked) {
7
+            hasMastodonSelected = true;
8
+        }
9
+    });
10
+    if (!hasMastodonSelected) {
11
+        mastodonItems.classList.add('d-none');
12
+    }
13
+    else {
14
+        mastodonItems.classList.remove('d-none');
15
+    }
16
+}
17
+updateMastodonLinks();
18
+siteInputs.forEach(site => site.addEventListener('change', updateMastodonLinks));
19
+//# sourceMappingURL=mastodon.js.map

+ 22
- 0
src/static/ts/sites/mastodon.ts View File

@@ -0,0 +1,22 @@
1
+const siteInputs: HTMLInputElement[] = Array.from(document.querySelectorAll('input[name="account"]'));
2
+const mastodonItems = document.querySelector('.mastodon-link')!;
3
+
4
+function updateMastodonLinks(): void {
5
+    let hasMastodonSelected = false;
6
+
7
+    siteInputs.forEach(site => {
8
+        if (site.dataset.site === '101' && site.checked) {
9
+            hasMastodonSelected = true;
10
+        }
11
+    });
12
+
13
+    if (!hasMastodonSelected) {
14
+        mastodonItems.classList.add('d-none');
15
+    } else {
16
+        mastodonItems.classList.remove('d-none');
17
+    }
18
+}
19
+
20
+updateMastodonLinks();
21
+
22
+siteInputs.forEach(site => site.addEventListener('change', updateMastodonLinks));

+ 1
- 1
src/templates/_main.html View File

@@ -33,7 +33,7 @@
33 33
     {% endif %}
34 34
 {%- endmacro %}
35 35
 
36
-{% set siteTemplatesToLoad = ['deviantart', 'inkbunny', 'twitter'] %} {# TODO: this needs to be dynamic #}
36
+{% set siteTemplatesToLoad = ['deviantart', 'inkbunny', 'twitter', 'mastodon'] %} {# TODO: this needs to be dynamic #}
37 37
 
38 38
 {% macro getSiteTemplates(location) -%}
39 39
     {% for site in siteTemplatesToLoad %}

+ 11
- 0
src/templates/sites/mastodon/right_sidebar.html View File

@@ -0,0 +1,11 @@
1
+<div class="d-none mastodon-link mt-2">
2
+    <div class="form-group">
3
+        <label for="mastodon-warning">Mastodon Content Warning</label>
4
+        <input id="mastodon-warning" type="text" name="mastodon-warning" class="form-control" placeholder="Content Warning" value="{{ sub.data.get('mastodon-warning') or '' if sub else '' }}">
5
+    </div>
6
+
7
+    <div class="form-group">
8
+        <label for="mastodon-image-desc">Mastodon Image Description</label>
9
+        <input id="mastodon-image-desc" type="text" name="mastodon-image-desc" class="form-control" placeholder="Image Description" value="{{ sub.data.get('mastodon-image-desc') or '' if sub else '' }}">
10
+    </div>
11
+</div>

Loading…
Cancel
Save