/// <summary> /// (Thread safe) Remove a pending notification for the given user/room. Harmless if user/room aren't in pending list /// </summary> /// <param name="userId"></param> /// <param name="roomId"></param> /// <param name="timeStamp">when did the event occur that is causing this remove</param> /// <param name="logIt">whether or not to generate a log entry</param> public void RemovePendingNotification(int userId, int roomId, DateTime timeStamp, bool logIt) { lock (this.pendingNotifications) { PendingNotify pn = pendingNotifications.FirstOrDefault(p => p.Reference.TargetUser.Id == userId && p.Reference.Room.Id == roomId); if (pn != null) { if (logIt) { Utils.TraceVerboseMessage(string.Format("Remove Pending Notification: User: {0}, Room: {1}, Event: {2}", pn.Reference.TargetUser.NickName, pn.Reference.Room.Name, timeStamp)); } pendingNotifications.Remove(pn); } } }
/// <summary> /// (Thread safe) Adds a "pending notification" for the given "user reference", set to trigger at the specified time. /// If there's already a pending notification for this user/room then nothing happens /// </summary> /// <param name="reference"></param> /// <param name="triggerTime"></param> public void AddPendingNotification(UserReference reference, DateTime triggerTime) { lock (this.pendingNotifications) { PendingNotify pending = pendingNotifications.FirstOrDefault(pn => pn.Reference.TargetUser.Id == reference.TargetUser.Id && pn.Reference.Room.Id == reference.Room.Id); if (pending != null) { // already a pending notification for this user/room. Compare 'Trigger Times' to determine what to do. if (triggerTime < pending.TriggerTime) { // move up the trigger time pending.TriggerTime = triggerTime; } return; } Utils.TraceVerboseMessage(string.Format("Add Pending Notification: User: {0}, Room: {1}, triggerAt: {2}", reference.TargetUser.NickName, reference.Room.Name, triggerTime.ToString())); PendingNotify notifier = new PendingNotify(reference, triggerTime); pendingNotifications.Add(notifier); } }