2018-08-29 01:18:58 +00:00
|
|
|
//
|
|
|
|
// Account+Preferences.swift
|
|
|
|
// Tusker
|
|
|
|
//
|
|
|
|
// Created by Shadowfacts on 8/28/18.
|
|
|
|
// Copyright © 2018 Shadowfacts. All rights reserved.
|
|
|
|
//
|
|
|
|
|
|
|
|
import Foundation
|
2018-09-11 14:52:21 +00:00
|
|
|
import Pachyderm
|
2018-08-29 01:18:58 +00:00
|
|
|
|
2020-04-12 16:54:27 +00:00
|
|
|
extension AccountMO {
|
2018-08-29 01:18:58 +00:00
|
|
|
|
2020-03-02 00:40:32 +00:00
|
|
|
var displayOrUserName: String {
|
2020-01-05 04:13:23 +00:00
|
|
|
if displayName.isEmpty {
|
|
|
|
return username
|
2018-08-29 01:18:58 +00:00
|
|
|
} else {
|
|
|
|
return displayName
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-02 00:40:32 +00:00
|
|
|
var displayNameWithoutCustomEmoji: String {
|
2022-12-07 03:26:08 +00:00
|
|
|
let stripped = stripCustomEmoji(from: displayName)
|
|
|
|
if stripped.isEmpty {
|
2020-03-02 00:40:32 +00:00
|
|
|
return username
|
|
|
|
} else {
|
2022-12-07 03:26:08 +00:00
|
|
|
return stripped
|
2020-03-02 00:40:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 03:26:08 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
extension Account {
|
|
|
|
var displayNameWithoutCustomEmoji: String {
|
|
|
|
let stripped = stripCustomEmoji(from: displayName)
|
|
|
|
if stripped.isEmpty {
|
|
|
|
return username
|
|
|
|
} else {
|
|
|
|
return stripped
|
|
|
|
}
|
2018-08-29 01:18:58 +00:00
|
|
|
}
|
2022-12-07 03:26:08 +00:00
|
|
|
}
|
2018-08-29 01:18:58 +00:00
|
|
|
|
2022-12-07 03:26:08 +00:00
|
|
|
private let customEmojiRegex = try! NSRegularExpression(pattern: ":[a-zA-Z0-9_]+:", options: [])
|
|
|
|
|
|
|
|
private func stripCustomEmoji(from string: String) -> String {
|
|
|
|
let range = NSRange(location: 0, length: string.utf16.count)
|
|
|
|
return customEmojiRegex.stringByReplacingMatches(in: string, options: [], range: range, withTemplate: "")
|
2018-08-29 01:18:58 +00:00
|
|
|
}
|