discourse/app/models/draft.rb

55 lines
1.2 KiB
Ruby
Raw Normal View History

2013-02-05 13:16:51 -06:00
class Draft < ActiveRecord::Base
NEW_TOPIC = 'new_topic'
NEW_PRIVATE_MESSAGE = 'new_private_message'
EXISTING_TOPIC = 'topic_'
def self.set(user, key, sequence, data)
d = find_draft(user,key)
if d
return if d.sequence > sequence
d.update_columns(data: data, sequence: sequence)
2013-02-05 13:16:51 -06:00
else
Draft.create!(user_id: user.id, draft_key: key, data: data, sequence: sequence)
2013-02-05 13:16:51 -06:00
end
end
def self.get(user, key, sequence)
d = find_draft(user,key)
2013-02-07 09:45:24 -06:00
if d && d.sequence == sequence
2013-02-05 13:16:51 -06:00
d.data
end
end
def self.clear(user, key, sequence)
d = find_draft(user,key)
if d && d.sequence <= sequence
d.destroy
end
end
def self.find_draft(user, key)
if user.is_a?(User)
find_by(user_id: user.id, draft_key: key)
else
find_by(user_id: user, draft_key: key)
end
2013-02-05 13:16:51 -06:00
end
end
# == Schema Information
#
# Table name: drafts
#
# id :integer not null, primary key
# user_id :integer not null
# draft_key :string(255) not null
# data :text not null
2014-05-27 20:49:50 -05:00
# created_at :datetime
# updated_at :datetime
# sequence :integer default(0), not null
#
# Indexes
#
# index_drafts_on_user_id_and_draft_key (user_id,draft_key)
#