Class: FeedSubscription

Inherits:
ApplicationRecord show all
Defined in:
app/models/feed_subscription.rb

Overview

Feed subscription model. Each instance of this class represents a subscription from a single user to a single feed.

Each subscription belongs to a single user, and each user can have many subscriptions (one-to-may relationship).

Also, each subscription belongs to a single feed, and each feed can be subscribed to many times (one-to-many relationship).

A given feed can be subscribed at most once by a given user.

The model fields are:

  • user_id: integer. Mandatory. ID of the user who is subscribed to the feed.

  • feed_id: integer. Mandatory. ID of the feed to which the user is subscribed

  • unread_entries: integer. Mandatory. Number of entries in the feed the user has not read yet.

When a user subscribes to a feed, initially all entries are unread, contributing to the unread_entries attribute. As entries change state for the user, the attribute decreases (when entries become read) or increases (when entries become unread).

Instance Method Summary collapse

Instance Method Details

#touch_subscriptionsObject

Update the date in which subscriptions have been changed:

  • touch this FeedSubscription instance, updating its updated_at attribute

  • update the subscriptions_updated_at attribute of the associated user to the current date/time

  • update the subscriptions_updated_at attribute of the folder which contains the feed, if any, to the

current date/time


43
44
45
46
47
48
49
50
51
# File 'app/models/feed_subscription.rb', line 43

def touch_subscriptions
  Rails.logger.info "Touching subscription of user #{user_id} to feed #{feed_id}"
  self.touch if !destroyed?
  if user.present?
    user.update subscriptions_updated_at: Time.zone.now
    folder = feed.user_folder user
    folder.update subscriptions_updated_at: Time.zone.now if folder.present?
  end
end