diff --git a/files/assets/js/emoji_modal/search_dictionary.js b/files/assets/js/emoji_modal/search_dictionary.js
index 8f44f46ec..3df61c4aa 100644
--- a/files/assets/js/emoji_modal/search_dictionary.js
+++ b/files/assets/js/emoji_modal/search_dictionary.js
@@ -78,6 +78,8 @@ function makeEmojisSearchDictionary() {
emojisSearchDictionary.updateTag(`@${emoji.author_username.toLowerCase()}`, emoji.name);
if (emoji.author_original_username != emoji.author_username)
emojisSearchDictionary.updateTag(`@${emoji.author_original_username.toLowerCase()}`, emoji.name);
+ if (emoji.author_extra_username !== undefined)
+ emojisSearchDictionary.updateTag(`@${emoji.author_extra_username.toLowerCase()}`, emoji.name);
if (emoji.author_prelock_username !== undefined)
emojisSearchDictionary.updateTag(`@${emoji.author_prelock_username.toLowerCase()}`, emoji.name);
}
diff --git a/files/classes/emoji.py b/files/classes/emoji.py
index a34d773df..1b43d5719 100644
--- a/files/classes/emoji.py
+++ b/files/classes/emoji.py
@@ -41,6 +41,8 @@ class Emoji(Base):
data["author_username"] = self.author_username
if "author_original_username" in self.__dict__ and self.author_original_username:
data["author_original_username"] = self.author_original_username
+ if "author_extra_username" in self.__dict__ and self.author_extra_username:
+ data["author_extra_username"] = self.author_extra_username
if "author_prelock_username" in self.__dict__ and self.author_prelock_username:
data["author_prelock_username"] = self.author_prelock_username
return data
diff --git a/files/classes/user.py b/files/classes/user.py
index 0e7d7672f..209dbe93b 100644
--- a/files/classes/user.py
+++ b/files/classes/user.py
@@ -134,6 +134,7 @@ class User(Base):
defaulttime = Column(String, default=DEFAULT_TIME_FILTER)
custom_filter_list = Column(String)
original_username = Column(String)
+ extra_username = Column(String)
prelock_username = Column(String)
referred_by = Column(Integer, ForeignKey("users.id"))
currently_held_lottery_tickets = Column(Integer, default=0)
@@ -979,6 +980,8 @@ class User(Base):
if self.username == self.original_username:
return ''
names = {self.original_username}
+ if self.extra_username:
+ names.add(self.extra_username)
if self.prelock_username:
names.add(self.prelock_username)
return 'Original Usernames: @' + ', @'.join(names)
diff --git a/files/helpers/get.py b/files/helpers/get.py
index 0436b9bf4..5cf9c9f86 100644
--- a/files/helpers/get.py
+++ b/files/helpers/get.py
@@ -32,6 +32,7 @@ def get_user(username, v=None, graceful=False, include_blocks=False, attributes=
or_(
User.username.ilike(search_name),
User.original_username.ilike(search_name),
+ User.extra_username.ilike(search_name),
User.prelock_username.ilike(search_name),
)
)
@@ -65,8 +66,9 @@ def get_users(usernames, ids_only=False, graceful=False):
or_(
User.username.ilike(any_(usernames)),
User.original_username.ilike(any_(usernames)),
+ User.extra_username.ilike(any_(usernames)),
User.prelock_username.ilike(any_(usernames)),
- )
+ )
).all()
if len(users) != len(usernames) and not graceful:
diff --git a/files/helpers/sanitize.py b/files/helpers/sanitize.py
index d08382a4e..53ab2183b 100644
--- a/files/helpers/sanitize.py
+++ b/files/helpers/sanitize.py
@@ -423,6 +423,8 @@ def sanitize(sanitized, golden=True, limit_pings=0, showmore=False, count_emojis
users_dict[u.username.lower()] = u
if u.original_username:
users_dict[u.original_username.lower()] = u
+ if u.extra_username:
+ users_dict[u.extra_username.lower()] = u
if u.prelock_username:
users_dict[u.prelock_username.lower()] = u
diff --git a/files/routes/search.py b/files/routes/search.py
index cf9ba655c..91011dc02 100644
--- a/files/routes/search.py
+++ b/files/routes/search.py
@@ -418,6 +418,7 @@ def searchusers(v):
or_(
User.username.ilike(f'%{term}%'),
User.original_username.ilike(f'%{term}%'),
+ User.extra_username.ilike(f'%{term}%'),
User.prelock_username.ilike(f'%{term}%'),
)
).order_by(User.username.ilike(term).desc(), User.stored_subscriber_count.desc())
diff --git a/files/routes/settings.py b/files/routes/settings.py
index e6f11c321..5753ce67a 100644
--- a/files/routes/settings.py
+++ b/files/routes/settings.py
@@ -574,6 +574,7 @@ def settings_images_profile(v):
cache.delete_memoized(get_profile_picture, v.id)
cache.delete_memoized(get_profile_picture, v.username)
cache.delete_memoized(get_profile_picture, v.original_username)
+ cache.delete_memoized(get_profile_picture, v.extra_username)
cache.delete_memoized(get_profile_picture, v.prelock_username)
return redirect("/settings/personal?msg=Profile picture successfully updated!")
@@ -768,6 +769,9 @@ def settings_name_change(v):
if existing and existing.id != v.id:
abort(400, f"Username `{new_name}` is already in use.")
+ if v.patron:
+ v.extra_username = v.username
+
v.username = new_name
if new_name.lower() == v.original_username.lower():
diff --git a/files/routes/static.py b/files/routes/static.py
index 92a7caadd..883ffe43d 100644
--- a/files/routes/static.py
+++ b/files/routes/static.py
@@ -90,6 +90,7 @@ def get_emojis(nsfw):
User.id,
User.username,
User.original_username,
+ User.extra_username,
User.prelock_username,
)).filter(Emoji.submitter_id == None)
@@ -110,6 +111,7 @@ def get_emojis(nsfw):
else:
emoji.author_username = author.username
emoji.author_original_username = author.original_username
+ emoji.author_extra_username = author.extra_username
emoji.author_prelock_username = author.prelock_username
collected.append(emoji.json())
return collected
diff --git a/files/templates/userpage/banner.html b/files/templates/userpage/banner.html
index 24b38cd49..f9323ac30 100644
--- a/files/templates/userpage/banner.html
+++ b/files/templates/userpage/banner.html
@@ -33,6 +33,10 @@
{% if can_see(v, u) and u.username != u.original_username %}
{% set ns.og_usernames = 'Original Usernames:
@' ~ u.original_username %}
+ {% if u.extra_username and u.extra_username != u.original_username %}
+ {% set ns.og_usernames = ns.og_usernames + '
@' ~ u.extra_username %}
+ {% endif %}
+
{% if u.prelock_username and u.prelock_username != u.original_username %}
{% set ns.og_usernames = ns.og_usernames + '
@' ~ u.prelock_username %}
{% endif %}
diff --git a/migrations/20231125-add-extra-username-for-patrons.sql b/migrations/20231125-add-extra-username-for-patrons.sql
new file mode 100644
index 000000000..36b55f4c5
--- /dev/null
+++ b/migrations/20231125-add-extra-username-for-patrons.sql
@@ -0,0 +1,5 @@
+alter table users add column extra_username character varying(30) unique;
+
+CREATE UNIQUE INDEX lowercase_extra_username ON public.users USING btree (lower((extra_username)::text));
+
+CREATE INDEX users_extra_username_trgm_idx ON public.users USING gin (extra_username public.gin_trgm_ops);