public PartialViewResult UnreadAlerts() { string userId = null; if (User != null) { userId = User.Identity.GetUserId(); } var vm = new UnreadModel(); if (userId != null) { using (var db = new ZapContext()) { var user = db.Users .Include("Alerts") //.Include("Messages") //.Include("Alerts.PostLink") //.Include("Messages.PostLink") .Where(u => u.AppId == userId).First(); var messages = user.Alerts.Where(m => !m.IsRead && !m.IsDeleted).OrderByDescending(m => m.TimeStamp); vm.NumUnread = messages.Count(); } } return(PartialView("_UnreadMessages", model: vm)); }
private void SendToastNotification(UnreadModel newValue, UnreadModel oldValue) { if (newValue.Follower != 0 && newValue.Follower != oldValue?.Follower) { ToastNotificationSender.SendText(Localization.Format("FollowerCount", newValue.Follower)); } if (newValue.MentionStatus != 0 && newValue.MentionStatus != oldValue?.MentionStatus) { ToastNotificationSender.SendText(Localization.Format("MentionStatusCount", newValue.MentionStatus)); } if (newValue.MentionCmt != 0 && newValue.MentionCmt != oldValue?.MentionCmt) { ToastNotificationSender.SendText(Localization.Format("MentionCmtCount", newValue.MentionCmt)); } if (newValue.Cmt != 0 && newValue.Cmt != oldValue?.Cmt) { ToastNotificationSender.SendText(Localization.Format("CmtCount", newValue.Cmt)); } if (newValue.Dm != 0 && newValue.Dm != oldValue?.Dm) { ToastNotificationSender.SendText(Localization.Format("DmCount", newValue.Dm)); } }
public async Task <PartialViewResult> UnreadAlerts() { XFrameOptionsDeny(); Response.AddHeader("X-Frame-Options", "DENY"); string userId = null; if (User != null) { userId = User.Identity.GetUserId(); } var vm = new UnreadModel(); if (userId != null) { using (var db = new ZapContext()) { var numUnread = await db.Users .Include("Alerts") .Where(u => u.AppId == userId) .SelectMany(u => u.Alerts) .Where(m => !m.IsRead && !m.IsDeleted) .CountAsync(); vm.NumUnread = numUnread; } } return(PartialView("_UnreadMessages", model: vm)); }
private async Task FetchUnread() { Debug.WriteLine("fetching notification..."); var result = await Singleton <Api> .Instance.Unread(); await DispatcherHelper.ExecuteOnUIThreadAsync(() => { SendToastNotification(result, Unread); Unread = result; }); Debug.WriteLine("fetching complete!"); }
private void SendToastNotification(UnreadModel newValue, UnreadModel oldValue) { if (newValue.Follower != oldValue?.Follower) { if (newValue.Follower != 0) { Singleton <BroadcastCenter> .Instance.Send(this, "notification_new_fans", newValue.Follower); } Singleton <BroadcastCenter> .Instance.Send(this, "notification_changed_fans", newValue.Follower); } if (newValue.MentionStatus != oldValue?.MentionStatus) { if (newValue.MentionStatus != 0) { Singleton <BroadcastCenter> .Instance.Send(this, "notification_new_mention_at", newValue.MentionStatus); } Singleton <BroadcastCenter> .Instance.Send(this, "notification_changed_mention_at", newValue.MentionStatus); } if (newValue.MentionCmt != oldValue?.MentionCmt) { if (newValue.MentionCmt != 0) { Singleton <BroadcastCenter> .Instance.Send(this, "notification_new_mention_comment", newValue.MentionCmt); } Singleton <BroadcastCenter> .Instance.Send(this, "notification_changed_mention_comment", newValue.MentionCmt); } if (newValue.Cmt != oldValue?.Cmt) { if (newValue.Cmt != 0) { Singleton <BroadcastCenter> .Instance.Send(this, "notification_new_comment", newValue.Cmt); } Singleton <BroadcastCenter> .Instance.Send(this, "notification_changed_comment", newValue.Cmt); } if (newValue.Dm != oldValue?.Dm) { if (newValue.Dm != 0) { Singleton <BroadcastCenter> .Instance.Send(this, "notification_new_dm", newValue.Dm); } Singleton <BroadcastCenter> .Instance.Send(this, "notification_changed_dm", newValue.Dm); } }