🐛 Bug fixes in the Sphere still referencing the old realm db
This commit is contained in:
@@ -75,6 +75,18 @@ public class RealmServiceGrpc(
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<GetPublicRealmsResponse> SearchRealms(SearchRealmsRequest request, ServerCallContext context)
|
||||
{
|
||||
var realms = await db.Realms
|
||||
.Where(r => r.IsPublic)
|
||||
.Where(r => EF.Functions.Like(r.Slug, $"{request.Query}%") || EF.Functions.Like(r.Name, $"{request.Query}%"))
|
||||
.Take(request.Limit)
|
||||
.ToListAsync();
|
||||
var response = new GetPublicRealmsResponse();
|
||||
response.Realms.AddRange(realms.Select(r => r.ToProtoValue()));
|
||||
return response;
|
||||
}
|
||||
|
||||
public override async Task<Empty> SendInviteNotify(SendInviteNotifyRequest request, ServerCallContext context)
|
||||
{
|
||||
var member = request.Member;
|
||||
|
@@ -39,7 +39,8 @@ public class SnRealm : ModelBase, IIdentifiedResource
|
||||
return new Realm
|
||||
{
|
||||
Id = Id.ToString(),
|
||||
Name = Name
|
||||
Name = Name,
|
||||
Slug = Slug
|
||||
};
|
||||
}
|
||||
|
||||
@@ -49,7 +50,7 @@ public class SnRealm : ModelBase, IIdentifiedResource
|
||||
{
|
||||
Id = Guid.Parse(proto.Id),
|
||||
Name = proto.Name,
|
||||
Slug = "", // Required but not in proto
|
||||
Slug = proto.Slug,
|
||||
Description = "",
|
||||
IsCommunity = false,
|
||||
IsPublic = false
|
||||
|
@@ -15,6 +15,7 @@ import 'account.proto';
|
||||
message Realm {
|
||||
string id = 1;
|
||||
string name = 2;
|
||||
string slug = 3;
|
||||
}
|
||||
|
||||
message RealmMember {
|
||||
@@ -38,6 +39,8 @@ service RealmService {
|
||||
rpc GetUserRealms(GetUserRealmsRequest) returns (GetUserRealmsResponse) {}
|
||||
// Get public realms
|
||||
rpc GetPublicRealms(google.protobuf.Empty) returns (GetPublicRealmsResponse) {}
|
||||
// Search public realms
|
||||
rpc SearchRealms(SearchRealmsRequest) returns (GetPublicRealmsResponse) {}
|
||||
// Send invitation notification
|
||||
rpc SendInviteNotify(SendInviteNotifyRequest) returns (google.protobuf.Empty) {}
|
||||
// Check if member has required role
|
||||
@@ -77,6 +80,11 @@ message GetPublicRealmsResponse {
|
||||
repeated Realm realms = 1;
|
||||
}
|
||||
|
||||
message SearchRealmsRequest {
|
||||
string query = 1;
|
||||
int32 limit = 2;
|
||||
}
|
||||
|
||||
message SendInviteNotifyRequest {
|
||||
RealmMember member = 1;
|
||||
}
|
||||
|
@@ -33,6 +33,13 @@ public class RemoteRealmService(RealmService.RealmServiceClient realms)
|
||||
return response.Realms.Select(SnRealm.FromProtoValue).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<SnRealm>> SearchRealms(string query, int limit)
|
||||
{
|
||||
var request = new SearchRealmsRequest { Query = query, Limit = limit };
|
||||
var response = await realms.SearchRealmsAsync(request);
|
||||
return response.Realms.Select(SnRealm.FromProtoValue).ToList();
|
||||
}
|
||||
|
||||
public async Task<List<SnRealm>> GetRealmBatch(List<string> ids)
|
||||
{
|
||||
var request = new GetRealmBatchRequest();
|
||||
|
@@ -4,7 +4,7 @@ using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace DysonNetwork.Sphere.Autocompletion;
|
||||
|
||||
public class AutocompletionService(AppDatabase db, RemoteAccountService remoteAccountsHelper)
|
||||
public class AutocompletionService(AppDatabase db, RemoteAccountService remoteAccountsHelper, RemoteRealmService remoteRealmService)
|
||||
{
|
||||
public async Task<List<DysonNetwork.Shared.Models.Autocompletion>> GetAutocompletion(string content, Guid? chatId = null, Guid? realmId = null, int limit = 10)
|
||||
{
|
||||
@@ -95,17 +95,14 @@ public class AutocompletionService(AppDatabase db, RemoteAccountService remoteAc
|
||||
break;
|
||||
|
||||
case "r":
|
||||
var realms = await db.Realms
|
||||
.Where(r => EF.Functions.Like(r.Slug, $"{query}%") || EF.Functions.Like(r.Name, $"{query}%"))
|
||||
.Take(limit)
|
||||
.Select(r => new DysonNetwork.Shared.Models.Autocompletion
|
||||
{
|
||||
Type = "realm",
|
||||
Keyword = "@r/" + r.Slug,
|
||||
Data = r
|
||||
})
|
||||
.ToListAsync();
|
||||
results.AddRange(realms);
|
||||
var realms = await remoteRealmService.SearchRealms(query, limit);
|
||||
var autocompletions = realms.Select(r => new DysonNetwork.Shared.Models.Autocompletion
|
||||
{
|
||||
Type = "realm",
|
||||
Keyword = "@r/" + r.Slug,
|
||||
Data = r
|
||||
});
|
||||
results.AddRange(autocompletions);
|
||||
break;
|
||||
|
||||
case "c":
|
||||
|
@@ -2,6 +2,7 @@ using System.ComponentModel.DataAnnotations;
|
||||
using DysonNetwork.Shared.Auth;
|
||||
using DysonNetwork.Shared.Models;
|
||||
using DysonNetwork.Shared.Proto;
|
||||
using DysonNetwork.Shared.Registry;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
@@ -17,7 +18,8 @@ public class PublisherController(
|
||||
AccountService.AccountServiceClient accounts,
|
||||
FileService.FileServiceClient files,
|
||||
FileReferenceService.FileReferenceServiceClient fileRefs,
|
||||
ActionLogService.ActionLogServiceClient als
|
||||
ActionLogService.ActionLogServiceClient als,
|
||||
RemoteRealmService remoteRealmService
|
||||
)
|
||||
: ControllerBase
|
||||
{
|
||||
@@ -352,7 +354,7 @@ public class PublisherController(
|
||||
return BadRequest("Name and Nick are required.");
|
||||
if (HttpContext.Items["CurrentUser"] is not Account currentUser) return Unauthorized();
|
||||
|
||||
var realm = await db.Realms.FirstOrDefaultAsync(r => r.Slug == realmSlug);
|
||||
var realm = await remoteRealmService.GetRealmBySlug(realmSlug);
|
||||
if (realm == null) return NotFound("Realm not found");
|
||||
|
||||
var accountId = Guid.Parse(currentUser.Id);
|
||||
|
Reference in New Issue
Block a user