You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
pgfqe6ch8/lib/trustie/at/at.rb

31 lines
1.3 KiB

#coding=utf-8
module Trustie
module At
extend ActiveSupport::Concern
module ClassMethods
def act_as_at_message(content, send_id)
self.send :define_method, :act_as_at_message_func do
users = self[content].scan /<span class="at" data-user-id="(.+?)">/m
users && users.flatten.uniq.each do |uids|
uids.split(",").each do |uid|
if self.class.to_s == "JournalsForMessage"
self.tidings << Tiding.new(user_id: uid, trigger_user_id: self[send_id], parent_container_id: self.jour_id, parent_container_type: self.jour_type, viewed: 0, tiding_type: "Mentioned")
elsif self.class.to_s == "Message"
self.tidings << Tiding.new(user_id: uid, trigger_user_id: self[send_id], parent_container_id: self.root_id, parent_container_type: "Message", viewed: 0, tiding_type: "Mentioned")
elsif self.class.to_s == "Journal"
self.tidings << Tiding.new(user_id: uid, trigger_user_id: self[send_id], parent_container_id: self.journalized_id, parent_container_type: self.journalized_type, viewed: 0, tiding_type: "Mentioned")
end
# self.at_messages << AtMessage.new(user_id: uid, sender_id: self[send_id])
end
end
end
end
end
end
end
ActiveRecord::Base.send(:include, Trustie::At)