[backend/masto-client] Allow searching by user fqn (ISH-196)
This commit is contained in:
parent
7564c67371
commit
a0e83949ff
2 changed files with 27 additions and 7 deletions
|
@ -130,8 +130,8 @@ public class SearchController(
|
||||||
|
|
||||||
return await db.Users
|
return await db.Users
|
||||||
.IncludeCommonProperties()
|
.IncludeCommonProperties()
|
||||||
.Where(p => p.DisplayNameContainsCaseInsensitive(search.Query!) ||
|
.Where(p => p.DisplayNameOrUsernameOrFqnContainsCaseInsensitive(search.Query!,
|
||||||
p.UsernameContainsCaseInsensitive(search.Query!))
|
config.Value.AccountDomain))
|
||||||
.Where(p => !search.Following || p.IsFollowedBy(user))
|
.Where(p => !search.Following || p.IsFollowedBy(user))
|
||||||
.Paginate(pagination, ControllerContext) //TODO: this will mess up our sorting
|
.Paginate(pagination, ControllerContext) //TODO: this will mess up our sorting
|
||||||
.OrderByDescending(p => p.NotesCount)
|
.OrderByDescending(p => p.NotesCount)
|
||||||
|
|
|
@ -439,7 +439,7 @@ public class User : IEntity
|
||||||
|
|
||||||
[InverseProperty(nameof(SwSubscription.User))]
|
[InverseProperty(nameof(SwSubscription.User))]
|
||||||
public virtual ICollection<SwSubscription> SwSubscriptions { get; set; } = new List<SwSubscription>();
|
public virtual ICollection<SwSubscription> SwSubscriptions { get; set; } = new List<SwSubscription>();
|
||||||
|
|
||||||
[InverseProperty(nameof(PushSubscription.User))]
|
[InverseProperty(nameof(PushSubscription.User))]
|
||||||
public virtual ICollection<PushSubscription> PushSubscriptions { get; set; } = new List<PushSubscription>();
|
public virtual ICollection<PushSubscription> PushSubscriptions { get; set; } = new List<PushSubscription>();
|
||||||
|
|
||||||
|
@ -499,12 +499,32 @@ public class User : IEntity
|
||||||
[StringLength(32)]
|
[StringLength(32)]
|
||||||
public string Id { get; set; } = null!;
|
public string Id { get; set; } = null!;
|
||||||
|
|
||||||
|
[Projectable]
|
||||||
|
public string GetFqnLower(string accountDomain) => UsernameLower + "@" + (Host ?? accountDomain);
|
||||||
|
|
||||||
|
[Projectable]
|
||||||
|
public string GetFqn(string accountDomain) => Username + "@" + (Host ?? accountDomain);
|
||||||
|
|
||||||
[Projectable]
|
[Projectable]
|
||||||
public bool DisplayNameContainsCaseInsensitive(string str) =>
|
public bool DisplayNameContainsCaseInsensitive(string str) =>
|
||||||
DisplayName != null && EF.Functions.ILike(DisplayName, "%" + EfHelpers.EscapeLikeQuery(str) + "%", @"\");
|
DisplayName != null && EF.Functions.ILike(DisplayName, "%" + EfHelpers.EscapeLikeQuery(str) + "%", @"\");
|
||||||
|
|
||||||
[Projectable]
|
[Projectable]
|
||||||
public bool UsernameContainsCaseInsensitive(string str) => UsernameLower.Contains(str);
|
public bool UsernameContainsCaseInsensitive(string str) => UsernameLower.Contains(str.ToLowerInvariant());
|
||||||
|
|
||||||
|
[Projectable]
|
||||||
|
public bool FqnContainsCaseInsensitive(string str, string accountDomain) =>
|
||||||
|
GetFqnLower(accountDomain).Contains(str.ToLowerInvariant());
|
||||||
|
|
||||||
|
[Projectable]
|
||||||
|
public bool UsernameOrFqnContainsCaseInsensitive(string str, string accountDomain) =>
|
||||||
|
str.Contains('@') ? FqnContainsCaseInsensitive(str, accountDomain) : UsernameContainsCaseInsensitive(str);
|
||||||
|
|
||||||
|
[Projectable]
|
||||||
|
public bool DisplayNameOrUsernameOrFqnContainsCaseInsensitive(string str, string accountDomain) =>
|
||||||
|
str.Contains('@') && !str.Contains(' ')
|
||||||
|
? FqnContainsCaseInsensitive(str, accountDomain)
|
||||||
|
: UsernameContainsCaseInsensitive(str) || DisplayNameContainsCaseInsensitive(str);
|
||||||
|
|
||||||
[Projectable]
|
[Projectable]
|
||||||
public bool IsBlockedBy(User user) => BlockedBy.Contains(user);
|
public bool IsBlockedBy(User user) => BlockedBy.Contains(user);
|
||||||
|
@ -582,9 +602,9 @@ public class User : IEntity
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
public string GetPublicUrl(Config.InstanceSection config) => GetPublicUrl(config.WebDomain);
|
public string GetPublicUrl(Config.InstanceSection config) => GetPublicUrl(config.WebDomain);
|
||||||
public string GetPublicUri(Config.InstanceSection config) => GetPublicUri(config.WebDomain);
|
public string GetPublicUri(Config.InstanceSection config) => GetPublicUri(config.WebDomain);
|
||||||
public string GetIdenticonUrl(Config.InstanceSection config) => GetIdenticonUrl(config.WebDomain);
|
public string GetIdenticonUrl(Config.InstanceSection config) => GetIdenticonUrl(config.WebDomain);
|
||||||
public string GetIdenticonUrlPng(Config.InstanceSection config) => GetIdenticonUrl(config.WebDomain) + ".png";
|
public string GetIdenticonUrlPng(Config.InstanceSection config) => GetIdenticonUrl(config.WebDomain) + ".png";
|
||||||
|
|
||||||
public string GetPublicUri(string webDomain) => Host == null
|
public string GetPublicUri(string webDomain) => Host == null
|
||||||
|
|
Loading…
Add table
Reference in a new issue