Handle mentions even if not following

master
Bob Mottram 2019-08-19 12:41:15 +01:00
parent fc0d1ab8a5
commit 984712ab45
1 changed files with 12 additions and 12 deletions

View File

@ -107,7 +107,7 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r
possibleHandle=wordStr[1:] possibleHandle=wordStr[1:]
print('Possible mention: '+possibleHandle) print('Possible mention: '+possibleHandle)
# @nick # @nick
if '@' not in possibleHandle: if following and '@' not in possibleHandle:
# fall back to a best effort match against the following list # fall back to a best effort match against the following list
# if no domain was specified. eg. @nick # if no domain was specified. eg. @nick
possibleNickname=possibleHandle possibleNickname=possibleHandle
@ -122,14 +122,15 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r
return False return False
possibleNickname=possibleHandle.split('@')[0] possibleNickname=possibleHandle.split('@')[0]
possibleDomain=possibleHandle.split('@')[1].strip('\n') possibleDomain=possibleHandle.split('@')[1].strip('\n')
for follow in following: if following:
if follow.replace('\n','')!=possibleHandle: for follow in following:
continue if follow.replace('\n','')!=possibleHandle:
recipientActor=httpPrefix+"://"+possibleDomain+"/users/"+possibleNickname continue
if recipientActor not in recipients: recipientActor=httpPrefix+"://"+possibleDomain+"/users/"+possibleNickname
recipients.append(recipientActor) if recipientActor not in recipients:
replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>" recipients.append(recipientActor)
return True replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
return True
# @nick@domain # @nick@domain
if '@' in possibleHandle: if '@' in possibleHandle:
if not (possibleDomain=='localhost' or '.' in possibleDomain): if not (possibleDomain=='localhost' or '.' in possibleDomain):
@ -183,9 +184,8 @@ def addHtmlTags(baseDir: str,httpPrefix: str, \
# extract mentions and tags from words # extract mentions and tags from words
for wordStr in words: for wordStr in words:
if following: if addMention(wordStr,httpPrefix,following,replaceMentions,recipients):
if addMention(wordStr,httpPrefix,following,replaceMentions,recipients): continue
continue
if addHashTags(wordStr,httpPrefix,originalDomain,replaceHashTags,hashtags): if addHashTags(wordStr,httpPrefix,originalDomain,replaceHashTags,hashtags):
continue continue
if len(wordStr)>2 and wordStr.startswith(':') and wordStr.endswith(':') and not emojiDict: if len(wordStr)>2 and wordStr.startswith(':') and wordStr.endswith(':') and not emojiDict: