Skip to content

Commit

Permalink
Merge pull request discourse#904 from janjiss/master
Browse files Browse the repository at this point in the history
Removed code duplication on UserAction model
  • Loading branch information
SamSaffron committed May 26, 2013
2 parents 9c9e5e9 + f58bcf7 commit 6046d33
Showing 1 changed file with 17 additions and 30 deletions.
47 changes: 17 additions & 30 deletions app/models/user_action.rb
Original file line number Diff line number Diff line change
Expand Up @@ -114,21 +114,7 @@ def self.stream(opts={})
builder.limit(limit.to_i)
data = builder.exec.to_a
end

data.each do |row|
row["action_type"] = row["action_type"].to_i
row["created_at"] = DateTime.parse(row["created_at"])
# we should probably cache the excerpts in the db at some point
row["excerpt"] = PrettyText.excerpt(row["cooked"],300) if row["cooked"]
row["cooked"] = nil
row["avatar_template"] = User.avatar_template(row["email"])
row["acting_avatar_template"] = User.avatar_template(row["acting_email"])
row.delete("email")
row.delete("acting_email")
row["slug"] = Slug.for(row["title"])
end

data
normalize_builder_data(data)
end

# slightly different to standard stream, it collapses replies
Expand Down Expand Up @@ -164,21 +150,7 @@ def self.private_message_stream(action_type, opts)

data = builder.exec(user_id: user_id, action_type: action_type).to_a

data.each do |row|
row["action_type"] = row["action_type"].to_i
row["created_at"] = DateTime.parse(row["created_at"])
# we should probably cache the excerpts in the db at some point
row["excerpt"] = PrettyText.excerpt(row["cooked"],300) if row["cooked"]
row["cooked"] = nil
row["avatar_template"] = User.avatar_template(row["email"])
row["acting_avatar_template"] = User.avatar_template(row["acting_email"])
row.delete("email")
row.delete("acting_email")
row["slug"] = Slug.for(row["title"])
end

data

normalize_builder_data(data)
end

def self.log_action!(hash)
Expand Down Expand Up @@ -237,6 +209,21 @@ def self.remove_action!(hash)
end

protected

def self.normalize_builder_data(data)
data.each do |row|
row["action_type"] = row["action_type"].to_i
row["created_at"] = DateTime.parse(row["created_at"])
# we should probably cache the excerpts in the db at some point
row["excerpt"] = PrettyText.excerpt(row["cooked"],300) if row["cooked"]
row["cooked"] = nil
row["avatar_template"] = User.avatar_template(row["email"])
row["acting_avatar_template"] = User.avatar_template(row["acting_email"])
row.delete("email")
row.delete("acting_email")
row["slug"] = Slug.for(row["title"])
end
end

def self.apply_common_filters(builder,user_id,guardian,ignore_private_messages=false)

Expand Down

0 comments on commit 6046d33

Please sign in to comment.