From 2296f1ff5baa79a1a6214e30c0150af47ea09af3 Mon Sep 17 00:00:00 2001 From: Alexander Pantyuhov Date: Wed, 12 Oct 2016 13:32:32 +0300 Subject: [PATCH] Beginning of chat (#296), fix for status saving Former-commit-id: ba885ea97f5b7b02a9114f7855b9e476d52a64e3 --- src/status_im/chat/screen.cljs | 29 ++++++--- src/status_im/chat/sign_up.cljs | 2 - src/status_im/chat/styles/message.cljs | 3 + src/status_im/chat/utils.cljs | 2 +- src/status_im/chat/views/message.cljs | 62 +++++++++++++------ .../realm/schemas/account/core.cljs | 8 ++- .../realm/schemas/account/v2/contact.cljs | 22 +++++++ .../realm/schemas/account/v2/core.cljs | 29 +++++++++ 8 files changed, 124 insertions(+), 33 deletions(-) create mode 100644 src/status_im/data_store/realm/schemas/account/v2/contact.cljs create mode 100644 src/status_im/data_store/realm/schemas/account/v2/core.cljs diff --git a/src/status_im/chat/screen.cljs b/src/status_im/chat/screen.cljs index adec449948..032faf69aa 100644 --- a/src/status_im/chat/screen.cljs +++ b/src/status_im/chat/screen.cljs @@ -79,6 +79,7 @@ (let [message (-> row (add-message-color contact-by-identity) (assoc :group-chat group-chat) + (assoc :messages-count messages-count) (assoc :last-message (= (js/parseInt index) (dec messages-count))))] (list-item [chat-message message]))) @@ -142,15 +143,27 @@ :custom-action [toolbar-action] :style (get-in platform-specific [:component-styles :toolbar])}]]) +(defn get-intro-status-message [all-messages] + (let [{:keys [timestamp content-type] :as last-message} (last all-messages)] + (when (not= content-type content-type-status) + {:message-id "intro-status" + :content-type content-type-status + :timestamp (or timestamp (time/now-ms))}))) + + (defn messages-with-timemarks [all-messages] - (let [messages (->> all-messages - (map #(assoc % :datemark (time/day-relative (:timestamp %)))) - (group-by :datemark) - (map (fn [[k v]] [v {:type :datemark :value k}])) - (flatten)) - remove-last? (some (fn [{:keys [content-type]}] - (= content-type content-type-status)) - messages)] + (let [status-message (get-intro-status-message all-messages) + all-messages (if status-message + (concat all-messages [status-message]) + all-messages) + messages (->> all-messages + (map #(assoc % :datemark (time/day-relative (:timestamp %)))) + (group-by :datemark) + (map (fn [[k v]] [v {:type :datemark :value k}])) + (flatten)) + remove-last? (some (fn [{:keys [content-type]}] + (= content-type content-type-status)) + messages)] (if remove-last? (drop-last messages) messages))) diff --git a/src/status_im/chat/sign_up.cljs b/src/status_im/chat/sign_up.cljs index e127d36c44..34e90bd5d7 100644 --- a/src/status_im/chat/sign_up.cljs +++ b/src/status_im/chat/sign_up.cljs @@ -121,8 +121,6 @@ ;; TODO highlight '!phone' (start-signup)) - - (def intro-status {:message-id "intro-status" :content (label :t/intro-status) diff --git a/src/status_im/chat/styles/message.cljs b/src/status_im/chat/styles/message.cljs index 0740c11ef9..6dd375acbd 100644 --- a/src/status_im/chat/styles/message.cljs +++ b/src/status_im/chat/styles/message.cljs @@ -40,6 +40,9 @@ {:margin-top 10 :margin-bottom -4}) +(def message-empty-spacing + {:height 16}) + (def message-body-base {:padding-right 8 :padding-left 8}) diff --git a/src/status_im/chat/utils.cljs b/src/status_im/chat/utils.cljs index 3cd56d9d85..42679a7f69 100644 --- a/src/status_im/chat/utils.cljs +++ b/src/status_im/chat/utils.cljs @@ -20,7 +20,7 @@ (merge message {:same-author (if previous-message (= (:from previous-message) from) - false) + true) :same-direction (if previous-message (= (:outgoing previous-message) outgoing) true)})) diff --git a/src/status_im/chat/views/message.cljs b/src/status_im/chat/views/message.cljs index 02e6260fb6..2b58bf2b85 100644 --- a/src/status_im/chat/views/message.cljs +++ b/src/status_im/chat/views/message.cljs @@ -18,12 +18,16 @@ [status-im.models.commands :refer [parse-command-message-content parse-command-request]] [status-im.resources :as res] - [status-im.constants :refer [text-content-type + [status-im.utils.datetime :as time] + [status-im.constants :refer [console-chat-id + text-content-type content-type-status content-type-command content-type-command-request]] [status-im.utils.identicon :refer [identicon]] - [status-im.chat.utils :as cu])) + [status-im.i18n :refer [label]] + [status-im.chat.utils :as cu] + [clojure.string :as str])) (defn contact-photo [photo-path] [view st/contact-photo-container @@ -32,28 +36,46 @@ {:uri photo-path}) :style st/contact-photo}]]) -(defn contact-online [{:keys [online]}] - (when online +(defn contact-online [online?] + (when online? [view st/online-container [view st/online-dot-left] [view st/online-dot-right]])) -(defview message-content-status - [{:keys [from content datemark]}] - [{chat-name :name} [:get-chat-by-id from] - photo-path [:chat-photo from]] - [view st/status-container - [view st/status-image-view - [contact-photo photo-path] - [contact-online {:online true}]] - [text {:style st/status-from - :font :default} - (or chat-name from)] - [text {:style st/status-text - :font :default} - content] - [view st/message-datemark - [chat-datemark datemark]]]) +;;[photo-path (subscribe [:chat-photo from]) + +(defn message-content-status [{:keys [from]}] + (let [chat-photo-path (subscribe [:chat-photo from]) + {:keys [group-chat name]} (subscribe [:chat-properties [:group-chat :name]]) + members (subscribe [:current-chat-contacts])] + (fn [{:keys [messages-count content datemark]}] + (let [{:keys [photo-path + status + last-online]} (if @group-chat + {:photo-path nil + :status nil + :last-online 0} + (first @members)) + online? (-> (- (time/now-ms) last-online) + (< (* 60 1000)))] + [view st/status-container + [view st/status-image-view + [contact-photo (or photo-path @chat-photo-path)] + [contact-online online?]] + [text {:style st/status-from + :font :default + :number-of-lines 1} + (if (str/blank? @name) + (label :t/user-anonymous) + (or @name (label :t/chat-name)))] + (when (or status content) + [text {:style st/status-text + :font :default} + (or status content)]) + (if (> messages-count 1) + [view st/message-datemark + [chat-datemark datemark]] + [view st/message-empty-spacing])])))) (defn message-content-audio [_] [view st/audio-container diff --git a/src/status_im/data_store/realm/schemas/account/core.cljs b/src/status_im/data_store/realm/schemas/account/core.cljs index 666e27468f..98de1be71e 100644 --- a/src/status_im/data_store/realm/schemas/account/core.cljs +++ b/src/status_im/data_store/realm/schemas/account/core.cljs @@ -1,7 +1,11 @@ (ns status-im.data-store.realm.schemas.account.core - (:require [status-im.data-store.realm.schemas.account.v1.core :as v1])) + (:require [status-im.data-store.realm.schemas.account.v1.core :as v1] + [status-im.data-store.realm.schemas.account.v2.core :as v2])) ; put schemas ordered by version (def schemas [{:schema v1/schema :schemaVersion 1 - :migration v1/migration}]) \ No newline at end of file + :migration v1/migration} + {:schema v2/schema + :schemaVersion 2 + :migration v2/migration}]) \ No newline at end of file diff --git a/src/status_im/data_store/realm/schemas/account/v2/contact.cljs b/src/status_im/data_store/realm/schemas/account/v2/contact.cljs new file mode 100644 index 0000000000..6d743fcff0 --- /dev/null +++ b/src/status_im/data_store/realm/schemas/account/v2/contact.cljs @@ -0,0 +1,22 @@ +(ns status-im.data-store.realm.schemas.account.v2.contact + (:require [taoensso.timbre :as log])) + +(def schema {:name :contact + :primaryKey :whisper-identity + :properties {:address {:type "string" :optional true} + :whisper-identity "string" + :name {:type "string" :optional true} + :photo-path {:type "string" :optional true} + :last-updated {:type "int" :default 0} + :last-online {:type "int" :default 0} + :pending {:type "bool" :default false} + :status {:type "string" :optional true} + :public-key {:type :string + :optional true} + :private-key {:type :string + :optional true} + :dapp? {:type :bool + :default false}}}) + +(defn migration [old-realm new-realm] + (log/debug "migrating contact schema")) \ No newline at end of file diff --git a/src/status_im/data_store/realm/schemas/account/v2/core.cljs b/src/status_im/data_store/realm/schemas/account/v2/core.cljs new file mode 100644 index 0000000000..bd379a1b8a --- /dev/null +++ b/src/status_im/data_store/realm/schemas/account/v2/core.cljs @@ -0,0 +1,29 @@ +(ns status-im.data-store.realm.schemas.account.v2.core + (:require [taoensso.timbre :as log] + [status-im.data-store.realm.schemas.account.v2.contact :as contact] + [status-im.data-store.realm.schemas.account.v1.chat :as chat] + [status-im.data-store.realm.schemas.account.v1.chat-contact :as chat-contact] + [status-im.data-store.realm.schemas.account.v1.command :as command] + [status-im.data-store.realm.schemas.account.v1.discovery :as discovery] + [status-im.data-store.realm.schemas.account.v1.kv-store :as kv-store] + [status-im.data-store.realm.schemas.account.v1.message :as message] + [status-im.data-store.realm.schemas.account.v1.pending-message :as pending-message] + [status-im.data-store.realm.schemas.account.v1.request :as request] + [status-im.data-store.realm.schemas.account.v1.tag :as tag] + [status-im.data-store.realm.schemas.account.v1.user-status :as user-status])) + +(def schema [chat/schema + chat-contact/schema + command/schema + contact/schema + discovery/schema + kv-store/schema + message/schema + pending-message/schema + request/schema + tag/schema + user-status/schema]) + +(defn migration [old-realm new-realm] + (log/debug "migrating v2 account database: " old-realm new-realm) + (contact/migration old-realm new-realm)) \ No newline at end of file