Implement mentions as a separate text field in replies

This avoids the need for any javascript putting the cursor at the end of the mentions
main
Bob Mottram 2020-06-26 10:09:53 +00:00
parent 125ead6f8b
commit fcbdf2be84
17 changed files with 58 additions and 47 deletions

View File

@ -5205,6 +5205,9 @@ class PubServer(BaseHTTPRequestHandler):
except BaseException:
pass
mentionsStr = ''
if fields.get('mentions'):
mentionsStr = fields['mentions'].strip() + ' '
if postType == 'newpost':
messageJson = \
createPublicPost(self.server.baseDir,
@ -5212,7 +5215,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain,
self.server.port,
self.server.httpPrefix,
fields['message'],
mentionsStr + fields['message'],
False, False, False,
filename, attachmentMediaType,
fields['imageDescription'],
@ -5341,7 +5344,7 @@ class PubServer(BaseHTTPRequestHandler):
nickname,
self.server.domain, self.server.port,
self.server.httpPrefix,
fields['message'],
mentionsStr + fields['message'],
False, False, False,
filename, attachmentMediaType,
fields['imageDescription'],
@ -5373,7 +5376,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain,
self.server.port,
self.server.httpPrefix,
fields['message'],
mentionsStr + fields['message'],
True, False, False,
filename, attachmentMediaType,
fields['imageDescription'],
@ -5401,13 +5404,14 @@ class PubServer(BaseHTTPRequestHandler):
elif postType == 'newdm':
messageJson = None
print('A DM was posted')
if '@' in fields['message']:
if '@' in mentionsStr:
messageJson = \
createDirectMessagePost(self.server.baseDir,
nickname,
self.server.domain,
self.server.port,
self.server.httpPrefix,
mentionsStr +
fields['message'],
True, False, False,
filename, attachmentMediaType,
@ -5440,15 +5444,15 @@ class PubServer(BaseHTTPRequestHandler):
messageJson = None
handle = nickname + '@' + self.server.domainFull
print('A reminder was posted for ' + handle)
if '@' + handle not in fields['message']:
fields['message'] = '@' + handle + ' ' + fields['message']
if '@' + handle not in mentionsStr:
mentionsStr = '@' + handle + ' ' + mentionsStr
messageJson = \
createDirectMessagePost(self.server.baseDir,
nickname,
self.server.domain,
self.server.port,
self.server.httpPrefix,
fields['message'],
mentionsStr + fields['message'],
True, False, False,
filename, attachmentMediaType,
fields['imageDescription'],
@ -5481,7 +5485,7 @@ class PubServer(BaseHTTPRequestHandler):
nickname,
self.server.domain, self.server.port,
self.server.httpPrefix,
fields['message'],
mentionsStr + fields['message'],
True, False, False,
filename, attachmentMediaType,
fields['imageDescription'],

View File

@ -234,5 +234,6 @@
"Henge": "هنج",
"QR Code": "رمز الاستجابة السريعة",
"Reminder": "تذكير",
"Scheduled note to yourself": "ملاحظة مجدولة لنفسك"
"Scheduled note to yourself": "ملاحظة مجدولة لنفسك",
"Replying to": "الرد على"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "Codi QR",
"Reminder": "Recordatori",
"Scheduled note to yourself": "Nota programada a tu mateix"
"Scheduled note to yourself": "Nota programada a tu mateix",
"Replying to": "Responent a"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "Cod QR",
"Reminder": "Nodyn atgoffa",
"Scheduled note to yourself": "Nodyn wedi'i drefnu i chi'ch hun"
"Scheduled note to yourself": "Nodyn wedi'i drefnu i chi'ch hun",
"Replying to": "Ymateb i"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "QR-Code",
"Reminder": "Erinnerung",
"Scheduled note to yourself": "Geplante Notiz an dich"
"Scheduled note to yourself": "Geplante Notiz an dich",
"Replying to": "Antworten auf"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "QR Code",
"Reminder": "Reminder",
"Scheduled note to yourself": "Scheduled note to yourself"
"Scheduled note to yourself": "Scheduled note to yourself",
"Replying to": "Replying to"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "Código QR",
"Reminder": "Recordatorio",
"Scheduled note to yourself": "Nota programada para ti"
"Scheduled note to yourself": "Nota programada para ti",
"Replying to": "Respondiendo a"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "QR Code",
"Reminder": "Rappel",
"Scheduled note to yourself": "Note programmée pour vous"
"Scheduled note to yourself": "Note programmée pour vous",
"Replying to": "Répondre à"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "Cód QR",
"Reminder": "Meabhrúchán",
"Scheduled note to yourself": "Nóta sceidealta duit féin"
"Scheduled note to yourself": "Nóta sceidealta duit féin",
"Replying to": "Ag freagairt do"
}

View File

@ -234,5 +234,6 @@
"Henge": "हेंगे",
"QR Code": "क्यूआर कोड",
"Reminder": "अनुस्मारक",
"Scheduled note to yourself": "खुद को निर्धारित नोट"
"Scheduled note to yourself": "खुद को निर्धारित नोट",
"Replying to": "को जवाब दे रहा है"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "QR Code",
"Reminder": "Promemoria",
"Scheduled note to yourself": "Nota programmata per te"
"Scheduled note to yourself": "Nota programmata per te",
"Replying to": "In risposta a"
}

View File

@ -234,5 +234,6 @@
"Henge": "ヘンゲ",
"QR Code": "QRコード",
"Reminder": "リマインダー",
"Scheduled note to yourself": "自分への予定されたメモ"
"Scheduled note to yourself": "自分への予定されたメモ",
"Replying to": "に返信しています"
}

View File

@ -230,5 +230,6 @@
"Henge": "Henge",
"QR Code": "QR Code",
"Reminder": "Reminder",
"Scheduled note to yourself": "Scheduled note to yourself"
"Scheduled note to yourself": "Scheduled note to yourself",
"Replying to": "Replying to"
}

View File

@ -234,5 +234,6 @@
"Henge": "Henge",
"QR Code": "Código QR",
"Reminder": "Lembrete",
"Scheduled note to yourself": "Nota agendada para si mesmo"
"Scheduled note to yourself": "Nota agendada para si mesmo",
"Replying to": "Respondendo a"
}

View File

@ -234,5 +234,6 @@
"Henge": "Хендж",
"QR Code": "QR код",
"Reminder": "напоминание",
"Scheduled note to yourself": "Запланированная заметка для себя"
"Scheduled note to yourself": "Запланированная заметка для себя",
"Replying to": "Отвечать на"
}

View File

@ -233,5 +233,6 @@
"Henge": "亨格",
"QR Code": "二维码",
"Reminder": "提醒",
"Scheduled note to yourself": "预定给自己的笔记"
"Scheduled note to yourself": "预定给自己的笔记",
"Replying to": "回覆"
}

View File

@ -1798,6 +1798,11 @@ def htmlNewPost(mediaInstance: bool, translate: {},
scopeDescription = translate['Public']
placeholderSubject = \
translate['Subject or Content Warning (optional)'] + '...'
placeholderMentions = ''
if inReplyTo:
# mentionsAndContent = getMentionsString(content)
placeholderMentions = \
translate['Replying to'] + '...'
placeholderMessage = translate['Write something'] + '...'
extraFields = ''
endpoint = 'newpost'
@ -2070,10 +2075,20 @@ def htmlNewPost(mediaInstance: bool, translate: {},
newPostForm += replyStr
if mediaInstance and not replyStr:
newPostForm += newPostImageSection
newPostForm += \
' <label class="labels">' + placeholderSubject + '</label><br>'
newPostForm += ' <input type="text" name="subject">'
newPostForm += ''
if inReplyTo:
newPostForm += \
' <label class="labels">' + placeholderMentions + '</label><br>'
newPostForm += \
' <input type="text" name="mentions" value="' + \
mentionsStr + '">'
newPostForm += ''
newPostForm += \
' <br><label class="labels">' + placeholderMessage + '</label>'
messageBoxHeight = 400
@ -2087,7 +2102,7 @@ def htmlNewPost(mediaInstance: bool, translate: {},
newPostForm += \
' <textarea id="message" name="message" style="height:' + \
str(messageBoxHeight) + 'px">' + mentionsStr + '</textarea>\n'
str(messageBoxHeight) + 'px"></textarea>\n'
newPostForm += extraFields+dateAndLocation
if not mediaInstance or replyStr:
newPostForm += newPostImageSection
@ -2095,8 +2110,6 @@ def htmlNewPost(mediaInstance: bool, translate: {},
newPostForm += '</form>\n'
if not reportUrl:
newPostForm += \
'<script>' + cursorToEndOfMessageScript() + '</script>'
newPostForm = \
newPostForm.replace('<body>', '<body onload="focusOnMessage()">')
@ -2743,27 +2756,6 @@ def individualFollowAsHtml(translate: {},
return resultStr
def cursorToEndOfMessageScript() -> str:
"""Moves the cursor to the end of the text in a textarea
This avoids the cursor being in the wrong position when replying
"""
script = 'function focusOnMessage() {\n'
script += " var replyTextArea=document.getElementById('message');\n"
script += ' val=replyTextArea.value;\n'
script += ' if ((val.length>0) && (val.charAt(val.length-1) != " ")) {\n'
script += ' val += " ";\n'
script += ' }\n'
script += ' replyTextArea.focus();\n'
script += ' replyTextArea.value="";\n'
script += ' replyTextArea.value=val;\n'
script += '}\n'
script += "var replyTextArea=document.getElementById('message')\n"
script += 'replyTextArea.onFocus=function() {\n'
script += ' focusOnMessage();'
script += '}\n'
return script
def addEmbeddedAudio(translate: {}, content: str) -> str:
"""Adds embedded audio for mp3/ogg
"""