Skip to content

Commit

Permalink
[#7454] fix add basic copy to public chat empty screen state + chat m…
Browse files Browse the repository at this point in the history
…essages-views intro screens for all chats

[#7454] fix add basic copy to public chat empty screen state + chat messages-views intro screens for all chats
  • Loading branch information
bitsikka authored and bitsikka committed Mar 27, 2019
1 parent 6eb806d commit 25e9966
Show file tree
Hide file tree
Showing 12 changed files with 382 additions and 132 deletions.
8 changes: 7 additions & 1 deletion src/status_im/chat/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,16 @@
(let [pending-invite-inviter-name
(group-chats.db/get-pending-invite-inviter-name contacts
chat
current-public-key)]
current-public-key)
inviter-name
(group-chats.db/get-inviter-name contacts
chat
current-public-key)]
(cond-> chat
pending-invite-inviter-name
(assoc :pending-invite-inviter-name pending-invite-inviter-name)
inviter-name
(assoc :inviter-name inviter-name)
:always
(assoc :chat-name (group-chat-name chat))))
(let [{contact-name :name :as contact}
Expand Down
33 changes: 25 additions & 8 deletions src/status_im/chat/models.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,22 @@
[{:keys [current-chat-id] :as db} ui-element]
(update-in db [:chat-ui-props current-chat-id ui-element] not))

(defn join-time-messages-checked
"The key :might-have-join-time-messages? in public chats signals that
the public chat is freshly (re)created and requests for messages to the
mailserver for the topic has not completed yet. Likewise, the key
:join-time-mail-request-id is associated a little bit after, to signal that
the request to mailserver was a success. When request is signalled complete
by mailserver, corresponding event :chat.ui/join-time-messages-checked
dissociates these two fileds via this function, thereby signalling that the
public chat is not fresh anymore."
[{:keys [chats] :as db} chat-id]
(if (:might-have-join-time-messages? (get chats chat-id))
(-> db
(update-in [:chats chat-id] dissoc :join-time-mail-request-id)
(update-in [:chats chat-id] dissoc :might-have-join-time-messages?))
db))

(defn- create-new-chat
[chat-id {:keys [db now]}]
(let [name (get-in db [:contacts/contacts chat-id :name])]
Expand Down Expand Up @@ -84,14 +100,15 @@
"Adds new public group chat to db & realm"
[cofx topic]
(upsert-chat cofx
{:chat-id topic
:is-active true
:name topic
:group-chat true
:contacts #{}
:public? true
:unviewed-messages-count 0
:loaded-unviewed-messages-ids #{}}))
{:chat-id topic
:is-active true
:name topic
:group-chat true
:contacts #{}
:public? true
:might-have-join-time-messages? true
:unviewed-messages-count 0
:loaded-unviewed-messages-ids #{}}))

(fx/defn add-group-chat
"Adds new private group chat to db & realm"
Expand Down
51 changes: 48 additions & 3 deletions src/status_im/chat/subs.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@
[status-im.chat.db :as chat.db]
[status-im.models.transactions :as transactions]
[status-im.utils.platform :as platform]
[status-im.ui.components.bottom-bar.styles :as tabs-styles]
[status-im.ui.components.bottom-bar.styles :as tabs.styles]))
[status-im.utils.universal-links.core :as links]
[status-im.ui.components.bottom-bar.styles :as tabs.styles]
[status-im.ui.components.toolbar.styles :as toolbar.styles]
[status-im.ui.screens.chat.stickers.styles :as stickers.styles]))

(re-frame/reg-sub ::chats :chats)
(re-frame/reg-sub ::access-scope->command-id :access-scope->command-id)
Expand Down Expand Up @@ -53,6 +55,32 @@
(fn [chats [_ chat-id]]
(get chats chat-id)))

(re-frame/reg-sub
:chats/content-layout-height
:<- [:get :content-layout-height]
:<- [:chats/current-chat-ui-prop :input-height]
:<- [:chats/current-chat-ui-prop :input-focused?]
:<- [:get :keyboard-height]
:<- [:chats/current-chat-ui-prop :show-stickers?]
(fn [[home-content-layout-height input-height input-focused? kheight stickers?]]
(- (+ home-content-layout-height tabs.styles/tabs-height)
(if platform/iphone-x?
(* 2 toolbar.styles/toolbar-height)
toolbar.styles/toolbar-height)
(if input-height input-height 0)
(if stickers?
(stickers.styles/stickers-panel-height)
kheight)
(if input-focused?
(cond
platform/iphone-x? 0
platform/ios? tabs.styles/tabs-diff
:else 0)
(cond
platform/iphone-x? (* 2 tabs.styles/minimized-tabs-height)
platform/ios? tabs.styles/tabs-height
:else tabs.styles/minimized-tabs-height)))))

(re-frame/reg-sub
:chats/current-chat-ui-props
:<- [::chat-ui-props]
Expand Down Expand Up @@ -100,7 +128,13 @@
:<- [:chats/active-chats]
:<- [:chats/current-chat-id]
(fn [[chats current-chat-id]]
(get chats current-chat-id)))
(let [current-chat (get chats current-chat-id)
messages (:messages current-chat)]
(if (empty? messages)
(assoc current-chat
:universal-link
(links/generate-link :public-chat :external current-chat-id))
current-chat))))

(re-frame/reg-sub
:chats/current-chat-message
Expand Down Expand Up @@ -143,6 +177,17 @@
(chat.db/messages-with-datemarks-and-statuses messages message-statuses referenced-messages)
chat.db/messages-stream)))

(re-frame/reg-sub
:chats/current-chat-intro-status
:<- [:chats/current-chat]
:<- [:chats/current-chat-messages]
(fn [[{:keys [might-have-join-time-messages?]} messages]]
(if might-have-join-time-messages?
:loading
(if (empty? messages)
:empty
:messages))))

(re-frame/reg-sub
:chats/available-commands
:<- [::get-commands-for-chat]
Expand Down
5 changes: 5 additions & 0 deletions src/status_im/events.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -729,6 +729,11 @@
(fn [{:keys [db]} [_ kvs]]
{:db (chat/set-chat-ui-props db kvs)}))

(handlers/register-handler-fx
:chat.ui/join-time-messages-checked
(fn [{:keys [db]} [_ chat-id]]
{:db (chat/join-time-messages-checked db chat-id)}))

(handlers/register-handler-fx
:chat.ui/show-message-details
(fn [{:keys [db]} [_ details]]
Expand Down
10 changes: 10 additions & 0 deletions src/status_im/group_chats/db.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -44,3 +44,13 @@
(let [inviter-pk (get-inviter-pk my-public-key chat)]
(get-in contacts [inviter-pk :name]
(gfycat/generate-gfy inviter-pk)))))

(defn get-inviter-name
"when the chat is a private group chat in which the user has been
invited and didn't accept the invitation yet, return inviter-name"
[contacts chat my-public-key]
(when (and (models.chat/group-chat? chat)
(joined? my-public-key chat))
(let [inviter-pk (get-inviter-pk my-public-key chat)]
(get-in contacts [inviter-pk :name]
(gfycat/generate-gfy inviter-pk)))))
68 changes: 55 additions & 13 deletions src/status_im/mailserver/core.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -276,9 +276,28 @@
(log/debug "Adjusting mailserver request" "from:" from "adjusted-from:" adjusted-from)
adjusted-from))

(fx/defn handle-request-success [{:keys [db]} {:keys [request-id]}]
(fx/defn handle-request-success [{{:keys [chats] :as db} :db}
{:keys [request-id topics]}]
(when (:mailserver/current-request db)
{:db (assoc-in db [:mailserver/current-request :request-id] request-id)}))
(let [fresh-public-chats (into {}
(comp (filter (fn [[k v]] (:is-active v)))
(filter (fn [[k v]] (:public? v)))
(filter (fn [[k v]] (:might-have-join-time-messages? v))))
chats)
by-topic-fresh-chats (reduce-kv
#(assoc %1 (transport.utils/get-topic %2) %3)
{}
fresh-public-chats)
chats-in-this-request (select-keys by-topic-fresh-chats (vec topics))]
(if (seq chats-in-this-request)
{:db (-> db
(assoc-in [:mailserver/current-request :request-id] request-id)
((fn [db] (reduce
(fn [db chat]
(assoc-in db [:chats (:chat-id chat) :join-time-mail-request-id] request-id))
db
(vals chats-in-this-request)))))}
{:db (assoc-in db [:mailserver/current-request :request-id] request-id)}))))

(defn request-messages! [web3 {:keys [sym-key-id address]} {:keys [topics cursor to from] :as request}]
;; Add some room to from, unless we break day boundaries so that messages that have
Expand All @@ -303,7 +322,7 @@
(if-not error
(do
(log/info "mailserver: messages request success for topic " topics "from" from "to" to)
(re-frame/dispatch [:mailserver.callback/request-success {:request-id request-id}]))
(re-frame/dispatch [:mailserver.callback/request-success {:request-id request-id :topics topics}]))
(do
(log/error "mailserver: messages request error for topic " topics ": " error)
(utils/set-timeout #(re-frame/dispatch [:mailserver.callback/resend-request {:request-id nil}])
Expand Down Expand Up @@ -523,17 +542,40 @@
:mailserver/pending-requests))})

(fx/defn handle-request-completed
[cofx event]
[{{:keys [chats] :as db} :db :as cofx}
{:keys [requestID lastEnvelopeHash cursor errorMessage] :as event}]
(when (accounts.db/logged-in? cofx)
(let [error (:errorMessage event)]
(if (empty? error)
(fx/merge
cofx
{:mailserver/increase-limit []}
(update-mailserver-topics {:request-id (:requestID event)
:cursor (:cursor event)}))

(handle-request-error cofx error)))))
(if (empty? errorMessage)
(let [fresh-chats-in-request (into []
(comp (filter :is-active)
(filter :public?)
(filter #(= requestID (:join-time-mail-request-id %))))
(vals chats))]
(if (seq fresh-chats-in-request)
(let [dispatch-list (map #(identity [:chat.ui/join-time-messages-checked (:chat-id %)])
fresh-chats-in-request)
dispatch-later-vec (vec (map #(identity {:ms 1000
:dispatch [:chat.ui/join-time-messages-checked (:chat-id %)]})
fresh-chats-in-request))]
(if (= lastEnvelopeHash "0x0000000000000000000000000000000000000000000000000000000000000000")
(fx/merge
cofx
{:mailserver/increase-limit []
:dispatch-n dispatch-list}
(update-mailserver-topics {:request-id requestID
:cursor cursor}))
(fx/merge
cofx
{:mailserver/increase-limit []
:dispatch-later dispatch-later-vec}
(update-mailserver-topics {:request-id requestID
:cursor cursor}))))
(fx/merge
cofx
{:mailserver/increase-limit []}
(update-mailserver-topics {:request-id requestID
:cursor cursor}))))
(handle-request-error cofx errorMessage))))

(fx/defn show-request-error-popup
[{:keys [db]}]
Expand Down
6 changes: 6 additions & 0 deletions src/status_im/ui/components/chat_icon/screen.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,12 @@
:default-chat-icon (styles/default-chat-icon-profile colors/default-chat-color size)
:default-chat-icon-text styles/default-chat-icon-text}])

(defn chat-intro-icon-view [icon-text chat-id styles]
(let [photo-path (re-frame.core/subscribe [:contacts/chat-photo chat-id])]
(if-not (string/blank? @photo-path)
[photos/photo @photo-path styles]
[default-chat-icon icon-text styles])))

(defn profile-icon-view [photo-path name color edit? size override-styles]
(let [styles (merge {:container {:width size :height size}
:online-view styles/online-view-profile
Expand Down
75 changes: 55 additions & 20 deletions src/status_im/ui/screens/chat/styles/main.cljs
Original file line number Diff line number Diff line change
Expand Up @@ -191,9 +191,6 @@
{:opacity opacity
:flex 1})

(def empty-chat-container-one-to-one
{:margin-top 10})

(def empty-chat-container
{:flex 1
:flex-direction :column
Expand All @@ -202,36 +199,74 @@
:padding-vertical 50
:margin-right 6})

(def empty-chat-text
{:color colors/gray
:width 280
:text-align :center})
(defn intro-header-container
[height status no-messages]
(let [adjusted-height (if (< height 280) 324 height)]
(if (or no-messages (= status (or :loading :empty)))
{:flex 1
:flex-direction :column
:justify-content :center
:align-items :center
:height adjusted-height
:padding-horizontal 32}
{:flex 1
:flex-direction :column
:justify-content :center
:align-items :center
:padding-horizontal 32})))

(defn intro-header-icon [diameter color]
{:width diameter
:height diameter
:align-items :center
:justify-content :center
:border-radius (/ diameter 2)
:background-color color})

(def empty-chat-text-name
{:margin-bottom 5})
(def intro-header-icon-text
{:color colors/white
:font-size 52
:font-weight "700"
:opacity 0.8
:line-height 72})

(def intro-header-chat-name
{:font-size 22
:font-weight "700"
:line-height 28
:margin-bottom 8
:color colors/black})

(def intro-header-description-container
{:flex-wrap :wrap
:align-items :flex-start
:flex-direction :row})

(def join-button
{:margin-top 24
:margin-bottom 15})
(def intro-header-description
{:color colors/gray
:line-height 22
:text-align :center})

(def group-chat-icon
{:color colors/white
:font-size 40
:font-weight "700"})

(def group-chat-join-footer
{:position :absolute
:justify-content :center
:margin-bottom 30
:bottom 0})

(def group-chat-join-name
{:typography :header})
{:flex 1
:justify-content :center})

(def group-chat-join-container
{:flex 1
:align-items :center
:justify-content :center})

(def group-chat-join-name
{:typography :header})

(def join-button
{:margin-bottom 15})

(def decline-chat
{:color colors/blue})
{:color colors/blue
:margin-bottom 40})
Loading

0 comments on commit 25e9966

Please sign in to comment.