示例#1
0
 public static void SendNotifications(BaseController controller, Message message, SiteConfiguration config, ITopicsSubscriptionsService service)
 {
     if (!config.Notifications.Subscription.IsDefined)
     {
         return;
     }
     var threadUrl = controller.Domain;
     threadUrl += controller.Url.RouteUrl(new
     {
         controller = "Topics",
         action = "ShortUrl",
         id = message.Topic.Id
     });
     threadUrl += "#msg" + message.Id;
     //Build a generic url that can be replaced with the real values
     var unsubscribeUrl = controller.Domain + controller.Url.RouteUrl(new
     {
         controller = "TopicsSubscriptions",
         action = "Unsubscribe",
         uid = Int32.MaxValue,
         tid = message.Topic.Id,
         guid = Int64.MaxValue.ToString()
     });
     unsubscribeUrl = unsubscribeUrl.Replace(Int32.MaxValue.ToString(), "{0}");
     unsubscribeUrl = unsubscribeUrl.Replace(Int64.MaxValue.ToString(), "{1}");
     service.SendNotifications(message, controller.User.Id, threadUrl, unsubscribeUrl);
 }
示例#2
0
 /// <summary>
 /// Determines if a user is subscribed to a topic
 /// </summary>
 /// <param name="topicId"></param>
 /// <param name="userId"></param>
 /// <param name="config"></param>
 public static bool IsUserSubscribed(int topicId, int userId, SiteConfiguration config, ITopicsSubscriptionsService service)
 {
     if (!config.Notifications.Subscription.IsDefined)
     {
         return false;
     }
     var usersSubscribed = service.GetSubscribed(topicId);
     return usersSubscribed.Any(x => x.Id == userId);
 }
示例#3
0
 /// <summary>
 /// Ensure that an email is set if the user wants notifications.
 /// </summary>
 /// <param name="email"></param>
 /// <param name="session"></param>
 /// <exception cref="ValidationException"></exception>
 public static void SetNotificationEmail(bool notify, string email, SessionWrapper session, SiteConfiguration config, IUsersService service)
 {
     if (notify && config.Notifications.Subscription.IsDefined)
     {
         if (session.User.Email == null)
         {
             service.AddEmail(session.User.Id, email, EmailPolicy.SendFromSubscriptions);
             session.User.Email = email;
         }
     }
 }
示例#4
0
 /// <summary>
 /// Subscribes or unsubscribes a user to a topic
 /// </summary>
 public static void Manage(bool subscribe, int topicId, int userId, Guid userGuid, SiteConfiguration config, ITopicsSubscriptionsService service)
 {
     if (!config.Notifications.Subscription.IsDefined)
     {
         return;
     }
     if (subscribe)
     {
         service.Add(topicId, userId);
     }
     else
     {
         service.Remove(topicId, userId, userGuid);
     }
 }
 public SiteConfiguration LoadSettings(SiteConfiguration config)
 {
     LoadElement(config.General, "general");
     LoadElement(config.UI, "ui");
     return config;
 }