掲示板実装
This commit is contained in:
21
app/models/board_membership.rb
Normal file
21
app/models/board_membership.rb
Normal file
@@ -0,0 +1,21 @@
|
||||
class BoardMembership < ApplicationRecord
|
||||
belongs_to :board
|
||||
belongs_to :participant
|
||||
|
||||
# 参加中かどうか(退出していない)
|
||||
def active?
|
||||
left_at.nil?
|
||||
end
|
||||
|
||||
# 退出処理
|
||||
def leave!
|
||||
update!(left_at: Time.current)
|
||||
end
|
||||
|
||||
# 既読位置を更新
|
||||
def mark_read!(post_id)
|
||||
# 既存の既読位置より新しい場合のみ更新(巻き戻り防止)
|
||||
# ただし今回は単純に最新をセットする形で良い
|
||||
update!(last_read_post_id: post_id)
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user