<commit_before>module MB
  class Message < ActiveRecord::Base

    acts_as_resourceful

#     validates_presence_of :user, :category, :subject, :body

    # Actions for Permissions.
    def self.actions
      %w{
        DELETE
        PERMISSIONS
        SUBSCRIBE
        UPDATE
        VIEW
      }
    end

    # Parameters:
    #  - user
    #  - category or parent message
    #  - body
    #  - flag (Fixnum)
    def initialize(params)
      raise 'No user' unless params[:user] or params[:userid]
      unless ((params[:category] or params[:categoryid]) || (params[:parent] or params[:parentmessageid]))
        raise 'No category or parentmessage'
      end
      raise 'No body' unless params[:body]
      super(params)

      # COPY mbmessage (uuid_, messageid, companyid, userid, username, createdate, modifieddate, categoryid, threadid, parentmessageid, subject, body, attachments, anonymous) FROM stdin;
      # +66089117-ddb5-4577-ba9b-76479a273727	10308	10109	10129	Test Test	2009-01-17 08:07:11.947	2009-01-17 08:07:11.947	10307	10309	0	New thread	This is a test, using rich editor.	f	f

      unless self.uuid_
        require 'rubygems'
        require 'uuidtools'
        self.uuid_ = UUID.random_create.to_s
      end

      self.category ||= self.parent.category
      category = self.category

      self.companyid ||= category.companyid

      # always require User
      #unless self.userid
      #  self.userid = 0
      #  self.anonymous = true
      #else
        self.anonymous = false
      #end

      self.subject         ||= ''
      self.username        ||= ''
      self.createdate      = Time.now
      self.modifieddate    = Time.now
      self.parentmessageid ||= 0
      self.attachments     ||= false
      self.save


      # COPY mbcategory (uuid_, categoryid, groupid, companyid, userid, username, createdate, modifieddate, parentcategoryid, name, description, lastpostdate) FROM stdin;
      # -fda18eef-3992-419e-a373-6e2f01a8b6a9	10307	10166	10109	10129	Test Test	2009-01-17 08:06:00.359	2009-01-17 08:06:00.359	0	Teppo Testaaja	message board for user Teppo	\N
      # +fda18eef-3992-419e-a373-6e2f01a8b6a9	10307	10166	10109	10129	Test Test	2009-01-17 08:06:00.359	2009-01-17 08:06:00.359	0	Teppo Testaaja	message board for user Teppo	2009-01-17 08:07:11.947

      category.lastpostdate = Time.now
      category.save


      # COPY mbthread (threadid, categoryid, rootmessageid, messagecount, viewcount, lastpostbyuserid, lastpostdate, priority) FROM stdin;
      # +10309	10307	10308	1	1	10129	2009-01-17 08:07:11.947	0

      thread = MB::Thread.find(:first,
        :conditions => "categoryid=#{category.id} AND rootmessageid=#{self.find_thread_root.id}")
      unless thread
        thread = MB::Thread.create(
          :category => category,
          :rootmessage => self
        )
      end
      thread.messagecount += 1
      thread.lastpostbyuserid = self.user.id
      thread.lastpostdate = Time.now
      thread.save<commit_msg>using user.full as message.username if message has user<commit_after>module MB
  class Message < ActiveRecord::Base

    acts_as_resourceful

#     validates_presence_of :user, :category, :subject, :body

    # Actions for Permissions.
    def self.actions
      %w{
        DELETE
        PERMISSIONS
        SUBSCRIBE
        UPDATE
        VIEW
      }
    end

    # Parameters:
    #  - user
    #  - category or parent message
    #  - body
    #  - flag (Fixnum)
    def initialize(params)
      raise 'No user' unless params[:user] or params[:userid]
      unless ((params[:category] or params[:categoryid]) || (params[:parent] or params[:parentmessageid]))
        raise 'No category or parentmessage'
      end
      raise 'No body' unless params[:body]
      super(params)

      # COPY mbmessage (uuid_, messageid, companyid, userid, username, createdate, modifieddate, categoryid, threadid, parentmessageid, subject, body, attachments, anonymous) FROM stdin;
      # +66089117-ddb5-4577-ba9b-76479a273727	10308	10109	10129	Test Test	2009-01-17 08:07:11.947	2009-01-17 08:07:11.947	10307	10309	0	New thread	This is a test, using rich editor.	f	f

      unless self.uuid_
        require 'rubygems'
        require 'uuidtools'
        self.uuid_ = UUID.random_create.to_s
      end

      self.category ||= self.parent.category
      category = self.category

      self.companyid ||= category.companyid

      # always require User
      #unless self.userid
      #  self.userid = 0
      #  self.anonymous = true
      #else
        self.anonymous = false
      #end

      self.createdate      = Time.now
      self.modifieddate    = Time.now
      self.subject         ||= ''
      self.username        ||= self.user ? self.user.fullname : ''
      self.parentmessageid ||= 0
      self.attachments     ||= false
      self.save


      # COPY mbcategory (uuid_, categoryid, groupid, companyid, userid, username, createdate, modifieddate, parentcategoryid, name, description, lastpostdate) FROM stdin;
      # -fda18eef-3992-419e-a373-6e2f01a8b6a9	10307	10166	10109	10129	Test Test	2009-01-17 08:06:00.359	2009-01-17 08:06:00.359	0	Teppo Testaaja	message board for user Teppo	\N
      # +fda18eef-3992-419e-a373-6e2f01a8b6a9	10307	10166	10109	10129	Test Test	2009-01-17 08:06:00.359	2009-01-17 08:06:00.359	0	Teppo Testaaja	message board for user Teppo	2009-01-17 08:07:11.947

      category.lastpostdate = Time.now
      category.save


      # COPY mbthread (threadid, categoryid, rootmessageid, messagecount, viewcount, lastpostbyuserid, lastpostdate, priority) FROM stdin;
      # +10309	10307	10308	1	1	10129	2009-01-17 08:07:11.947	0

      thread = MB::Thread.find(:first,
        :conditions => "categoryid=#{category.id} AND rootmessageid=#{self.find_thread_root.id}")
      unless thread
        thread = MB::Thread.create(
          :category => category,
          :rootmessage => self
        )
      end
      thread.messagecount += 1
      thread.lastpostbyuserid = self.user.id
      thread.lastpostdate = Time.now
      thread.save
{'fraction_non_alphanumeric': 0.09730712043614737, 'fraction_numerical': 0.09681149843053032, 'mean_word_length': 2.567472009428403, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4847060', 'n_tokens_mistral': 2361, 'n_tokens_neox': 1994, 'n_words': 496}