Also send to mentioned recipients

master
Bob Mottram 2019-08-05 17:56:32 +01:00
parent 491df84892
commit 88b0b13ddc
3 changed files with 15 additions and 6 deletions

View File

@ -10,7 +10,8 @@ import os
import commentjson import commentjson
def addMentions(baseDir: str,httpPrefix: str, \ def addMentions(baseDir: str,httpPrefix: str, \
nickname: str,domain: str,content: str) -> str: nickname: str,domain: str,content: str, \
recipients: []) -> str:
""" Replaces plaintext mentions such as @nick@domain into html """ Replaces plaintext mentions such as @nick@domain into html
by matching against known following accounts by matching against known following accounts
""" """
@ -44,8 +45,11 @@ def addMentions(baseDir: str,httpPrefix: str, \
if not replaceFound: if not replaceFound:
# fall back to a best effort match if an exact one is not found # fall back to a best effort match if an exact one is not found
for follow in following: for follow in following:
if follow.startsWith(possibleNickname+'@'): if follow.startswith(possibleNickname+'@'):
replaceDomain=follow.replace('\n','').split('@')[1] replaceDomain=follow.replace('\n','').split('@')[1]
recipientActor=httpPrefix+"://"+replaceDomain+"/users/"+possibleNickname
if recipientActor not in recipients:
recipients.append(recipientActor)
replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+replaceDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>" replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+replaceDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
replaceFound=True replaceFound=True
break break

View File

@ -1795,7 +1795,7 @@ class PubServer(BaseHTTPRequestHandler):
addMentions(self.server.baseDir, \ addMentions(self.server.baseDir, \
self.server.httpPrefix, \ self.server.httpPrefix, \
nickname, \ nickname, \
self.server.domain,fields['bio']) self.server.domain,fields['bio'],[])
actorChanged=True actorChanged=True
if fields.get('approveFollowers'): if fields.get('approveFollowers'):
approveFollowers=False approveFollowers=False

View File

@ -379,10 +379,12 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
inReplyTo=None, inReplyToAtomUri=None, subject=None) -> {}: inReplyTo=None, inReplyToAtomUri=None, subject=None) -> {}:
"""Creates a message """Creates a message
""" """
mentionedRecipients=[]
if not clientToServer: if not clientToServer:
# convert content to html # convert content to html
content=addMentions(baseDir,httpPrefix, \ content=addMentions(baseDir,httpPrefix, \
nickname,domain,content) nickname,domain,content, \
mentionedRecipients)
if port!=80 and port!=443: if port!=80 and port!=443:
if ':' not in domain: if ':' not in domain:
@ -404,6 +406,9 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
summary=subject summary=subject
sensitive=True sensitive=True
# who to send to
toRecipients=[toUrl] + mentionedRecipients
if not clientToServer: if not clientToServer:
actorUrl=httpPrefix+'://'+domain+'/users/'+nickname actorUrl=httpPrefix+'://'+domain+'/users/'+nickname
@ -434,7 +439,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
'published': published, 'published': published,
'url': httpPrefix+'://'+domain+'/@'+nickname+'/'+statusNumber, 'url': httpPrefix+'://'+domain+'/@'+nickname+'/'+statusNumber,
'attributedTo': httpPrefix+'://'+domain+'/users/'+nickname, 'attributedTo': httpPrefix+'://'+domain+'/users/'+nickname,
'to': [toUrl], 'to': toRecipients,
'cc': [], 'cc': [],
'sensitive': sensitive, 'sensitive': sensitive,
'atomUri': newPostId, 'atomUri': newPostId,
@ -471,7 +476,7 @@ def createPostBase(baseDir: str,nickname: str, domain: str, port: int, \
'published': published, 'published': published,
'url': httpPrefix+'://'+domain+'/@'+nickname+'/'+statusNumber, 'url': httpPrefix+'://'+domain+'/@'+nickname+'/'+statusNumber,
'attributedTo': httpPrefix+'://'+domain+'/users/'+nickname, 'attributedTo': httpPrefix+'://'+domain+'/users/'+nickname,
'to': [toUrl], 'to': toRecipients,
'cc': [], 'cc': [],
'sensitive': sensitive, 'sensitive': sensitive,
'atomUri': newPostId, 'atomUri': newPostId,