Closed happtim closed 1 day ago
I am traveling with my family and will test it when I return to Japan. Thanks for following Dignite Abp.
Have a pleasant journey.
There are two main modifications.
In the initialization of the file WebAssembly.Toolbar
protected override async Task OnInitializedAsync()
{
var baseUrl = Configuration.GetValue<string>("RemoteServices:NotificationCenter:BaseUrl");
if (baseUrl.IsNullOrEmpty())
{
baseUrl = Configuration.GetValue<string>("RemoteServices:Default:BaseUrl");
}
LocalizationResource = typeof(NotificationCenterResource);
if (CurrentUser.IsAuthenticated)
{
(await AccessTokenProvider.RequestAccessToken()).TryGetToken(out var accessToken);
hubConnection = new HubConnectionBuilder()
.WithUrl(baseUrl.EnsureEndsWith('/') + "signalr-hubs/notifications", options =>
{
options.AccessTokenProvider = () => Task.FromResult((string?)accessToken!.Value);
})
.Build();
notificationCount = await NotificationAppService.GetCountAsync(UserNotificationState.Unread);
hubConnection.On<RealTimeNotifyEto>("ReceiveNotifications", async (eto) =>
{
notificationCount++;
hasNewNotifications = true;
await InvokeAsync(StateHasChanged);
});
await hubConnection.StartAsync();
}
await base.OnInitializedAsync();
}
and in the ConfigureService of the file DigniteAbpNotificationCenterHttpApiClientModule in http.api.client project
Configure<AbpSystemTextJsonSerializerOptions>(options =>
{
options.JsonSerializerOptions.Converters.Add(new NotificationDataConverter());
});
the NotificationDataConverter class
public class NotificationDataConverter : JsonConverter<NotificationData>
{
public override NotificationData Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
{
using (JsonDocument doc = JsonDocument.ParseValue(ref reader))
{
JsonElement root = doc.RootElement;
if (root.TryGetProperty("type", out JsonElement typeElement))
{
string type = typeElement.GetString();
switch (type)
{
case "Dignite.Abp.Notifications.MessageNotificationData":
return JsonSerializer.Deserialize<MessageNotificationData>(root.GetRawText(), options);
// 如果有其他类型,可以在这里添加更多 case
default:
throw new JsonException($"Unknown notification data type: {type}");
}
}
throw new JsonException("Type property not found in notification data");
}
}
public override void Write(Utf8JsonWriter writer, NotificationData value, JsonSerializerOptions options)
{
JsonSerializer.Serialize(writer, value, value.GetType(), options);
}
}
If you have fixed the relevant BUG, please submit it to the project and I will merge your code.
The code has just been merged, thank you very much for your contribution!
I use Blazor WebAssembly for my UI interface. I attempted to reference Dignite.Abp.NotificationCenter.Blazor.WebAssembly and encountered some issues, which I then tried to fix.