Use content_type when posting if it's available in your Mastodon.py
This feature hasn't been merged to mainline yet, and then it will probably take a little longer for it to get on pip, so brutaldon has to be belt-and- suspenders when using it.
This commit is contained in:
parent
5e9feab403
commit
cce4198a3b
|
@ -13,11 +13,16 @@ from urllib import parse
|
|||
from pdb import set_trace
|
||||
from inscriptis import get_text
|
||||
from time import sleep
|
||||
import inspect
|
||||
import re
|
||||
|
||||
class NotLoggedInException(Exception):
|
||||
pass
|
||||
|
||||
def post_has_content_type():
|
||||
sig = inspect.signature(Mastodon.status_post)
|
||||
return 'content_type' in sig.parameters.keys()
|
||||
|
||||
def get_usercontext(request):
|
||||
if is_logged_in(request):
|
||||
try:
|
||||
|
@ -485,10 +490,17 @@ def toot(request, mention=None):
|
|||
if form.cleaned_data['visibility'] == '':
|
||||
form.cleaned_data['visibility'] = request.session['user'].source.privacy
|
||||
try:
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects)
|
||||
if post_has_content_type():
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects,
|
||||
content_type='text/markdown')
|
||||
else:
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects)
|
||||
except MastodonAPIError as error:
|
||||
form.add_error("", "%s (%s used)" % (error.args[-1],
|
||||
len(form.cleaned_data['status'])
|
||||
|
@ -542,11 +554,19 @@ def redraft(request, id):
|
|||
if form.cleaned_data['visibility'] == '':
|
||||
form.cleaned_data['visibility'] = request.session['user'].source.privacy
|
||||
try:
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects,
|
||||
in_reply_to_id=toot.in_reply_to_id)
|
||||
if post_has_content_type():
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects,
|
||||
in_reply_to_id=toot.in_reply_to_id,
|
||||
content_type='text/markdown')
|
||||
else:
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects,
|
||||
in_reply_to_id=toot.in_reply_to_id)
|
||||
mastodon.status_delete(id)
|
||||
except MastodonAPIError as error:
|
||||
form.add_error("", "%s (%s used)" % (error.args[-1],
|
||||
|
@ -616,11 +636,19 @@ def reply(request, id):
|
|||
+str(index),
|
||||
None)))
|
||||
try:
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects,
|
||||
in_reply_to_id=id)
|
||||
if post_has_content_type():
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects,
|
||||
in_reply_to_id=id,
|
||||
content_type="text/markdown")
|
||||
else:
|
||||
mastodon.status_post(status=form.cleaned_data['status'],
|
||||
visibility=form.cleaned_data['visibility'],
|
||||
spoiler_text=form.cleaned_data['spoiler_text'],
|
||||
media_ids=media_objects,
|
||||
in_reply_to_id=id)
|
||||
except MastodonAPIError as error:
|
||||
form.add_error("", "%s (%s used)" % (error.args[-1],
|
||||
len(form.cleaned_data['status'])
|
||||
|
|
Loading…
Reference in New Issue