When replying to or bouncing a chat message the post should have ChatMessage type

merge-requests/30/head
Bob Mottram 2022-02-08 12:08:20 +00:00
parent 51a666df39
commit 823b4c331d
4 changed files with 44 additions and 12 deletions

View File

@ -2838,6 +2838,7 @@ class PubServer(BaseHTTPRequestHandler):
custom_submit_text = get_config_param(base_dir, 'customSubmitText') custom_submit_text = get_config_param(base_dir, 'customSubmitText')
conversation_id = None conversation_id = None
reply_is_chat = False
msg = html_new_post(self.server.css_cache, msg = html_new_post(self.server.css_cache,
False, self.server.translate, False, self.server.translate,
base_dir, base_dir,
@ -2872,7 +2873,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.signing_priv_key_pem, self.server.signing_priv_key_pem,
self.server.cw_lists, self.server.cw_lists,
self.server.lists_enabled, self.server.lists_enabled,
self.server.default_timeline).encode('utf-8') self.server.default_timeline,
reply_is_chat).encode('utf-8')
msglen = len(msg) msglen = len(msg)
self._set_headers('text/html', msglen, self._set_headers('text/html', msglen,
cookie, calling_domain, False) cookie, calling_domain, False)
@ -2973,6 +2975,7 @@ class PubServer(BaseHTTPRequestHandler):
custom_submit_text = get_config_param(base_dir, 'customSubmitText') custom_submit_text = get_config_param(base_dir, 'customSubmitText')
conversation_id = None conversation_id = None
reply_is_chat = False
msg = html_new_post(self.server.css_cache, msg = html_new_post(self.server.css_cache,
False, self.server.translate, False, self.server.translate,
base_dir, base_dir,
@ -3006,7 +3009,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.signing_priv_key_pem, self.server.signing_priv_key_pem,
self.server.cw_lists, self.server.cw_lists,
self.server.lists_enabled, self.server.lists_enabled,
self.server.default_timeline).encode('utf-8') self.server.default_timeline,
reply_is_chat).encode('utf-8')
msglen = len(msg) msglen = len(msg)
self._set_headers('text/html', msglen, self._set_headers('text/html', msglen,
cookie, calling_domain, False) cookie, calling_domain, False)
@ -13188,6 +13192,7 @@ class PubServer(BaseHTTPRequestHandler):
media_instance: bool, translate: {}, media_instance: bool, translate: {},
base_dir: str, http_prefix: str, base_dir: str, http_prefix: str,
in_reply_to_url: str, reply_to_list: [], in_reply_to_url: str, reply_to_list: [],
reply_is_chat: bool,
share_description: str, reply_page_number: int, share_description: str, reply_page_number: int,
reply_category: str, reply_category: str,
domain: str, domain_full: str, domain: str, domain_full: str,
@ -13214,7 +13219,7 @@ class PubServer(BaseHTTPRequestHandler):
str(reply_interval_hours) + ' hours') str(reply_interval_hours) + ' hours')
self._403() self._403()
return True return True
elif self.server.debug: if self.server.debug:
print('Reply is within time interval: ' + print('Reply is within time interval: ' +
str(reply_interval_hours) + ' hours') str(reply_interval_hours) + ' hours')
@ -13267,7 +13272,8 @@ class PubServer(BaseHTTPRequestHandler):
self.server.signing_priv_key_pem, self.server.signing_priv_key_pem,
self.server.cw_lists, self.server.cw_lists,
self.server.lists_enabled, self.server.lists_enabled,
self.server.default_timeline).encode('utf-8') self.server.default_timeline,
reply_is_chat).encode('utf-8')
if not msg: if not msg:
print('Error replying to ' + in_reply_to_url) print('Error replying to ' + in_reply_to_url)
self._404() self._404()
@ -15932,10 +15938,12 @@ class PubServer(BaseHTTPRequestHandler):
# replying as a direct message, # replying as a direct message,
# for moderation posts or the dm timeline # for moderation posts or the dm timeline
reply_is_chat = False
if '?replydm=' in self.path or '?replychat=' in self.path: if '?replydm=' in self.path or '?replychat=' in self.path:
reply_type = 'replydm' reply_type = 'replydm'
if '?replychat=' in self.path: if '?replychat=' in self.path:
reply_type = 'replychat' reply_type = 'replychat'
reply_is_chat = True
in_reply_to_url = self.path.split('?' + reply_type + '=')[1] in_reply_to_url = self.path.split('?' + reply_type + '=')[1]
in_reply_to_url = urllib.parse.unquote_plus(in_reply_to_url) in_reply_to_url = urllib.parse.unquote_plus(in_reply_to_url)
if '?' in in_reply_to_url: if '?' in in_reply_to_url:
@ -16071,6 +16079,7 @@ class PubServer(BaseHTTPRequestHandler):
self.server.base_dir, self.server.base_dir,
self.server.http_prefix, self.server.http_prefix,
in_reply_to_url, reply_to_list, in_reply_to_url, reply_to_list,
reply_is_chat,
share_description, reply_page_number, share_description, reply_page_number,
reply_category, reply_category,
self.server.domain, self.server.domain,
@ -16919,6 +16928,7 @@ class PubServer(BaseHTTPRequestHandler):
city = get_spoofed_city(self.server.city, city = get_spoofed_city(self.server.city,
self.server.base_dir, self.server.base_dir,
nickname, self.server.domain) nickname, self.server.domain)
conversation_id = None conversation_id = None
if fields.get('conversationId'): if fields.get('conversationId'):
conversation_id = fields['conversationId'] conversation_id = fields['conversationId']
@ -17305,6 +17315,10 @@ class PubServer(BaseHTTPRequestHandler):
self.server.domain_full, self.server.domain_full,
self.server.person_cache) self.server.person_cache)
reply_is_chat = False
if fields.get('replychatmsg'):
reply_is_chat = fields['replychatmsg']
message_json = \ message_json = \
create_direct_message_post(self.server.base_dir, create_direct_message_post(self.server.base_dir,
nickname, nickname,
@ -17333,7 +17347,8 @@ class PubServer(BaseHTTPRequestHandler):
conversation_id, conversation_id,
self.server.low_bandwidth, self.server.low_bandwidth,
content_license_url, content_license_url,
languages_understood) languages_understood,
reply_is_chat)
if message_json: if message_json:
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1
@ -17396,7 +17411,8 @@ class PubServer(BaseHTTPRequestHandler):
conversation_id, conversation_id,
self.server.low_bandwidth, self.server.low_bandwidth,
self.server.content_license_url, self.server.content_license_url,
languages_understood) languages_understood,
False)
if message_json: if message_json:
if fields['schedulePost']: if fields['schedulePost']:
return 1 return 1

View File

@ -2826,7 +2826,8 @@ def _bounce_dm(senderPostId: str, session, http_prefix: str,
last_bounce_message: [], system_language: str, last_bounce_message: [], system_language: str,
signing_priv_key_pem: str, signing_priv_key_pem: str,
content_license_url: str, content_license_url: str,
languages_understood: []) -> bool: languages_understood: [],
bounce_is_chat: bool) -> bool:
"""Sends a bounce message back to the sending handle """Sends a bounce message back to the sending handle
if a DM has been rejected if a DM has been rejected
""" """
@ -2888,7 +2889,7 @@ def _bounce_dm(senderPostId: str, session, http_prefix: str,
system_language, conversation_id, system_language, conversation_id,
low_bandwidth, low_bandwidth,
content_license_url, content_license_url,
languages_understood) languages_understood, bounce_is_chat)
if not post_json_object: if not post_json_object:
print('WARN: unable to create bounce message to ' + sending_handle) print('WARN: unable to create bounce message to ' + sending_handle)
return False return False
@ -2984,6 +2985,10 @@ def _is_valid_dm(base_dir: str, nickname: str, domain: str, port: int,
if not obj.get('inReplyTo'): if not obj.get('inReplyTo'):
bounced_id = \ bounced_id = \
remove_id_ending(post_json_object['id']) remove_id_ending(post_json_object['id'])
bounce_chat = False
if obj.get('type'):
if obj['type'] == 'ChatMessage':
bounce_chat = True
_bounce_dm(bounced_id, _bounce_dm(bounced_id,
session, http_prefix, session, http_prefix,
base_dir, base_dir,
@ -2998,7 +3003,8 @@ def _is_valid_dm(base_dir: str, nickname: str, domain: str, port: int,
system_language, system_language,
signing_priv_key_pem, signing_priv_key_pem,
content_license_url, content_license_url,
languages_understood) languages_understood,
bounce_chat)
return False return False
# dm index will be updated # dm index will be updated

View File

@ -2113,7 +2113,8 @@ def create_direct_message_post(base_dir: str,
location: str, system_language: str, location: str, system_language: str,
conversation_id: str, low_bandwidth: bool, conversation_id: str, low_bandwidth: bool,
content_license_url: str, content_license_url: str,
languages_understood: []) -> {}: languages_understood: [],
dm_is_chat: bool) -> {}:
"""Direct Message post """Direct Message post
""" """
content = resolve_petnames(base_dir, nickname, domain, content) content = resolve_petnames(base_dir, nickname, domain, content)
@ -2144,6 +2145,8 @@ def create_direct_message_post(base_dir: str,
message_json['object']['to'] = message_json['to'] message_json['object']['to'] = message_json['to']
message_json['cc'] = [] message_json['cc'] = []
message_json['object']['cc'] = [] message_json['object']['cc'] = []
if dm_is_chat:
message_json['object']['type'] = 'ChatMessage'
if schedule_post: if schedule_post:
post_id = remove_id_ending(message_json['object']['id']) post_id = remove_id_ending(message_json['object']['id'])
save_post_to_box(base_dir, http_prefix, post_id, save_post_to_box(base_dir, http_prefix, post_id,

View File

@ -210,7 +210,8 @@ def html_new_post(css_cache: {}, media_instance: bool, translate: {},
system_language: str, system_language: str,
max_like_count: int, signing_priv_key_pem: str, max_like_count: int, signing_priv_key_pem: str,
cw_lists: {}, lists_enabled: str, cw_lists: {}, lists_enabled: str,
boxName: str) -> str: boxName: str,
reply_is_chat: bool) -> str:
"""New post screen """New post screen
""" """
reply_str = '' reply_str = ''
@ -691,7 +692,10 @@ def html_new_post(css_cache: {}, media_instance: bool, translate: {},
dropdown_new_blog_suffix += '?replyto=' + inReplyTo dropdown_new_blog_suffix += '?replyto=' + inReplyTo
dropdown_unlisted_suffix += '?replyto=' + inReplyTo dropdown_unlisted_suffix += '?replyto=' + inReplyTo
dropdown_followers_suffix += '?replyfollowers=' + inReplyTo dropdown_followers_suffix += '?replyfollowers=' + inReplyTo
dropdown_dm_suffix += '?replydm=' + inReplyTo if reply_is_chat:
dropdown_dm_suffix += '?replychat=' + inReplyTo
else:
dropdown_dm_suffix += '?replydm=' + inReplyTo
for mentioned_actor in mentions: for mentioned_actor in mentions:
dropdown_new_post_suffix += '?mention=' + mentioned_actor dropdown_new_post_suffix += '?mention=' + mentioned_actor
dropdown_new_blog_suffix += '?mention=' + mentioned_actor dropdown_new_blog_suffix += '?mention=' + mentioned_actor
@ -732,6 +736,9 @@ def html_new_post(css_cache: {}, media_instance: bool, translate: {},
'<form enctype="multipart/form-data" method="POST" ' + \ '<form enctype="multipart/form-data" method="POST" ' + \
'accept-charset="UTF-8" action="' + \ 'accept-charset="UTF-8" action="' + \
path + '?' + endpoint + '?page=' + str(page_number) + '">\n' path + '?' + endpoint + '?page=' + str(page_number) + '">\n'
if reply_is_chat:
new_post_form += \
' <input type="hidden" name="replychatmsg" value="yes">\n'
if conversationId: if conversationId:
new_post_form += \ new_post_form += \
' <input type="hidden" name="conversationId" value="' + \ ' <input type="hidden" name="conversationId" value="' + \