add extra username for patrons

pull/218/head
Aevann 2023-11-25 23:57:15 +02:00
parent 630f0a4891
commit d7350e73cf
10 changed files with 28 additions and 1 deletions

View File

@ -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);
}

View File

@ -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

View File

@ -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)

View File

@ -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:

View File

@ -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

View File

@ -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())

View File

@ -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():

View File

@ -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

View File

@ -33,6 +33,10 @@
{% if can_see(v, u) and u.username != u.original_username %}
{% set ns.og_usernames = 'Original Usernames:<br>@' ~ u.original_username %}
{% if u.extra_username and u.extra_username != u.original_username %}
{% set ns.og_usernames = ns.og_usernames + '<br>@' ~ u.extra_username %}
{% endif %}
{% if u.prelock_username and u.prelock_username != u.original_username %}
{% set ns.og_usernames = ns.og_usernames + '<br>@' ~ u.prelock_username %}
{% endif %}

View File

@ -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);