Skip to content

Commit

Permalink
Enable stickers on all envs. Use contenthash to identify stickers
Browse files Browse the repository at this point in the history
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
  • Loading branch information
jeluard committed Jul 11, 2019
1 parent 433f840 commit 28f7ea0
Show file tree
Hide file tree
Showing 20 changed files with 86 additions and 65 deletions.
1 change: 0 additions & 1 deletion .env
Expand Up @@ -17,7 +17,6 @@ POW_TARGET=0.002
POW_TIME=1
SNOOPY=0
RPC_NETWORKS_ONLY=0
STICKERS_ENABLED=1
PARTITIONED_TOPIC=0
CONTRACT_NODES=1
MOBILE_UI_FOR_DESKTOP=0
Expand Down
1 change: 0 additions & 1 deletion .env.jenkins
Expand Up @@ -17,7 +17,6 @@ POW_TARGET=0.002
POW_TIME=1
SNOOPY=0
RPC_NETWORKS_ONLY=0
STICKERS_ENABLED=1
PARTITIONED_TOPIC=0
CONTRACT_NODES=1
MOBILE_UI_FOR_DESKTOP=0
1 change: 0 additions & 1 deletion .env.nightly
Expand Up @@ -15,7 +15,6 @@ POW_TARGET=0.002
POW_TIME=1
SNOOPY=0
RPC_NETWORKS_ONLY=0
STICKERS_ENABLED=0
PARTITIONED_TOPIC=0
CONTRACT_NODES=1
MOBILE_UI_FOR_DESKTOP=0
1 change: 0 additions & 1 deletion .env.prod
Expand Up @@ -15,6 +15,5 @@ POW_TARGET=0.002
POW_TIME=1
SNOOPY=0
RPC_NETWORKS_ONLY=1
STICKERS_ENABLED=0
PARTITIONED_TOPIC=0
MOBILE_UI_FOR_DESKTOP=0
6 changes: 3 additions & 3 deletions src/status_im/chat/models/input.cljs
Expand Up @@ -152,12 +152,12 @@
:text message-text})})))

(fx/defn send-sticker-fx
[{:keys [db] :as cofx} {:keys [uri pack]} current-chat-id]
(when-not (string/blank? uri)
[{:keys [db] :as cofx} {:keys [hash pack]} current-chat-id]
(when-not (string/blank? hash)
(chat.message/send-message cofx {:chat-id current-chat-id
:content-type constants/content-type-sticker
:content (cond-> {:chat-id current-chat-id
:uri uri
:hash hash
:pack pack
:text "Update to latest version to see a nice sticker here!"})})))

Expand Down
4 changes: 2 additions & 2 deletions src/status_im/events.cljs
Expand Up @@ -824,10 +824,10 @@

(handlers/register-handler-fx
:chat/send-sticker
(fn [{{:keys [current-chat-id] :account/keys [account]} :db :as cofx} [_ {:keys [uri] :as sticker}]]
(fn [{{:keys [current-chat-id] :account/keys [account]} :db :as cofx} [_ {:keys [hash] :as sticker}]]
(fx/merge
cofx
(accounts/update-recent-stickers (conj (remove #(= uri %) (:recent-stickers account)) uri))
(accounts/update-recent-stickers (conj (remove #(= hash %) (:recent-stickers account)) hash))
(chat.input/send-sticker-fx sticker current-chat-id))))

(handlers/register-handler-fx
Expand Down
16 changes: 10 additions & 6 deletions src/status_im/stickers/core.cljs
Expand Up @@ -99,12 +99,18 @@
(assoc :stickers/selected-pack id))}
(accounts/update-stickers (conj (:stickers account) (pr-str pack))))))

(defn valid-sticker? [sticker]
(contains? sticker :hash))

(fx/defn load-sticker-pack-success
[{:keys [db] :as cofx} edn-string id price open?]
(let [pack (assoc (get (edn/read-string edn-string) 'meta)
:id id :price price)]
(let [{:keys [stickers] :as pack} (assoc (get (edn/read-string edn-string) 'meta)
:id id :price price)]
(fx/merge cofx
{:db (assoc-in db [:stickers/packs id] pack)}
{:db (cond-> db
(and (seq stickers)
(every? valid-sticker? stickers))
(assoc-in [:stickers/packs id] pack))}
#(when open?
(navigation/navigate-to-cofx % :stickers-pack-modal pack)))))

Expand All @@ -127,9 +133,7 @@
hash)
:success-event-creator
(fn [o]
[:stickers/load-sticker-pack-success o id price open?])
:failure-event-creator
(constantly nil)}})
[:stickers/load-sticker-pack-success o id price open?])}})

(fx/defn load-packs
[{:keys [db]}]
Expand Down
6 changes: 3 additions & 3 deletions src/status_im/subs.cljs
Expand Up @@ -893,9 +893,9 @@
(fn [[{:keys [id]} packs]]
(first (filter #(= (:id %) id) packs))))

(defn find-pack-id-for-uri [sticker-uri packs]
(defn find-pack-id-for-hash [sticker-uri packs]
(some (fn [{:keys [stickers id]}]
(when (some #(= sticker-uri (:uri %)) stickers)
(when (some #(= sticker-uri (:hash %)) stickers)
id))
packs))

Expand All @@ -904,7 +904,7 @@
:<- [:account/account]
:<- [:stickers/installed-packs-vals]
(fn [[{:keys [recent-stickers]} packs]]
(map (fn [uri] {:uri uri :pack (find-pack-id-for-uri uri packs)}) recent-stickers)))
(map (fn [hash] {:hash hash :pack (find-pack-id-for-hash hash packs)}) recent-stickers)))

;;EXTENSIONS ===========================================================================================================

Expand Down
2 changes: 1 addition & 1 deletion src/status_im/transport/db.cljs
Expand Up @@ -104,7 +104,7 @@
:req-opt [:message.content/response-to]))
(spec/def :message.command/content (spec/keys :req-un [:message.content/command-path :message.content/params]))

(spec/def :message.sticker/content (spec/keys :req-un [:message.content/uri]))
(spec/def :message.sticker/content (spec/keys :req-un [:message.content/hash]))

(defmulti content-type :content-type)

Expand Down
2 changes: 1 addition & 1 deletion src/status_im/ui/screens/chat/input/input.cljs
Expand Up @@ -201,7 +201,7 @@
[reply-message-view]
[react/view {:style style/input-container}
[input-view {:single-line-input? single-line-input? :set-text set-text :state-text state-text}]
(when (and config/stickers-enabled? input-text-empty?)
(when input-text-empty?
[stickers/button show-stickers?])
(if input-text-empty?
[commands-button]
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/ui/screens/chat/message/message.cljs
Expand Up @@ -15,6 +15,7 @@
[status-im.ui.screens.chat.photos :as photos]
[status-im.ui.screens.chat.styles.message.message :as style]
[status-im.ui.screens.chat.utils :as chat.utils]
[status-im.utils.contenthash :as contenthash]
[status-im.utils.platform :as platform])
(:require-macros [status-im.utils.views :refer [defview letsubs]]))

Expand Down Expand Up @@ -144,7 +145,7 @@
[wrapper {:keys [content] :as message}]
[wrapper message
[react/image {:style {:margin 10 :width 140 :height 140}
:source {:uri (:uri content)}}]])
:source {:uri (contenthash/url (:hash content))}}]])

(defmethod message-content :default
[wrapper {:keys [content-type] :as message}]
Expand Down
46 changes: 23 additions & 23 deletions src/status_im/ui/screens/chat/stickers/views.cljs
@@ -1,13 +1,15 @@
(ns status-im.ui.screens.chat.stickers.views
(:require-macros [status-im.utils.views :refer [defview letsubs]])
(:require [re-frame.core :as re-frame]
[reagent.core :as reagent]
[status-im.stickers.core :as stickers]
[status-im.ui.components.react :as react]
[status-im.ui.components.icons.vector-icons :as vector-icons]
[status-im.ui.components.colors :as colors]
[status-im.i18n :as i18n]
[status-im.ui.screens.chat.stickers.styles :as styles]
[status-im.ui.components.animation :as anim]
[reagent.core :as reagent]
[status-im.utils.contenthash :as contenthash]
[status-im.utils.platform :as platform]))

(def icon-size 28)
Expand Down Expand Up @@ -43,13 +45,14 @@
[react/view {:width window-width :flex 1}
[react/scroll-view
[react/view {:style styles/stickers-panel}
(for [{:keys [uri] :as sticker} stickers]
^{:key uri}
(for [{:keys [hash pack] :as sticker} stickers]
^{:key (str hash)}
[react/touchable-highlight {:style {:height 75 :width 75 :margin 5}
:on-press #(re-frame/dispatch [:chat/send-sticker sticker])}
[react/image {:style {:resize-mode :cover :width "100%" :height "100%"}
:accessibility-label :sticker-icon
:source {:uri uri}}]])]]])
[react/view
[react/image {:style {:resize-mode :cover :width "100%" :height "100%"}
:accessibility-label :sticker-icon
:source {:uri (contenthash/url (str "0x" hash))}}]]])]]])

(defview recent-stickers-panel [window-width]
(letsubs [stickers [:stickers/recent]]
Expand Down Expand Up @@ -83,18 +86,19 @@
{:component-will-update (fn [_ [_ installed-packs selected-pack]]
(update-scroll-position @ref installed-packs selected-pack window-width))
:component-did-mount #(update-scroll-position @ref installed-packs selected-pack window-width)}
[react/scroll-view {:style {:flex 1} :horizontal true :paging-enabled true
:ref #(reset! ref %)
:shows-horizontal-scroll-indicator false
:on-momentum-scroll-end #(on-scroll % installed-packs window-width)
:scrollEventThrottle 8
:on-scroll #(reset! scroll-x (.-nativeEvent.contentOffset.x %))
:on-layout #(reset! content-width (-> % .-nativeEvent .-layout .-width))}
^{:key "recent"}
[recent-stickers-panel @content-width]
(for [{:keys [stickers id]} installed-packs]
^{:key (str "sticker" id)}
[stickers-panel (map #(assoc % :pack id) stickers) @content-width])]))
(let [width @content-width]
[react/scroll-view {:style {:flex 1} :horizontal true :paging-enabled true
:ref #(reset! ref %)
:shows-horizontal-scroll-indicator false
:on-momentum-scroll-end #(on-scroll % installed-packs window-width)
:scrollEventThrottle 8
:on-scroll #(reset! scroll-x (.-nativeEvent.contentOffset.x %))
:on-layout #(reset! content-width (-> % .-nativeEvent .-layout .-width))}
^{:key "recent"}
[recent-stickers-panel width]
(for [{:keys [stickers id]} installed-packs]
^{:key (str "sticker" id)}
[stickers-panel (map #(assoc % :pack id) (filter stickers/valid-sticker? stickers)) width])])))

(defn pack-icon [{:keys [id on-press background-color]
:or {on-press #(re-frame/dispatch [:stickers/select-pack id])}}
Expand All @@ -104,10 +108,6 @@
[react/view {:style (styles/pack-icon background-color icon-size icon-horizontal-margin)}
icon]]])

(defn pack-stickers [packs pack-id]
(let [{:keys [stickers id]} (some #(when (= pack-id (:id %)) %) packs)]
(map #(assoc % :pack id) stickers)))

(defn show-panel-anim
[bottom-anim-value alpha-value]
(anim/start
Expand Down Expand Up @@ -157,5 +157,5 @@
[pack-icon {:id id
:background-color colors/white}
[react/image {:style {:width icon-size :height icon-size :border-radius (/ icon-size 2)}
:source {:uri thumbnail}}]])]
:source {:uri (contenthash/url thumbnail)}}]])]
[scroll-indicator]]]]]))
5 changes: 3 additions & 2 deletions src/status_im/ui/screens/desktop/main/chat/views.cljs
Expand Up @@ -27,7 +27,8 @@
[status-im.ui.screens.desktop.main.chat.emoji :as emoji]
[status-im.ui.components.icons.vector-icons :as icons]
[status-im.ui.screens.chat.message.gap :as gap]
[status-im.ui.components.animation :as animation])
[status-im.ui.components.animation :as animation]
[status-im.utils.contenthash :as contenthash])
(:require-macros [status-im.utils.views :as views]))

(defn toolbar-chat-view
Expand Down Expand Up @@ -175,7 +176,7 @@
[_ _ {:keys [content] :as message}]
[message-wrapper message
[react/image {:style {:margin 10 :width 140 :height 140}
:source {:uri (:uri content)}}]])
:source {:uri (contenthash/url (:hash content))}}]])

(views/defview message-content-status [text message]
[react/view
Expand Down
24 changes: 13 additions & 11 deletions src/status_im/ui/screens/desktop/main/tabs/home/views.cljs
Expand Up @@ -17,7 +17,8 @@
[reagent.core :as reagent]
[status-im.ui.components.action-button.styles :as action-button.styles]
[status-im.ui.components.action-button.action-button :as action-button]
[status-im.utils.config :as config]))
[status-im.utils.config :as config]
[status-im.utils.contenthash :as contenthash]))

(views/defview chat-list-item-inner-view
[{:keys [chat-id name group-chat
Expand Down Expand Up @@ -54,16 +55,17 @@
:number-of-lines 1
:style (styles/chat-name current?)}
name]]
(if (and (:uri (:content last-message) (= constants/content-type-sticker (:content-type last-message))))
[react/image {:style {:margin 2 :width 30 :height 30}
:source {:uri (:uri (:content last-message))}}]
[react/text {:ellipsize-mode :tail
:number-of-lines 1
:style styles/chat-last-message}
(if (= constants/content-type-command (:content-type last-message))
[chat-item/command-short-preview last-message]
(or (:text last-message-content)
(i18n/label :no-messages-yet)))])]
(let [uri (contenthash/url (:content last-message))]
(if (and uri (= constants/content-type-sticker (:content-type last-message)))
[react/image {:style {:margin 2 :width 30 :height 30}
:source {:uri uri}}]
[react/text {:ellipsize-mode :tail
:number-of-lines 1
:style styles/chat-last-message}
(if (= constants/content-type-command (:content-type last-message))
[chat-item/command-short-preview last-message]
(or (:text last-message-content)
(i18n/label :no-messages-yet)))]))]
[react/view {:style styles/timestamp}
[chat-item/message-timestamp (:timestamp last-message)]
(when (pos? unviewed-messages-count)
Expand Down
3 changes: 2 additions & 1 deletion src/status_im/ui/screens/home/views/inner_item.cljs
Expand Up @@ -12,6 +12,7 @@
[status-im.ui.components.list.views :as list]
[status-im.ui.components.react :as react]
[status-im.ui.screens.home.styles :as styles]
[status-im.utils.contenthash :as contenthash]
[status-im.utils.core :as utils]
[status-im.utils.datetime :as time])
(:require-macros [status-im.utils.views :refer [defview letsubs]]))
Expand All @@ -36,7 +37,7 @@

(= constants/content-type-sticker content-type)
[react/image {:style {:margin 2 :width 30 :height 30}
:source {:uri (:uri content)}}]
:source {:uri (contenthash/url (:hash content))}}]

(string/blank? (:text content))
[react/text {:style styles/last-message-text}
Expand Down
13 changes: 7 additions & 6 deletions src/status_im/ui/screens/stickers/views.cljs
Expand Up @@ -9,6 +9,7 @@
[status-im.ui.components.styles :as components.styles]
[status-im.ui.components.toolbar.view :as toolbar]
[status-im.ui.screens.stickers.styles :as styles]
[status-im.utils.contenthash :as contenthash]
[status-im.utils.money :as money])
(:require-macros [status-im.utils.views :refer [defview letsubs]]))

Expand Down Expand Up @@ -47,9 +48,9 @@
(defn pack-badge [{:keys [name author price thumbnail preview id installed owned pending] :as pack}]
[react/touchable-highlight {:on-press #(re-frame/dispatch [:navigate-to :stickers-pack pack])}
[react/view {:margin-bottom 27}
[react/image {:style {:height 200 :border-radius 20} :source {:uri preview}}]
[react/image {:style {:height 200 :border-radius 20} :source {:uri (contenthash/url preview)}}]
[react/view {:height 64 :align-items :center :flex-direction :row}
[thumbnail-icon thumbnail 40]
[thumbnail-icon (contenthash/url thumbnail) 40]
[react/view {:padding-horizontal 16 :flex 1}
[react/text {:accessibility-label :sticker-pack-name} name]
[react/text {:style {:color colors/gray :margin-top 6}
Expand Down Expand Up @@ -79,7 +80,7 @@
[react/keyboard-avoiding-view components.styles/flex
[toolbar/simple-toolbar nil modal?]
[react/view {:height 74 :align-items :center :flex-direction :row :padding-horizontal 16}
[thumbnail-icon thumbnail 64]
[thumbnail-icon (contenthash/url thumbnail) 64]
[react/view {:padding-horizontal 16 :flex 1}
[react/text {:style {:typography :header}} name]
[react/text {:style {:color colors/gray :margin-top 6}} author]]
Expand All @@ -89,10 +90,10 @@
[react/view {:style {:padding-top 8 :flex 1}}
[react/scroll-view {:keyboard-should-persist-taps :handled :style {:flex 1}}
[react/view {:flex-direction :row :flex-wrap :wrap}
(for [{:keys [uri]} stickers]
^{:key uri}
(for [{:keys [hash]} stickers]
^{:key hash}
[react/image {:style (styles/sticker-image sticker-icon-size)
:source {:uri uri}}])]]]]]))
:source {:uri (contenthash/url hash)}}])]]]]]))

(defview pack []
[pack-main false])
Expand Down
1 change: 0 additions & 1 deletion src/status_im/utils/config.cljs
Expand Up @@ -27,7 +27,6 @@
(def cached-webviews-enabled? (enabled? (get-config :CACHED_WEBVIEWS_ENABLED 0)))
(def snoopy-enabled? (enabled? (get-config :SNOOPY 0)))
(def extensions-enabled? (enabled? (get-config :EXTENSIONS 0)))
(def stickers-enabled? (enabled? (get-config :STICKERS_ENABLED 0)))
(def hardwallet-enabled? (enabled? (get-config :HARDWALLET_ENABLED 0)))
(def dev-build? (enabled? (get-config :DEV_BUILD 0)))
(def erc20-contract-warnings-enabled? (enabled? (get-config :ERC20_CONTRACT_WARNINGS)))
Expand Down
7 changes: 7 additions & 0 deletions src/status_im/utils/contenthash.cljs
Expand Up @@ -5,6 +5,7 @@
(:require [alphabase.base58 :as b58]
[alphabase.hex :as hex]
[clojure.string :as string]
[status-im.ethereum.core :as ethereum]
[status-im.ipfs.core :as ipfs]
[status-im.utils.fx :as fx]))

Expand Down Expand Up @@ -54,6 +55,12 @@
hex/decode
b58/encode))})))

(defn url [hex]
(let [{:keys [namespace hash]} (decode (ethereum/normalized-address hex))]
(case namespace
:ipfs (str "https://ipfs.infura.io/ipfs/" hash)
"")))

(fx/defn cat
[cofx {:keys [contenthash on-success on-failure]}]
(let [{:keys [namespace hash]} (decode contenthash)]
Expand Down
2 changes: 2 additions & 0 deletions test/cljs/status_im/test/runner.cljs
Expand Up @@ -44,6 +44,7 @@
[status-im.test.pairing.core]
[status-im.test.search.core]
[status-im.test.sign-in.flow]
[status-im.test.stickers.core]
[status-im.test.transport.core]
[status-im.test.tribute-to-talk.core]
[status-im.test.tribute-to-talk.db]
Expand Down Expand Up @@ -127,6 +128,7 @@
'status-im.test.pairing.core
'status-im.test.search.core
'status-im.test.sign-in.flow
'status-im.test.stickers.core
'status-im.test.signing.core
'status-im.test.signing.gas
'status-im.test.transport.core
Expand Down

0 comments on commit 28f7ea0

Please sign in to comment.