Check if tag already exists

main
Bob Mottram 2020-12-13 20:07:45 +00:00
parent 9d176ab77d
commit 88b0a6aa6f
3 changed files with 13 additions and 2 deletions

View File

@ -508,6 +508,15 @@ def addEmoji(baseDir: str, wordStr: str,
return True
def tagExists(tagType: str, tagName: str, tags: {}) -> bool:
"""Returns true if a tag exists in the given dict
"""
for tag in tags:
if tag['name'] == tagName and tag['type'] == tagType:
return True
return False
def addMention(wordStr: str, httpPrefix: str, following: str,
replaceMentions: {}, recipients: [], tags: {}) -> bool:
"""Detects mentions and adds them to the replacements dict and

View File

@ -52,6 +52,7 @@ from utils import votesOnNewswireItem
from utils import removeHtml
from media import attachMedia
from media import replaceYouTube
from content import tagExists
from content import removeLongWords
from content import addHtmlTags
from content import replaceEmojiFromTags
@ -801,6 +802,7 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
isPublic = True
break
for tagName, tag in hashtagsDict.items():
if not tagExists(tag['type'], tag['name'], tags):
tags.append(tag)
if isPublic:
updateHashtagsIndex(baseDir, tag, newPostId)

View File

@ -2506,7 +2506,7 @@ def testReplyToPublicPost() -> None:
"@ninjarodent@rat.site This is a test.",
False, False, False, True,
None, None, False, postId)
print(str(reply))
# print(str(reply))
assert reply['object']['content'] == \
'<p><span class=\"h-card\">' + \
'<a href=\"https://rat.site/@ninjarodent\" ' + \