fix protocol's initialization on js reloading

Former-commit-id: 55a5b96ad7
This commit is contained in:
Roman Volosovskyi 2016-07-07 11:08:22 +03:00
parent 02c2d4deae
commit aa89c0f85d
5 changed files with 25 additions and 14 deletions

View File

@ -128,7 +128,12 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
}
@ReactMethod
public void startNode(Callback callback) {
public void startNode(Callback callback, Callback onAlreadyRunning) {
if(GethService.isRunning()){
onAlreadyRunning.invoke();
return;
}
Activity currentActivity = getCurrentActivity();
@ -216,4 +221,4 @@ public class GethModule extends ReactContextBaseJavaModule implements LifecycleE
return UUID.randomUUID().toString();
}
}
}

View File

@ -588,7 +588,9 @@
(register-handler :send-seen!
(after (fn [_ [_ chat-id message-id]]
(when-not (= "console" chat-id))
(dispatch [:msg-seen chat-id message-id])))
(u/side-effect!
(fn [_ [_ chat-id message-id]]
(api/send-seen chat-id message-id))))
(when-not (= "console" chat-id)
(api/send-seen chat-id message-id)))))

View File

@ -88,7 +88,9 @@
(u/side-effect!
(fn [db _]
(log/debug "Starting node")
(.startNode geth (fn [result] (node-started db result))))))
(.startNode geth
(fn [result] (node-started db result))
#(dispatch [:initialize-protocol])))))
(register-handler :crypt-initialized
(u/side-effect!

View File

@ -26,7 +26,8 @@
(defn save-message
;; todo remove chat-id parameter
[chat-id {:keys [msg-id content]
[chat-id {:keys [delivery-status msg-id content]
:or {delivery-status :pending}
:as message}]
(when-not (r/exists? :msgs :msg-id msg-id)
(r/write
@ -38,6 +39,7 @@
message
{:chat-id chat-id
:content content'
:delivery-status delivery-status
:timestamp (timestamp)})]
(r/create :msgs message' true))))))
@ -49,13 +51,13 @@
(defn get-messages
([chat-id] (get-messages chat-id 0))
([chat-id from]
(->> (-> (r/get-by-field :msgs :chat-id chat-id)
(r/sorted :timestamp :desc)
(r/page from (+ from c/default-number-of-messages))
(r/collection->map))
(into '())
reverse
(keep (fn [{:keys [content-type] :as message}]
(->> (-> (r/get-by-field :msgs :chat-id chat-id)
(r/sorted :timestamp :desc)
(r/page from (+ from c/default-number-of-messages))
(r/collection->map))
(into '())
reverse
(keep (fn [{:keys [content-type] :as message}]
(if (command-type? content-type)
(update message :content str-to-map)
message))))))

View File

@ -18,8 +18,8 @@
(register-handler :initialize-protocol
(u/side-effect!
(fn [db [_ account]]
(init-protocol account (make-handler db)))))
(fn [{:keys [user-identity] :as db} [_ account]]
(init-protocol (or account user-identity) (make-handler db)))))
(register-handler :protocol-initialized
(fn [db [_ identity]]