实时通知未发送

2024-03-09

我试图在 ASP.NET Boilerplate 中显示实时通知,但未发送。

public override async Task<MessagesDto> Create(MessagesCreateDto input)
{
    var MessagesCore = ObjectMapper.Map<MessagesCore>(input);            
    MessagesCore.UserId = Convert.ToInt32(AbpSession.UserId);
    MessagesCore.CreationId = Convert.ToInt32(AbpSession.UserId);
    MessagesCore.FromUserId = Convert.ToInt32(AbpSession.UserId);
    MessagesCore.CreationTime = DateTime.Now;
    MessagesCore.LastModificationId = Convert.ToInt32(AbpSession.UserId);
    MessagesCore.LastModificationTime = DateTime.Now;

    _stateRepository.Insert(MessagesCore);
    CurrentUnitOfWork.SaveChanges();

    UserIdentifier identifier = new UserIdentifier(1,input.ToUserId);
    await _notificationSubscriptionManager.SubscribeAsync(new UserIdentifier(1, input.ToUserId), "NewMessage");
    await _notificationPublisher.PublishAsync("NewMessage", new SentMessageNotificationData("Test", "New Message"), userIds: new[] { identifier });

    return MapToEntityDto(MessagesCore);
}

SentMessage通知数据类:

[Serializable]
public class SentMessageNotificationData : NotificationData
{
    public string SenderUserName { get; set; }

    public string FriendshipMessage { get; set; }

    public SentMessageNotificationData(string senderUserName, string friendshipMessage)
    {
        SenderUserName = senderUserName;
        FriendshipMessage = friendshipMessage;
    }
}

数据存储在通知表中,但客户端不显示通知消息。

SignalR 代码在应用程序组件.ts:

ngOnInit(): void {
  if (this.appSession.application.features['SignalR']) {
    SignalRHelper.initSignalR();
  }

  abp.event.on('abp.notifications.received', userNotification => {
    abp.notifications.showUiNotifyForUserNotification(userNotification);
    if (userNotification.notification.data.type === 'Abp.Notifications.LocalizableMessageNotificationData') {
        var localizedText = abp.localization.localize(
            userNotification.notification.data.message.name,
            userNotification.notification.data.message.sourceName
        );

        $.each(userNotification.notification.data.properties, function (key, value) {
            localizedText = localizedText.replace('{' + key + '}', value);
        });

        alert('New localized notification: ' + localizedText);
    } else if (userNotification.notification.data.type === 'Abp.Notifications.MessageNotificationData') {
        alert('New simple notification: ' + userNotification.notification.data.message);
    }
    //Desktop notification
    Push.create("AbpZeroTemplate", {
      body: userNotification.notification.data.message,
      icon: abp.appPath + 'assets/app-logo-small.png',
      timeout: 6000,
      onClick: function () {
        window.focus();
        this.close();
      }
    });
  });
}

我在netcoreapp2.0

  • SignalR 仍然开启1.0.0-alpha2-final对于.NET Core。
  • 2.x仅在 2018 年第一季度/第二季度保持稳定。

Update 1

Abp.AspNetCore.SignalR http://www.nuget.org/packages/Abp.AspNetCore.SignalRNuGet 包已发布。

阅读文档SignalR AspNetCore 集成 https://aspnetboilerplate.com/Pages/Documents/SignalR-AspNetCore-Integration.

You can try https://github.com/acjh/module-zero-core-template/blob/signalr-try/signalr-try.md it and make the necessary changes https://github.com/aspnetboilerplate/module-zero-core-template/compare/126dec8...a813437 to your files. Or just wait for it to be released.

Update 2

你现在可以download https://aspnetboilerplate.com/Templates v3.4.1带有 AspNetCore.SignalR 预览的模板。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

实时通知未发送 的相关文章

随机推荐