Sha256: 2cae27444993c4a3b1ea3898db01bf22230203caa760c090f97aa2c2fa6c0680

Contents?: true

Size: 1.05 KB

Versions: 20

Compression:

Stored size: 1.05 KB

Contents

class Message < ApplicationRecord

  belongs_to :assignment, foreign_key: :submission_id, primary_key: :submission_id, optional: true
  has_one :exercise, through: :assignment

  validates_presence_of :submission_id, :content, :sender

  markdown_on :content

  def notify!
    Mumukit::Nuntius.notify! 'student-messages', as_platform_json
  end

  def as_platform_json
    as_json(except: [:id, :type],
            include: {exercise: {only: [:bibliotheca_id]}})
      .merge(organization: Organization.current.name)
  end

  def read!
    update! read: true
  end

  def self.parse_json(json)
    message = json.delete 'message'
    json
      .except('uid', 'exercise_id')
      .merge(message)
  end

  def self.read_all!
    update_all read: true
  end

  def self.import_from_json!(json)
    message_data = parse_json json
    Organization.find_by!(name: message_data.delete('organization')).switch!

    if message_data['submission_id'].present?
      Assignment.find_by(submission_id: message_data.delete('submission_id'))&.receive_answer! message_data
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
mumuki-laboratory-5.5.0 app/models/message.rb
mumuki-laboratory-5.4.0 app/models/message.rb
mumuki-laboratory-5.3.0 app/models/message.rb
mumuki-laboratory-5.2.1 app/models/message.rb
mumuki-laboratory-5.2.0 app/models/message.rb
mumuki-laboratory-5.1.1 app/models/message.rb
mumuki-laboratory-5.1.0 app/models/message.rb
mumuki-laboratory-5.0.12 app/models/message.rb
mumuki-laboratory-5.0.11 app/models/message.rb
mumuki-laboratory-5.0.10 app/models/message.rb
mumuki-laboratory-5.0.9 app/models/message.rb
mumuki-laboratory-5.0.8 app/models/message.rb
mumuki-laboratory-5.0.7 app/models/message.rb
mumuki-laboratory-5.0.6 app/models/message.rb
mumuki-laboratory-5.0.5 app/models/message.rb
mumuki-laboratory-5.0.4 app/models/message.rb
mumuki-laboratory-5.0.3 app/models/message.rb
mumuki-laboratory-5.0.2 app/models/message.rb
mumuki-laboratory-5.0.1 app/models/message.rb
mumuki-laboratory-5.0.0 app/models/message.rb