<commit_before>module Diaspora
  module XMLParser
    def parse_sender_id_from_xml(xml)
      doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
      doc.xpath("/XML/head/sender/email").text.to_s
    end

    def parse_sender_object_from_xml(xml)
      sender_id = parse_sender_id_from_xml(xml)
      Friend.where(:email =>sender_id ).first


    end
    

    def parse_owner_from_xml(xml)
      doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
      email = doc.xpath("//person/email").text.to_s
      Friend.where(:email => email).first
    end

    def parse_body_contents_from_xml(xml)
      doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
      doc.xpath("/XML/posts/post")
    end

    def parse_objects_from_xml(xml)
      objects = []
      sender = parse_sender_object_from_xml(xml)
      body = parse_body_contents_from_xml(xml)
      body.children.each do |post|
        begin
          object = post.name.camelize.constantize.from_xml post.to_s
          object.person =  parse_owner_from_xml post.to_s #if object.is_a? Post  
          
         # if object.is_a? Comment
         #   object.post = parse_post_
         # end
          
          
          objects << object 
        rescue
          puts "Not a real type: #{object.to_s}"
        end
      end
      objects
    end

    def store_objects_from_xml(xml)
      objects = parse_objects_from_xml(xml)

      objects.each do |p|
        p.save if p.respond_to?(:person) && !(p.person.nil?) #WTF
        #p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
      end
    end
  end

  module Webhooks
    def self.included(klass)
      klass.class_eval do
        @@queue = MessageHandler.new
        
        def notify_friends
          if self.person_id == User.first.id<commit_msg>RS, slight clarification in common<commit_after>module Diaspora
  module XMLParser
    def parse_sender_id_from_xml(xml)
      doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
      doc.xpath("/XML/head/sender/email").text.to_s
    end

    def parse_sender_object_from_xml(xml)
      sender_id = parse_sender_id_from_xml(xml)
      Friend.where(:email =>sender_id ).first


    end
    

    def parse_owner_from_xml(xml)
      doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
      email = doc.xpath("//person/email").text.to_s
      Friend.where(:email => email).first
    end

    def parse_body_contents_from_xml(xml)
      doc = Nokogiri::XML(xml) { |cfg| cfg.noblanks }
      doc.xpath("/XML/posts/post")
    end

    def parse_objects_from_xml(xml)
      objects = []
      sender = parse_sender_object_from_xml(xml)
      body = parse_body_contents_from_xml(xml)
      body.children.each do |post|
        begin
          object = post.name.camelize.constantize.from_xml post.to_s
          object.person =  parse_owner_from_xml post.to_s #if object.is_a? Post  
          objects << object 
        rescue
          puts "Not a real type: #{object.to_s}"
        end
      end
      objects
    end

    def store_objects_from_xml(xml)
      objects = parse_objects_from_xml(xml)

      objects.each do |p|
        #This line checks if the sender was in the database, among other things?
        p.save if p.respond_to?(:person) && !(p.person.nil?) #WTF
        #p.save if p.respond_to?(:person) && !(p.person == nil) #WTF
      end
    end
  end

  module Webhooks
    def self.included(klass)
      klass.class_eval do
        @@queue = MessageHandler.new
        
        def notify_friends
          if self.person_id == User.first.id
{'fraction_non_alphanumeric': 0.10335990888382687, 'fraction_numerical': 0.0, 'mean_word_length': 2.289325842696629, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 50}, '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': '5060262', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1180, 'n_words': 234}