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