ContentFilterable
protocol ContentFilterable
A Protocol
used to provide convenience functions for Models that return content that is filterable.
Adopting the protocol requires implmenting contentTextStrings()
which returns an array of ‘content’
strings that should be scanned in a filter operation.
-
Declaration
Swift
func contentTextStrings() -> [String]
-
containsMutewords(using:
Extension method) Checks if a
ContentFilterable
contains any of the provided array of muting strings, returning true if it doesDeclaration
Swift
func containsMutewords(using mutewords: [String]) -> Bool
Parameters
mutewords
The list of strings on which to filter the post.
Return Value
TRUE if the post contains a muting string.
-
filterOutStrings(using:
Extension method) Checks if a
ContentFilterable
contains any of the provided array of strings, returningnil
if it does, else returningself
. Returnsself
if the array of search strings is empty ornil
.Declaration
Swift
func filterOutStrings(using words: [String]?) -> Self?
Parameters
words
The list of strings on which to filter the post.
Return Value
The provided object, or
nil
if the object’s text fields contain a string. -
getMentionsDiffs(editedString:
Extension methodisCreate: ) Returns (removes, adds) which are (importantly!) disjoint sets of usernames @mentioned in the reciever or in the editedString. Used to update mention counts for mentioned users. A user @mentioned multiple times in the same ContentFilterable only counts once.
Declaration
Swift
func getMentionsDiffs(editedString: String?, isCreate: Bool) -> (Set<String>, Set<String>)
-
getAlertwordDiffs(editedString:
Extension methodisCreate: ) Declaration
Swift
func getAlertwordDiffs(editedString: String?, isCreate: Bool) -> (Set<String>, Set<String>)
-
getHashtags()
Extension methodRetuns all discovered hashtags in all text strings of the content.
Declaration
Swift
func getHashtags() -> Set<String>
-
buildCleanWordsArray(_:
Extension method) Declaration
Swift
static func buildCleanWordsArray(_ str: String) -> Set<String>
-
getMentionsSet(for:
Extension method) Returns a set of possible usernames found as @mentions in the given string. Does not check whether the @mentions are valid users. The regex looks for:
- Start-of-string or whitespace,
- ‘@’
- 2…50 characters that are in the set of valid Username chars
- Trailing separator characters are excluded from the mention (such as ending with punctuation)
- A non-Username char or end-of-string. ChatGPT turned this from a mega string processing nightmare into an unreadable regex! “Software”
Example: “@heidi likes @sam” -> [“heidi”, “sam”]
Declaration
Swift
static func getMentionsSet(for string: String) -> Set<String>
-
filterForMention(of:
Extension method) Fluent queries can filter for strings in text fields, but @mentions require more specific filtering. This fn tests that the given username is @mentioned in the receiver’s content. It’s specifically looking for cases where one name is a substring of another.
Example: both @John and @John.Doe are users. Simple string search returns @John.Doe results in a search for @John.
Also, if a user is @mentioned at the end of a sentence, the period is a valid username char, but is not valid at the end of a username (must have a following alphanumeric).
@TODO consider: https://www.swiftbysundell.com/articles/string-parsing-in-swift/
Declaration
Swift
func filterForMention(of username: String) -> Self?
Parameters
username
String of the username (including @) that we are attempting to match for.
Return Value
A ContentFilterable (such as ForumPost or FezPost) if the username is found, else nil.