########fq
module WordsHelper 
  def message_list(object, state, user)
    unless state
      if object.size > 5
        object = object[-5, 5]  
      end
    end
    object = object.reverse
    remove_allowed = (User.current.id == object.first.user_id)
    content = ''.html_safe
    lis = object.each do |t_object|
      s = ''.html_safe
      s << link_to(t_object.indice, {}, :class => "journal-link")
      s << avatar(t_object.user, :size => "16").to_s
      s << link_to_user(t_object.user, :class => 'user')
      time = time_tag(t_object.created_at)
      s << l(:field_add, :time => time).html_safe
      if !t_object.notes.blank?
        s << link_to(image_tag('comment.png'),
                       {:controller => 'words', :action => 'new', :id => user, :journal_id => t_object},
                       :remote => true,
                       :method => 'post',
                       :title => l(:button_quote))
        if remove_allowed || t_object.jour_id == User.current.id
          url = {:controller => 'words',
            :action => 'destroy',
            :object_id => t_object,
            :user_id => user}
          s << ' '
          s << link_to(image_tag('delete.png'), url,
                     :remote => true, :method => 'delete', :class => "delete", :title => l(:button_delete))
        end                                                     
      end
      #time = '更新于' + time_tag(t_object.created_at) + '之前'
      
      
      # s << content_tag('div', time)
      
      content << content_tag('li', s, :class => "user-#{t_object.jour_id}")
      content << textilizable(t_object.notes)
    end
    # content.present? ? content_tag('ul', content, :class => 'watchers') : content
    content
  end

  def fetch_user_leaveWord_reply leaveWordObj
    if leaveWordObj.kind_of? JournalsForMessage
      leaveWordObj.children
    elsif leaveWordObj.kind_of? Fixnum
      JournalsForMessage.find(leaveWordObj).children
    else
      []
    end
  end
end
