Calls to gfycat and identicon made async in few places

Signed-off-by: Volodymyr Kozieiev <vkjr.sp@gmail.com>
This commit is contained in:
Volodymyr Kozieiev 2019-11-28 12:00:29 +02:00
parent 0cca662380
commit 7168eada1c
No known key found for this signature in database
GPG Key ID: 82B04968DF4C0535
20 changed files with 228 additions and 27 deletions

View File

@ -143,7 +143,10 @@ var TopLevel = {
"extPost" : function () {}, "extPost" : function () {},
"extractGroupMembershipSignatures" : function () {}, "extractGroupMembershipSignatures" : function () {},
"identicon": function() {}, "identicon": function() {},
"identiconAsync": function() {},
"generateAlias": function() {}, "generateAlias": function() {},
"generateAliasAsync": function() {},
"generateAliasAndIdenticonAsync": function() {},
"fallbacks" : function () {}, "fallbacks" : function () {},
"fetch" : function () {}, "fetch" : function () {},
"floor" : function () {}, "floor" : function () {},

View File

@ -1144,11 +1144,76 @@ class StatusModule extends ReactContextBaseJavaModule implements LifecycleEventL
return Statusgo.generateAlias(seed); return Statusgo.generateAlias(seed);
} }
@ReactMethod
public void generateAliasAsync(final String seed, final Callback callback) {
Log.d(TAG, "generateAliasAsync");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.generateAlias(seed);
Log.d(TAG, res);
callback.invoke(res);
}
};
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod(isBlockingSynchronousMethod = true) @ReactMethod(isBlockingSynchronousMethod = true)
public String identicon(final String seed) { public String identicon(final String seed) {
return Statusgo.identicon(seed); return Statusgo.identicon(seed);
} }
@ReactMethod
public void identiconAsync(final String seed, final Callback callback) {
Log.d(TAG, "identiconAsync");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
String res = Statusgo.identicon(seed);
Log.d(TAG, res);
callback.invoke(res);
}
};
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod
public void generateAliasAndIdenticonAsync(final String seed, final Callback callback) {
Log.d(TAG, "generateAliasAndIdenticonAsync");
if (!checkAvailability()) {
callback.invoke(false);
return;
}
Runnable r = new Runnable() {
@Override
public void run() {
String resIdenticon = Statusgo.identicon(seed);
String resAlias = Statusgo.generateAlias(seed);
Log.d(TAG, resIdenticon);
Log.d(TAG, resAlias);
callback.invoke(resAlias, resIdenticon);
}
};
StatusThreadPoolExecutor.getInstance().execute(r);
}
@ReactMethod @ReactMethod
public void getNodesFromContract(final String rpcEndpoint, final String contractAddress, final Callback callback) { public void getNodesFromContract(final String rpcEndpoint, final String contractAddress, final Callback callback) {

View File

@ -653,13 +653,38 @@ void RCTStatus::chaosModeUpdate(bool on, double callbackId) {
QString RCTStatus::generateAlias(QString publicKey) { QString RCTStatus::generateAlias(QString publicKey) {
Q_D(RCTStatus); Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::generateAlias call"; qCDebug(RCTSTATUS) << "::generateAlias call";
// return GenerateGfycat(publicKey.toUtf8().data()); return "";
return "test"; }
void RCTStatus::generateAliasAsync(QString publicKey, double callbackId) {
Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::generateAliasAsync call";
QByteArray b = publicKey.toUtf8();
const char *result = GenerateAlias({b.data(), b.length()});
qCDebug(RCTSTATUS) << "::generateAliasAsync call result"<<result;
d->bridge->invokePromiseCallback(callbackId, QVariantList{result});
} }
QString RCTStatus::identicon(QString publicKey) { QString RCTStatus::identicon(QString publicKey) {
Q_D(RCTStatus); Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::identicon call"; qCDebug(RCTSTATUS) << "::identicon call";
// return Identicon(publicKey.toUtf8().data()); return "";
return "test"; }
void RCTStatus::identiconAsync(QString publicKey, double callbackId) {
Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::identiconAsync call";
QByteArray b = publicKey.toUtf8();
const char *result = Identicon({b.data(), b.length()});
qCDebug(RCTSTATUS) << "::identiconAsync call result"<<result;
d->bridge->invokePromiseCallback(callbackId, QVariantList{result});
}
void RCTStatus::generateAliasAndIdenticonAsync(QString publicKey, double callbackId) {
Q_D(RCTStatus);
qCDebug(RCTSTATUS) << "::generateAliasAndIdenticonAsync call";
QByteArray pubKey = publicKey.toUtf8();
const char *alias = GenerateAlias({pubKey.data(), pubKey.length()});
const char *identicon = Identicon({pubKey.data(), pubKey.length()});
d->bridge->invokePromiseCallback(callbackId, QVariantList{alias, identicon});
} }

View File

@ -93,7 +93,10 @@ public:
Q_INVOKABLE static void statusGoEventCallback(const char *event); Q_INVOKABLE static void statusGoEventCallback(const char *event);
Q_INVOKABLE QString identicon(QString publicKey); Q_INVOKABLE QString identicon(QString publicKey);
Q_INVOKABLE void identiconAsync(QString publicKey, double callbackId);
Q_INVOKABLE QString generateAlias(QString publicKey); Q_INVOKABLE QString generateAlias(QString publicKey);
Q_INVOKABLE void generateAliasAsync(QString publicKey, double callbackId);
Q_INVOKABLE void generateAliasAndIdenticonAsync(QString publicKey, double callbackId);
void emitStatusGoEvent(QString event); void emitStatusGoEvent(QString event);

View File

@ -585,10 +585,38 @@ RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(generateAlias:(NSString *)publicKey) {
return StatusgoGenerateAlias(publicKey); return StatusgoGenerateAlias(publicKey);
} }
RCT_EXPORT_METHOD(generateAliasAsync:(NSString *)publicKey
callback:(RCTResponseSenderBlock)callback) {
#if DEBUG
NSLog(@"generateAliasAsync() method called");
#endif
NSString *result = StatusgoGenerateAlias(publicKey);
callback(@[result]);
}
RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(identicon:(NSString *)publicKey) { RCT_EXPORT_BLOCKING_SYNCHRONOUS_METHOD(identicon:(NSString *)publicKey) {
return StatusgoIdenticon(publicKey); return StatusgoIdenticon(publicKey);
} }
RCT_EXPORT_METHOD(identiconAsync:(NSString *)publicKey
callback:(RCTResponseSenderBlock)callback) {
#if DEBUG
NSLog(@"identiconAsync() method called");
#endif
NSString *result = StatusgoIdenticon(publicKey);
callback(@[result]);
}
RCT_EXPORT_METHOD(generateAliasAndIdenticonAsync:(NSString *)publicKey
callback:(RCTResponseSenderBlock)callback) {
#if DEBUG
NSLog(@"generateAliasAndIdenticonAsync() method called");
#endif
NSString *identiconResult = StatusgoIdenticon(publicKey);
NSString *aliasResult = StatusgoGenerateAlias(publicKey);
callback(@[aliasResult, identiconResult]);
}
RCT_EXPORT_METHOD(callPrivateRPC:(NSString *)payload RCT_EXPORT_METHOD(callPrivateRPC:(NSString *)payload
callback:(RCTResponseSenderBlock)callback) { callback:(RCTResponseSenderBlock)callback) {
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{

View File

@ -36,5 +36,5 @@
(def net-info #js {:default #js {}}) (def net-info #js {:default #js {}})
(def react-native-mail #js {:mail (fn [])}) (def react-native-mail #js {:mail (fn [])})
(def async-storage #js {}) (def async-storage #js {})
(def back-handler #js {}) (def back-handler #js {:addEventListener (fn [])})
(def safe-area-context #js {}) (def safe-area-context #js {})

View File

@ -3,6 +3,7 @@
[status-im.multiaccounts.model :as multiaccounts.model] [status-im.multiaccounts.model :as multiaccounts.model]
[status-im.transport.filters.core :as transport.filters] [status-im.transport.filters.core :as transport.filters]
[status-im.contact.core :as contact.core] [status-im.contact.core :as contact.core]
[status-im.contact.db :as contact.db]
[status-im.data-store.chats :as chats-store] [status-im.data-store.chats :as chats-store]
[status-im.data-store.messages :as messages-store] [status-im.data-store.messages :as messages-store]
[status-im.ethereum.json-rpc :as json-rpc] [status-im.ethereum.json-rpc :as json-rpc]
@ -226,6 +227,8 @@
(transport.filters/load-chat chat-id)) (transport.filters/load-chat chat-id))
(when platform/desktop? (when platform/desktop?
(mark-messages-seen chat-id)) (mark-messages-seen chat-id))
(when (and (one-to-one-chat? cofx chat-id) (not (contact.db/contact-exists? db chat-id)))
(contact.core/create-contact chat-id))
(tribute-to-talk/check-tribute chat-id))) (tribute-to-talk/check-tribute chat-id)))
(fx/defn navigate-to-chat (fx/defn navigate-to-chat

View File

@ -147,7 +147,10 @@
(get-in db [:contacts/contacts public-key])) (get-in db [:contacts/contacts public-key]))
(assoc :tribute-to-talk (or tribute-to-talk (assoc :tribute-to-talk (or tribute-to-talk
{:disabled? true})))] {:disabled? true})))]
{:db (assoc-in db [:contacts/contacts public-key] contact)})) {:db (assoc-in db [:contacts/contacts public-key] contact)
:insert-identicons [[public-key [:contacts/contacts public-key :identicon]]]
:insert-gfycats [[public-key [:contacts/contacts public-key :name]]
[public-key [:contacts/contacts public-key :alias]]]}))
(defn add-ens-names [contacts names] (defn add-ens-names [contacts names]
(reduce-kv (fn [acc public-key-keyword result] (reduce-kv (fn [acc public-key-keyword result]

View File

@ -120,6 +120,10 @@
(assoc % :admin? true) (assoc % :admin? true)
%))))) %)))))
(defn contact-exists?
[db public-key]
(get-in db [:contacts/contacts public-key]))
(defn added? (defn added?
([{:keys [system-tags]}] ([{:keys [system-tags]}]
(contains? system-tags :contact/added)) (contains? system-tags :contact/added))

View File

@ -1565,3 +1565,13 @@
request-command request-command
{:asset (name symbol) {:asset (name symbol)
:amount (str (money/internal->formatted amount symbol decimals))}))))) :amount (str (money/internal->formatted amount symbol decimals))})))))
(handlers/register-handler-fx
:identicon-generated
(fn [{:keys [db]} [_ path identicon]]
{:db (assoc-in db path identicon)}))
(handlers/register-handler-fx
:gfycat-generated
(fn [{:keys [db]} [_ path gfycat]]
{:db (assoc-in db path gfycat)}))

View File

@ -54,8 +54,18 @@
(let [{:keys [selected-id address key-code]} (:intro-wizard db) (let [{:keys [selected-id address key-code]} (:intro-wizard db)
{:keys [address]} (get-selected-multiaccount cofx) {:keys [address]} (get-selected-multiaccount cofx)
hashed-password (ethereum/sha3 (security/safe-unmask-data key-code)) hashed-password (ethereum/sha3 (security/safe-unmask-data key-code))
callback #(re-frame/dispatch [::store-multiaccount-success key-code %])] callback (fn [result]
(log/debug "create-multiaccount") (let [derived-data (types/json->clj result)
publicKey (get-in derived-data [constants/path-whisper-keyword :publicKey])]
(status/gfycat-identicon-async
publicKey
(fn [name photo-path]
(let [derived-whisper (derived-data constants/path-whisper-keyword)
derived-data-extended (assoc-in derived-data
[constants/path-whisper-keyword]
(merge derived-whisper {:name name :photo-path photo-path}))]
(re-frame/dispatch [::store-multiaccount-success
key-code derived-data-extended]))))))]
{::store-multiaccount [selected-id address hashed-password callback]})) {::store-multiaccount [selected-id address hashed-password callback]}))
(fx/defn prepare-intro-wizard (fx/defn prepare-intro-wizard
@ -188,10 +198,12 @@
:wallet true :wallet true
:path constants/path-default-wallet :path constants/path-default-wallet
:name "Status account"}) :name "Status account"})
(let [{:keys [publicKey address]} (let [{:keys [publicKey address name photo-path]}
(get-in multiaccount [:derived constants/path-whisper-keyword])] (get-in multiaccount [:derived constants/path-whisper-keyword])]
{:publicKey publicKey {:publicKey publicKey
:address address :address address
:name name
:photo-path photo-path
:path constants/path-whisper :path constants/path-whisper
:chat true})]) :chat true})])
@ -216,9 +228,7 @@
:as multiaccount} :as multiaccount}
password password
{:keys [seed-backed-up? login?] :or {login? true}}] {:keys [seed-backed-up? login?] :or {login? true}}]
(let [[wallet-account {:keys [publicKey]} :as accounts-data] (prepare-accounts-data multiaccount) (let [[wallet-account {:keys [publicKey photo-path name]} :as accounts-data] (prepare-accounts-data multiaccount)
name (gfycat/generate-gfy publicKey)
photo-path (identicon/identicon publicKey)
multiaccount-data {:name name multiaccount-data {:name name
:address address :address address
:photo-path photo-path :photo-path photo-path
@ -349,7 +359,7 @@
(assoc (assoc
(get-selected-multiaccount cofx) (get-selected-multiaccount cofx)
:derived :derived
(types/json->clj derived)) derived)
password password
{:seed-backed-up? false})) {:seed-backed-up? false}))

View File

@ -107,9 +107,15 @@
constants/path-whisper constants/path-whisper
constants/path-default-wallet] constants/path-default-wallet]
(fn [result] (fn [result]
(let [derived-data (types/json->clj result)] (let [derived-data (types/json->clj result)
public-key (get-in derived-data [constants/path-whisper-keyword :publicKey])]
(status/gfycat-identicon-async
public-key
(fn [name photo-path]
(let [derived-whisper (derived-data constants/path-whisper-keyword)
derived-data-extended (assoc-in derived-data [constants/path-whisper-keyword] (merge derived-whisper {:name name :photo-path photo-path}))]
(re-frame/dispatch [::import-multiaccount-success (re-frame/dispatch [::import-multiaccount-success
root-data derived-data]))))))))) root-data derived-data-extended]))))))))))))
(fx/defn show-existing-multiaccount-alert (fx/defn show-existing-multiaccount-alert
[_ address] [_ address]

View File

@ -313,8 +313,24 @@
(log/debug "[native-module] generate-gfycat") (log/debug "[native-module] generate-gfycat")
(.generateAlias (status) public-key)) (.generateAlias (status) public-key))
(defn generate-gfycat-async
"Generate a 3 words random name based on the user public-key, asynchronously"
[public-key callback]
{:pre [(utils.db/valid-public-key? public-key)]}
(.generateAliasAsync (status) public-key callback))
(defn identicon (defn identicon
"Generate a icon based on a string, synchronously" "Generate a icon based on a string, synchronously"
[seed] [seed]
(log/debug "[native-module] identicon") (log/debug "[native-module] identicon")
(.identicon (status) seed)) (.identicon (status) seed))
(defn identicon-async
"Generate a icon based on a string, asynchronously"
[seed callback]
(.identiconAsync (status) seed callback))
(defn gfycat-identicon-async
"Generate an icon based on a string and 3 words random name asynchronously"
[seed callback]
(.generateAliasAndIdenticonAsync (status) seed callback))

View File

@ -259,6 +259,8 @@
:<- [:intro-wizard] :<- [:intro-wizard]
(fn [wizard-state] (fn [wizard-state]
{:pubkey (get-in wizard-state [:derived constants/path-whisper-keyword :publicKey]) {:pubkey (get-in wizard-state [:derived constants/path-whisper-keyword :publicKey])
:name (get-in wizard-state [:derived constants/path-whisper-keyword :name])
:photo-path (get-in wizard-state [:derived constants/path-whisper-keyword :photo-path])
:processing? (:processing? wizard-state)})) :processing? (:processing? wizard-state)}))
(re-frame/reg-sub (re-frame/reg-sub

View File

@ -242,6 +242,7 @@
last-in-group? last-in-group?
first-in-group? first-in-group?
display-photo? display-photo?
identicon
display-username? display-username?
from from
outgoing outgoing
@ -254,7 +255,7 @@
(when first-in-group? (when first-in-group?
[react/touchable-highlight {:on-press #(when-not modal? (re-frame/dispatch [:chat.ui/show-profile from]))} [react/touchable-highlight {:on-press #(when-not modal? (re-frame/dispatch [:chat.ui/show-profile from]))}
[react/view [react/view
[photos/member-photo from]]])]) [photos/member-photo from identicon]]])])
[react/view (style/group-message-view outgoing display-photo?) [react/view (style/group-message-view outgoing display-photo?)
(when display-username? (when display-username?
[react/touchable-opacity {:on-press #(re-frame/dispatch [:chat.ui/show-profile from])} [react/touchable-opacity {:on-press #(re-frame/dispatch [:chat.ui/show-profile from])}

View File

@ -19,8 +19,8 @@
(when identicon? (when identicon?
[react/view {:style (style/photo-border size)}])])) [react/view {:style (style/photo-border size)}])]))
(defview member-photo [from & [size]] (defview member-photo [from & [identicon size]]
(letsubs [photo-path [:chats/photo-path from]] (letsubs [photo-path [:chats/photo-path from]]
(photo photo-path (photo (or photo-path identicon)
{:accessibility-label :member-photo {:accessibility-label :member-photo
:size (or size style/default-size)}))) :size (or size style/default-size)})))

View File

@ -348,7 +348,7 @@
(let [next-count (min all-messages-count (+ @messages-to-load load-step))] (let [next-count (min all-messages-count (+ @messages-to-load load-step))]
(reset! messages-to-load next-count))) (reset! messages-to-load next-count)))
(defview messages-view-desktop [{:keys [chat-id group-chat]} (defview messages-view-desktop [{:keys [chat-id group-chat pending-invite-inviter-name]}
modal?] modal?]
(letsubs [messages [:chats/current-chat-messages-stream] (letsubs [messages [:chats/current-chat-messages-stream]
current-public-key [:multiaccount/public-key] current-public-key [:multiaccount/public-key]
@ -391,7 +391,9 @@
:current-public-key current-public-key :current-public-key current-public-key
:row message-obj :row message-obj
:idx #(or (:message-id message-obj) (:value message-obj)) :idx #(or (:message-id message-obj) (:value message-obj))
:list-ref messages-list-ref}]))]]]))) :list-ref messages-list-ref}]))]]
(if pending-invite-inviter-name
[group-chat-footer chat-id])])))
(defview chat-root [modal?] (defview chat-root [modal?]
(letsubs [{:keys [public? chat-id chat-name show-input? group-chat contact] :as current-chat} (letsubs [{:keys [public? chat-id chat-name show-input? group-chat contact] :as current-chat}

View File

@ -414,7 +414,7 @@
:margin-top 8}} :margin-top 8}}
(i18n/label :t/processing)]])]) (i18n/label :t/processing)]])])
(defn recovery-success [pubkey] (defn recovery-success [pubkey name photo-path]
[react/view {:flex 1 [react/view {:flex 1
:justify-content :space-between :justify-content :space-between
:background-color colors/white} :background-color colors/white}
@ -430,7 +430,7 @@
[react/view {:justify-content :center [react/view {:justify-content :center
:align-items :center :align-items :center
:margin-bottom 11} :margin-bottom 11}
[react/image {:source {:uri (identicon/identicon pubkey)} [react/image {:source {:uri photo-path}
:style {:width 61 :style {:width 61
:height 61 :height 61
:border-radius 30 :border-radius 30
@ -441,7 +441,7 @@
:font-weight "500"} :font-weight "500"}
:number-of-lines 1 :number-of-lines 1
:ellipsize-mode :middle} :ellipsize-mode :middle}
(gfy/generate-gfy pubkey)] name]
[react/text {:style {:text-align :center [react/text {:style {:text-align :center
:margin-top 4 :margin-top 4
:color colors/gray :color colors/gray
@ -558,7 +558,7 @@
wizard-state)]]])) wizard-state)]]]))
(defview wizard-recovery-success [] (defview wizard-recovery-success []
(letsubs [{:keys [pubkey processing?]} [:intro-wizard/recovery-success] (letsubs [{:keys [pubkey processing? name photo-path]} [:intro-wizard/recovery-success]
existing-account? [:intro-wizard/recover-existing-account?]] existing-account? [:intro-wizard/recover-existing-account?]]
[react/view {:style {:flex 1}} [react/view {:style {:flex 1}}
[toolbar/toolbar [toolbar/toolbar
@ -570,7 +570,7 @@
[react/view {:style {:flex 1 [react/view {:style {:flex 1
:justify-content :space-between}} :justify-content :space-between}}
[top-bar {:step :recovery-success}] [top-bar {:step :recovery-success}]
[recovery-success pubkey] [recovery-success pubkey name photo-path]
[bottom-bar {:step :recovery-success [bottom-bar {:step :recovery-success
:forward-action :multiaccounts.recover/re-encrypt-pressed :forward-action :multiaccounts.recover/re-encrypt-pressed
:processing? processing? :processing? processing?

View File

@ -1,5 +1,6 @@
(ns status-im.utils.gfycat.core (ns status-im.utils.gfycat.core
(:require [status-im.native-module.core :as native-module] (:require [status-im.native-module.core :as native-module]
[re-frame.core :as re-frame]
[status-im.utils.datetime :as datetime])) [status-im.utils.datetime :as datetime]))
(def unknown-gfy "Unknown") (def unknown-gfy "Unknown")
@ -12,3 +13,11 @@
(native-module/generate-gfycat public-key))) (native-module/generate-gfycat public-key)))
(def generate-gfy (memoize build-gfy)) (def generate-gfy (memoize build-gfy))
(re-frame/reg-fx
:insert-gfycats
(fn [key-path-seq]
(for [key-path key-path-seq]
(let [public-key (first key-path)
path-for-gfycat (second key-path)]
(native-module/generate-gfycat-async public-key #(re-frame/dispatch [:gfycat-generated path-for-gfycat %]))))))

View File

@ -1,5 +1,16 @@
(ns status-im.utils.identicon (ns status-im.utils.identicon
(:require (:require
[re-frame.core :as re-frame]
[status-im.native-module.core :as native-module])) [status-im.native-module.core :as native-module]))
(def identicon (memoize native-module/identicon)) (def identicon (memoize native-module/identicon))
(def identicon-async native-module/identicon-async)
(re-frame/reg-fx
:insert-identicons
(fn [key-path-seq]
(for [key-path key-path-seq]
(let [public-key (first key-path)
path-for-identicon (second key-path)]
(identicon-async public-key #(re-frame/dispatch [:identicon-generated path-for-identicon %]))))))