Check for valid handle

main2
Bob Mottram 2019-10-29 20:15:21 +00:00
parent bb954b62c6
commit e585424814
1 changed files with 20 additions and 14 deletions

View File

@ -198,8 +198,16 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r
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>"
return True return True
return False return False
possibleNickname=None
possibleDomain=None
if '@' not in possibleHandle:
return False
possibleNickname=possibleHandle.split('@')[0] possibleNickname=possibleHandle.split('@')[0]
if not possibleNickname:
return False
possibleDomain=possibleHandle.split('@')[1].strip('\n') possibleDomain=possibleHandle.split('@')[1].strip('\n')
if not possibleDomain:
return False
if following: if following:
for follow in following: for follow in following:
if follow.replace('\n','')!=possibleHandle: if follow.replace('\n','')!=possibleHandle:
@ -215,20 +223,18 @@ def addMention(wordStr: str,httpPrefix: str,following: str,replaceMentions: {},r
replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>" replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
return True return True
# @nick@domain # @nick@domain
if '@' in possibleHandle: if not (possibleDomain=='localhost' or '.' in possibleDomain):
if not (possibleDomain=='localhost' or '.' in possibleDomain): return False
return False recipientActor=httpPrefix+"://"+possibleDomain+"/users/"+possibleNickname
recipientActor=httpPrefix+"://"+possibleDomain+"/users/"+possibleNickname if recipientActor not in recipients:
if recipientActor not in recipients: recipients.append(recipientActor)
recipients.append(recipientActor) tags[wordStr]={
tags[wordStr]={ 'href': recipientActor,
'href': recipientActor, 'name': wordStr,
'name': wordStr, 'type': 'Mention'
'type': 'Mention' }
} replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>"
replaceMentions[wordStr]="<span class=\"h-card\"><a href=\""+httpPrefix+"://"+possibleDomain+"/@"+possibleNickname+"\" class=\"u-url mention\">@<span>"+possibleNickname+"</span></a></span>" return True
return True
return False
def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str: def removeLongWords(content: str,maxWordLength: int,longWordsList: []) -> str:
"""Breaks up long words so that on mobile screens this doesn't disrupt the layout """Breaks up long words so that on mobile screens this doesn't disrupt the layout