<commit_before>(in-package :kindista)

(defun create-person (&key name email password)
  (insert-db `(:type :person
               :name ,name
               :email ,email
               :help t
               :pass ,(new-password password)
               :created ,(get-universal-time))))

(defun index-person (id data)
  (let ((result (make-result :id id
                             :latitude (getf data :lat)
                             :longitude (getf data :long)
                             :type :person
                             :people (list id)
                             :created (getf data :created))))

    (setf (gethash (getf data :email) *email-index*) id)
    (setf (gethash (getf data :username) *username-index*) id)

    (awhen (getf data :following)
      (with-locked-hash-table (*followers-index*)
        (dolist (person it)
          (push id (gethash person *followers-index*)))))

    (when (getf data :loves)
      (with-locked-hash-table (*love-index*)
        (dolist (item (getf data :loves))
          (unless (member id (gethash item *love-index*))
            (push id (gethash item *love-index*))))))

    (with-locked-hash-table (*activity-person-index*)
      (asetf (gethash id *activity-person-index*)
             (sort (push result it) #'> :key #'result-created)))

    (when (and (getf data :lat) (getf data :long) (getf data :created))
      (metaphone-index-insert *metaphone-index* (getf data :name) result)
      (geo-index-insert *people-geo-index* result)
      (geo-index-insert *activity-geo-index* result))))

(defun username-or-id (&optional (id *userid*))
  (or (getf (db id) :username)
      (write-to-string id)))

(defun profile-activity-items (&key (userid *userid*) (page 0) (count 20) next-url type)
  (let ((items (gethash userid *activity-person-index*))
        (start (* page 20)))
    (html
      (iter 
        (for i from 0 to (+ start count))
          (if (and (>= i start) items)
            (let ((item (car items)))
              (when (or (not type) (eql type (result-type item)))
                (case (result-type item)
                  (:gratitude 
                    (str (unless (and (eql type :gratitude) 
                                      (eql userid (first (result-people item))))
                           (gratitude-activity-item item
                                                    :next-url next-url))))
                  (:person 
                    (str (joined-activity-item item)))
                  (:offer
                    (str (offer-activity-item item
                                              :show-what (unless (eql type :offer) t)
                                              :next-url next-url)))   
                  (:request
                    (str (request-activity-item item
                                                :show-what (unless (eql type :request) t)
                                                :next-url next-url))))))
            (finish))

          (setf items (cdr items))

          (finally
            (when (or (> page 0) (cdr items))
              (htm
                (:div :class "item"
                 (when (> page 0)
                   (htm
                     (:a :href (strcat "/home?p=" (- page 1)) "< previous page")))
                 "&nbsp;"
                 (when (cdr items)
                   (htm
                     (:a :style "float: right;" :href (strcat "/home?p=" (+ page 1)) "next page >")))))))))))

(defun profile-tabs-html (userid &key tab)
  (let* ((bio (getf (db userid) :bio))
         (self (eql userid *userid*))
         (show-bio-tab (or bio self)))
    (html
      (:menu :class "bar"
        (:h3 :class "label" "Profile Menu")
        (when show-bio-tab
          (if (and self (eql tab :about))
            (htm (:li :class "selected" "About"))
            (htm (:li (:a :href (strcat *base-url* "/about") "About")))))

        (if (eql tab :activity)
          (htm (:li :class "selected" "Activity"))
          (htm (:li (:a :href (strcat *base-url* "/activity") "Activity"))))
        (if (eql tab :gratitude)
          (htm (:li :class "selected" "Reputation"))
          (htm (:li (:a :href (strcat *base-url* "/reputation") "Reputation"))))  
        (if (eql tab :offer)
          (htm (:li :class "selected" "Offers"))
          (htm (:li (:a :href (strcat *base-url* "/offers") "Offers"))))
        (if (eql tab :request)
          (htm (:li :class "selected" "Requests"))
          (htm (:li (:a :href (strcat *base-url* "/requests") "Requests"))))))))

(defun profile-bio-section-html (title content &key editing editable section-name)
  (when (string= content "")
    (setf content nil))

  (when (or content editing editable)
    (html
      (:div :class "bio-section"
        (:h2 (str title)
             (when (and editable (not editing))
               (htm (:a :href (strcat *base-url* "?edit=" section-name)
                        (:img :class "icon" :src "/media/icons/pencil.png")))))
        (cond
          (editing
            (htm
              (:form :method "post" :action "/settings"
                (:input :type "hidden" :name "next" :value *base-url*)
                (:textarea :name (strcat "bio-" section-name) (str content))
                (:button :class "yes" :type "submit" :name "save" "Save")
                (:a :class "cancel" :href *base-url* "Cancel")
                ))) 
          ((not content)
            (htm
              (:p :class "empty" "I'm empty... fill me out!")))

          (t
            (htm
              (:p (str content)))))))))

(defun profile-bio-html (userid &key editing)
  ; is the user editing one of the sections?
  ; should we show edit links for the sections?
  ;  if the user is looking at their own bio
  ;   and they are not currently editing another section
  ;
  (require-user
    (let* ((strid (username-or-id userid))
           (editable (when (not editing) (eql userid *userid*)))
           (user (db userid))
           (*base-url* (strcat "/people/" strid)))
      (standard-page
        (getf (db userid) :name)
        (html
          (str (profile-tabs-html userid :tab :about))
          (if (or (eql userid *userid*) (getf user :bio))
            (htm
              (:div :class "bio"
                (str (profile-bio-section-html
                       "My self-summary"
                       (getf user :bio-summary)
                       :section-name "summary"
                       :editing (eql editing 'summary)
                       :editable editable))  
                (str (profile-bio-section-html
                       "What I'm doing with my life"
                       (getf user :bio-doing)
                       :section-name "doing"
                       :editing (eql editing 'doing)
                       :editable editable))  
                (str (profile-bio-section-html
                       "What I'm really good at"
                       (getf user :bio-skills)
                       :section-name "skills"
                       :editing (eql editing 'skills)
                       :editable editable))
                (str (profile-bio-section-html
                       "I'm also into"
                       (getf user :bio-into)
                       :section-name "into"
                       :editing (eql editing 'into)
                       :editable editable))
                (str (profile-bio-section-html
                       "You should contact me if"
                       (getf user :bio-contact)
                       :section-name "contact"
                       :editing (eql editing 'contact)
                       :editable editable))))
            (htm (:h3 "This person hasn't written anything here."))))
        :right (when editing (html (:h2 "Style guide")))
        :top (profile-top-html userid)))))

(defun profile-top-html (userid)
  (let ((user (db userid))
        (is-friend (member userid (getf *user* :following))))
    (html
     (:img :class "bigavatar" :src (strcat "/media/avatar/" userid ".jpg"))
     (:div :class "basics"
       (:h1 (str (getf user :name)))
       (:p :class "city" "Eugene, OR")
     (unless (eql userid *userid*)
       (htm 
         (:form :method "GET" :action (strcat *base-url* "/message")
           (:input :type "submit" :value "Send a message")) 
         (:form :method "POST" :action "/friends"
           (:input :type "hidden" :name (if is-friend "remove" "add") :value userid)
           (:input :type "hidden" :name "next" :value *base-url*)
           (:input :class (when is-friend "cancel") :type "submit" :value (if is-friend "Remove friend" "Add as friend")))))))))
<commit_msg>added :selected people<commit_after>(in-package :kindista)

(defun create-person (&key name email password)
  (insert-db `(:type :person
               :name ,name
               :email ,email
               :help t
               :pass ,(new-password password)
               :created ,(get-universal-time))))

(defun index-person (id data)
  (let ((result (make-result :id id
                             :latitude (getf data :lat)
                             :longitude (getf data :long)
                             :type :person
                             :people (list id)
                             :created (getf data :created))))

    (setf (gethash (getf data :email) *email-index*) id)
    (setf (gethash (getf data :username) *username-index*) id)

    (awhen (getf data :following)
      (with-locked-hash-table (*followers-index*)
        (dolist (person it)
          (push id (gethash person *followers-index*)))))

    (when (getf data :loves)
      (with-locked-hash-table (*love-index*)
        (dolist (item (getf data :loves))
          (unless (member id (gethash item *love-index*))
            (push id (gethash item *love-index*))))))

    (with-locked-hash-table (*activity-person-index*)
      (asetf (gethash id *activity-person-index*)
             (sort (push result it) #'> :key #'result-created)))

    (when (and (getf data :lat) (getf data :long) (getf data :created))
      (metaphone-index-insert *metaphone-index* (getf data :name) result)
      (geo-index-insert *people-geo-index* result)
      (geo-index-insert *activity-geo-index* result))))

(defun username-or-id (&optional (id *userid*))
  (or (getf (db id) :username)
      (write-to-string id)))

(defun profile-activity-items (&key (userid *userid*) (page 0) (count 20) next-url type)
  (let ((items (gethash userid *activity-person-index*))
        (start (* page 20)))
    (html
      (iter 
        (for i from 0 to (+ start count))
          (if (and (>= i start) items)
            (let ((item (car items)))
              (when (or (not type) (eql type (result-type item)))
                (case (result-type item)
                  (:gratitude 
                    (str (unless (and (eql type :gratitude) 
                                      (eql userid (first (result-people item))))
                           (gratitude-activity-item item
                                                    :next-url next-url))))
                  (:person 
                    (str (joined-activity-item item)))
                  (:offer
                    (str (offer-activity-item item
                                              :show-what (unless (eql type :offer) t)
                                              :next-url next-url)))   
                  (:request
                    (str (request-activity-item item
                                                :show-what (unless (eql type :request) t)
                                                :next-url next-url))))))
            (finish))

          (setf items (cdr items))

          (finally
            (when (or (> page 0) (cdr items))
              (htm
                (:div :class "item"
                 (when (> page 0)
                   (htm
                     (:a :href (strcat "/home?p=" (- page 1)) "< previous page")))
                 "&nbsp;"
                 (when (cdr items)
                   (htm
                     (:a :style "float: right;" :href (strcat "/home?p=" (+ page 1)) "next page >")))))))))))

(defun profile-tabs-html (userid &key tab)
  (let* ((bio (getf (db userid) :bio))
         (self (eql userid *userid*))
         (show-bio-tab (or bio self)))
    (html
      (:menu :class "bar"
        (:h3 :class "label" "Profile Menu")
        (when show-bio-tab
          (if (and self (eql tab :about))
            (htm (:li :class "selected" "About"))
            (htm (:li (:a :href (strcat *base-url* "/about") "About")))))

        (if (eql tab :activity)
          (htm (:li :class "selected" "Activity"))
          (htm (:li (:a :href (strcat *base-url* "/activity") "Activity"))))
        (if (eql tab :gratitude)
          (htm (:li :class "selected" "Reputation"))
          (htm (:li (:a :href (strcat *base-url* "/reputation") "Reputation"))))  
        (if (eql tab :offer)
          (htm (:li :class "selected" "Offers"))
          (htm (:li (:a :href (strcat *base-url* "/offers") "Offers"))))
        (if (eql tab :request)
          (htm (:li :class "selected" "Requests"))
          (htm (:li (:a :href (strcat *base-url* "/requests") "Requests"))))))))

(defun profile-bio-section-html (title content &key editing editable section-name)
  (when (string= content "")
    (setf content nil))

  (when (or content editing editable)
    (html
      (:div :class "bio-section"
        (:h2 (str title)
             (when (and editable (not editing))
               (htm (:a :href (strcat *base-url* "?edit=" section-name)
                        (:img :class "icon" :src "/media/icons/pencil.png")))))
        (cond
          (editing
            (htm
              (:form :method "post" :action "/settings"
                (:input :type "hidden" :name "next" :value *base-url*)
                (:textarea :name (strcat "bio-" section-name) (str content))
                (:button :class "yes" :type "submit" :name "save" "Save")
                (:a :class "cancel" :href *base-url* "Cancel")
                ))) 
          ((not content)
            (htm
              (:p :class "empty" "I'm empty... fill me out!")))

          (t
            (htm
              (:p (str content)))))))))

(defun profile-bio-html (userid &key editing)
  ; is the user editing one of the sections?
  ; should we show edit links for the sections?
  ;  if the user is looking at their own bio
  ;   and they are not currently editing another section
  ;
  (require-user
    (let* ((strid (username-or-id userid))
           (editable (when (not editing) (eql userid *userid*)))
           (user (db userid))
           (*base-url* (strcat "/people/" strid)))
      (standard-page
        (getf (db userid) :name)
        (html
          (str (profile-tabs-html userid :tab :about))
          (if (or (eql userid *userid*) (getf user :bio))
            (htm
              (:div :class "bio"
                (str (profile-bio-section-html
                       "My self-summary"
                       (getf user :bio-summary)
                       :section-name "summary"
                       :editing (eql editing 'summary)
                       :editable editable))  
                (str (profile-bio-section-html
                       "What I'm doing with my life"
                       (getf user :bio-doing)
                       :section-name "doing"
                       :editing (eql editing 'doing)
                       :editable editable))  
                (str (profile-bio-section-html
                       "What I'm really good at"
                       (getf user :bio-skills)
                       :section-name "skills"
                       :editing (eql editing 'skills)
                       :editable editable))
                (str (profile-bio-section-html
                       "I'm also into"
                       (getf user :bio-into)
                       :section-name "into"
                       :editing (eql editing 'into)
                       :editable editable))
                (str (profile-bio-section-html
                       "You should contact me if"
                       (getf user :bio-contact)
                       :section-name "contact"
                       :editing (eql editing 'contact)
                       :editable editable))))
            (htm (:h3 "This person hasn't written anything here."))))
        :right (when editing (html (:h2 "Style guide")))
        :top (profile-top-html userid)
        :selected "people"))))

(defun profile-top-html (userid)
  (let ((user (db userid))
        (is-friend (member userid (getf *user* :following))))
    (html
     (:img :class "bigavatar" :src (strcat "/media/avatar/" userid ".jpg"))
     (:div :class "basics"
       (:h1 (str (getf user :name)))
       (:p :class "city" "Eugene, OR")
     (unless (eql userid *userid*)
       (htm 
         (:form :method "GET" :action (strcat *base-url* "/message")
           (:input :type "submit" :value "Send a message")) 
         (:form :method "POST" :action "/friends"
           (:input :type "hidden" :name (if is-friend "remove" "add") :value userid)
           (:input :type "hidden" :name "next" :value *base-url*)
           (:input :class (when is-friend "cancel") :type "submit" :value (if is-friend "Remove friend" "Add as friend")))))))))

{'fraction_non_alphanumeric': 0.14300458715596331, 'fraction_numerical': 0.0017201834862385322, 'mean_word_length': 1.5192835475949733, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 24, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2789126', 'n_tokens_mistral': 5235, 'n_tokens_neox': 4898, 'n_words': 1540}