   (create-class {:reagent-render (fn [messages]
                                    [:div {:id ""}
                                     (doall
-                                     (for [item messages]
-                                       (message-list-item item state)))
+                                      (for [item messages]
+                                        (message-list-item item state)))
                                     (message-list-load-more state)])
                  ;:component-did-mount #(scroll-bottom)
                  ;:component-did-update #(scroll-bottom)

            [salava.core.ui.modal :refer [set-new-view]]
            [salava.core.time :refer [date-from-unix-time]]))

(defn init-data [state]
  (ajax/GET
   (path-for (str "/obpv1/social/messages/" (:badge_id @state) "/" (:page_count @state)))
   {:handler (fn [data]
               (swap! state assoc
                      :messages (into (:messages @state) (:messages data))
                      :message ""
                      :page_count (inc (:page_count @state))
                      :messages_left (:messages_left data)))}))


(defn save-message [state reload-fn]
  (let [{:keys [message user_id badge_id]} @state]
    (ajax/POST
     (path-for (str "/obpv1/social/messages/" badge_id))
     {:response-format :json
      :keywords? true
      :params {:message message
               :user_id user_id}
      :handler (fn [data]
                 (do
                   (if (= "success" (:connected? data))
                     (do
                       
                       (f/init-data badge_id)
                       (swap! state assoc :start-following true))
                     (swap! state assoc :start-following false))
                   (swap! state assoc
                          :messages []
                          :page_count 0)
                   (init-data state)
                   (reload-fn)
                   ))
      :error-handler (fn [{:keys [status status-text]}]
                       (dump (str status " " status-text)))})))

(defn delete-message [id state]
  (ajax/POST
   (path-for (str "/obpv1/social/delete_message/" id))
   {:response-format :json
    :keywords? true 
    :handler (fn [data]
               (let [filtered-messages (filter #(not (= id (:id %))) (:messages @state))]
                 (swap! state assoc :messages filtered-messages)))
    :error-handler (fn [{:keys [status status-text]}]
                    (dump (str status " " status-text)))}))

(defn delete-message-button [id state]
  (let [delete-clicked (atom nil)]

                    (do
                      (let [current (conj str1 " ")]
                        (conj current str2))))]
    (reduce str-space ()  a-seq)))

(defn search-and-replace-www [text]
  (let [split-words (clojure.string/split text #" ")
        helper (fn [current item]
                 (if (or (re-find #"www." item) (re-find #"^https?://" item) (re-find #"^http?://" item))
                   (conj current (hyperlink item))
                   (conj current (str item))))]
    (blank-reduce (reduce helper () split-words))))

(defn message-list-item [{:keys [message first_name last_name ctime id profile_picture user_id]} state]
