More notification updates

This commit is contained in:
Michael 2017-05-18 16:18:25 -04:00
parent 0571a9c8d9
commit 1d8b307bb5
4 changed files with 49 additions and 5 deletions

View file

@ -111,6 +111,17 @@ private set
}
}
public ActionResult Notification(string id, string url)
{
var db = new ApplicationDbContext();
var note = db.Notifications.FirstOrDefault(x => x.Id == id);
if (note == null)
return new HttpStatusCodeResult(404);
note.IsRead = false;
db.SaveChanges();
return Redirect(url);
}
public ApplicationUserManager UserManager
{
get
@ -157,6 +168,7 @@ public ActionResult Index(ApplicationUser model)
usr.ShowFollowers = model.ShowFollowers;
usr.ShowFollowed = model.ShowFollowed;
usr.ShowEmail = model.ShowEmail;
usr.EmailOnNotifications = model.EmailOnNotifications;
usr.ShowPostAndTopicCounts = model.ShowPostAndTopicCounts;
usr.ShowJoinDate = model.ShowJoinDate;
if (usr.Email != model.Email)
@ -510,7 +522,7 @@ protected override void Dispose(bool disposing)
base.Dispose(disposing);
}
#region Helpers
#region Helpers
// Used for XSRF protection when adding external logins
private const string XsrfKey = "XsrfId";

View file

@ -52,7 +52,7 @@ public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<Applicat
public bool ShowEmail { get; set; }
public bool ShowPostAndTopicCounts { get; set; }
public bool ShowJoinDate { get; set; }
public bool EmailOnNotifications { get; set; }
#endregion

View file

@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Web;
using Microsoft.AspNet.Identity.Owin;
using Microsoft.AspNet.SignalR;
using Project_Unite.Models;
@ -70,18 +71,40 @@ public static void NotifyUser(string uid, string target, string title, string de
var user = db.Users.FirstOrDefault(x => x.Id == uid);
if (user == null)
throw new Exception("Cannot find user with ID " + target + ".");
string id = Guid.NewGuid().ToString();
var note = new Notification
{
Id = Guid.NewGuid().ToString(),
Id = id,
UserId = target,
Title = title,
Timestamp = DateTime.Now,
ActionUrl = url,
ActionUrl = $"http://getshiftos.ml/Manage/Notification/{id}?url={Uri.EscapeDataString(url)}",
Description = desc,
AvatarUrl = user.AvatarUrl
};
db.Notifications.Add(note);
var t = db.Users.FirstOrDefault(x => x.Id == target);
if (t.EmailOnNotifications)
{
if (t.LastLogin <= DateTime.Now.AddDays(-7))
{
var man = HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>();
man.SendEmailAsync(target, "New notification", $@"<h1>New notification</h1>
<h3>{note.Title}</h3>
<img src=""{note.AvatarUrl}"" width=""128"" height=""128"" style=""border-radius:100%""/>
<h4>{user.FullName}</h4>
<h5>{user.DisplayName}</h5>
<p>{note.Description}</p>
<a href=""{note.ActionUrl}"">Click here to acknowledge this notification.</a>");
}
}
db.SaveChanges();
SendMessage(target, ComposeHtml(note));

View file

@ -30,7 +30,8 @@
<ul id="tabs" data-tabs="tabs" class="nav nav-pills nav-stacked" role="tablist">
<li class="active"><a data-toggle="tab" href="#t_profile">Profile</a></li>
<li><a data-toggle="tab" href="#t_privacy">Privacy &amp; Security</a></li>
<li><a data-toggle="tab" href="#t_data">Data</a></li>
<li><a data-toggle="tab" href="#t_notifications">Notifications</a></li>
<li><a data-toggle="tab" href="#t_data">Data</a></li>
<li><a data-toggle="tab" href="#t_api">API</a></li>
<li class="danger"><a data-toggle="tab" href="#t_danger">The Danger Zone</a></li>
</ul>
@ -86,6 +87,14 @@
@Html.TextAreaFor(Model => Model.Hobbies, new { @class = "form-control" })
</div>
<div class="tab-pane fade in" id="t_notifications">
<h2>Notifications</h2>
<p>These settings are for the ShiftOS notification system on your account.</p>
<h4>Send me notifications through email when I'm inactive</h4>
<p>Check this option to allow us to email you when you receive a notification and you haven't logged in for a week.</p> @Html.CheckBoxFor(Model=>Model.EmailOnNotifications)
</div>
<div class="tab-pane fade in" id="t_privacy">
<h2>Privacy &amp; Security</h2>