Class: SimpleForum::UserActivity::Checker

Inherits:
Object
  • Object
show all
Defined in:
app/models/simple_forum/user_activity.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, hash) ⇒ Checker

Returns a new instance of Checker.



7
8
9
10
# File 'app/models/simple_forum/user_activity.rb', line 7

def initialize(user, hash)
  @user = user
  @hash = hash
end

Instance Attribute Details

#hashObject (readonly)

Returns the value of attribute hash.



5
6
7
# File 'app/models/simple_forum/user_activity.rb', line 5

def hash
  @hash
end

#userObject (readonly)

Returns the value of attribute user.



5
6
7
# File 'app/models/simple_forum/user_activity.rb', line 5

def user
  @user
end

Instance Method Details

#bang(object) ⇒ Object



28
29
30
31
# File 'app/models/simple_forum/user_activity.rb', line 28

def bang(object)
  return unless user
  UserActivity.bang(object, user)
end

#recent_activity?(object) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'app/models/simple_forum/user_activity.rb', line 12

def recent_activity?(object)
  type = object.class.base_class.name.to_sym
  hash[type] ||= {}
  read_at = hash[type][object.id]
  return unless read_at

  if object.is_a?(SimpleForum::Forum)
    recent_post = object.recent_post
    recent_post && recent_post.created_at > read_at
  elsif object.is_a?(SimpleForum::Topic)
    object.last_updated_at && object.last_updated_at > read_at
  elsif object.respond_to?(:updated_at)
    object.updated_at > self[object]
  end
end