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 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, def addMention(wordStr: str, httpPrefix: str, following: str,
replaceMentions: {}, recipients: [], tags: {}) -> bool: replaceMentions: {}, recipients: [], tags: {}) -> bool:
"""Detects mentions and adds them to the replacements dict and """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 utils import removeHtml
from media import attachMedia from media import attachMedia
from media import replaceYouTube from media import replaceYouTube
from content import tagExists
from content import removeLongWords from content import removeLongWords
from content import addHtmlTags from content import addHtmlTags
from content import replaceEmojiFromTags from content import replaceEmojiFromTags
@ -801,7 +802,8 @@ def createPostBase(baseDir: str, nickname: str, domain: str, port: int,
isPublic = True isPublic = True
break break
for tagName, tag in hashtagsDict.items(): for tagName, tag in hashtagsDict.items():
tags.append(tag) if not tagExists(tag['type'], tag['name'], tags):
tags.append(tag)
if isPublic: if isPublic:
updateHashtagsIndex(baseDir, tag, newPostId) updateHashtagsIndex(baseDir, tag, newPostId)
print('Content tags: ' + str(tags)) print('Content tags: ' + str(tags))

View File

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