localStorage in jail

This commit is contained in:
Roman Volosovskyi 2017-06-05 13:50:34 +03:00 committed by Roman Volosovskyi
parent 111c6f3ae0
commit c56fa0c688
13 changed files with 127 additions and 31 deletions

View File

@ -227,14 +227,15 @@ function getJsSuggestions(code, context) {
var doc = DOC_MAP;
// TODO: what's /c / doing there ???
//console.debug(code);
var previousMessage = localStorage.getItem("previousMessage");
if (!code || code == "" || code == "c ") {
code = "";
//console.debug("Last message: " + context.data);
if (context.data != null) {
if (previousMessage != null) {
suggestions.push({
title: 'Last command used:',
desc: context.data,
pressValue: context.data
desc: previousMessage,
pressValue: previousMessage
});
}
var keys = Object.keys(doc);
@ -250,13 +251,13 @@ function getJsSuggestions(code, context) {
if (code.startsWith("c ")) {
code = code.substring(2);
}
if (context.data != null &&
(typeof context.data === 'string' || context.data instanceof String) &&
context.data.startsWith(code)) {
if (previousMessage != null &&
(typeof previousMessage === 'string' || previousMessage instanceof String) &&
previousMessage.startsWith(code)) {
suggestions.unshift({
title: 'Last command used:',
desc: context.data,
pressValue: context.data
desc: previousMessage,
pressValue: previousMessage
});
}
var originalCode = code;
@ -355,7 +356,7 @@ function jsHandler(params, context) {
messages = [];
try {
result["text-message"] = JSON.stringify(eval(params.code));
localStorage.set(params.code);
localStorage.setItem("previousMessage", params.code);
} catch (e) {
result.err = e;
}

View File

@ -73,13 +73,19 @@ function superSuggestion(params, context) {
return {markup: view};
};
var cnt = 0;
status.addListener("on-message-input-change", superSuggestion);
status.addListener("init", superSuggestion);
status.addListener("on-message-send", function (params, context) {
cnt = localStorage.getItem("cnt");
if(!cnt) {
cnt = 0;
}
cnt++;
localStorage.setItem("cnt", cnt);
if (isNaN(params.message)) {
return {"text-message": "Seems that you don't want to send money :(. cnt = " + cnt};
}

View File

@ -15,5 +15,5 @@ android {
dependencies {
compile 'com.facebook.react:react-native:+'
compile 'com.instabug.library:instabug:3+'
compile(group: 'status-im', name: 'status-go', version: 'hackaton-alt-gd3704fa', ext: 'aar')
compile(group: 'status-im', name: 'status-go', version: 'jail-signals-gfe007d5', ext: 'aar')
}

View File

@ -25,7 +25,7 @@
<artifactItem>
<groupId>status-im</groupId>
<artifactId>status-go-ios-simulator</artifactId>
<version>hackaton-alt-gd3704fa</version>
<version>jail-signals-gfe007d5</version>
<type>zip</type>
<overWrite>true</overWrite>
<outputDirectory>./</outputDirectory>

View File

@ -276,3 +276,12 @@ console = (function (old) {
}
};
}(console));
localStorage.setItem = function(key, value) {
localStorageData[key] = value;
localStorage.set(JSON.stringify(localStorageData));
};
localStorage.getItem = function(key) {
return localStorageData[key];
};

View File

@ -10,7 +10,8 @@
[status-im.constants :refer [console-chat-id]]
[status-im.i18n :refer [get-contact-translated]]
[taoensso.timbre :as log]
[status-im.commands.utils :as cu]))
[status-im.commands.utils :as cu]
[status-im.data-store.local-storage :as local-storage]))
(defn command-handler!
[_ [chat-id
@ -86,6 +87,7 @@
(handlers/side-effect! suggestions-events-handler!))
(reg-handler :set-local-storage
(fn [{:keys [current-chat-id] :as db} [{:keys [data] :as event}]]
(log/debug "Got event: " event)
(assoc-in db [:local-storage current-chat-id] data)))
(handlers/side-effect!
(fn [{:keys [current-chat-id] :as db} [{:keys [data chat_id] :as event}]]
(local-storage/set-data {:chat-id chat_id
:data data}))))

View File

@ -16,7 +16,8 @@
[status-im.utils.random :as random]
[status-im.chat.sign-up :as sign-up]
[status-im.bots.constants :as bots-constants]
[status-im.utils.datetime :as time]))
[status-im.utils.datetime :as time]
[status-im.data-store.local-storage :as local-storage]))
(defn load-commands!
@ -76,8 +77,10 @@
[_ [{{:keys [whisper-identity]} :contact
:keys [callback]}
file]]
(let [data (local-storage/get-data whisper-identity)
local-storage-js (js-res/local-storage-data data)]
(status/parse-jail
whisper-identity file
whisper-identity (str local-storage-js file)
(fn [result]
(let [{:keys [error result]} (json->clj result)]
(log/debug "Parsing commands results: " error result)
@ -85,7 +88,7 @@
(dispatch [::loading-failed! whisper-identity ::error-in-jail error])
(do
(dispatch [::add-commands whisper-identity file result])
(when callback (callback))))))))
(when callback (callback)))))))))
(defn validate-hash
[db [_ file]]

View File

@ -0,0 +1,9 @@
(ns status-im.data-store.local-storage
(:require [status-im.data-store.realm.local-storage :as data-store]))
(defn get-data [chat-id]
(:data (data-store/get-by-chat-id chat-id)))
(defn set-data [local-storage]
(data-store/save local-storage))

View File

@ -0,0 +1,10 @@
(ns status-im.data-store.realm.local-storage
(:require [status-im.data-store.realm.core :as realm]))
(defn get-by-chat-id
[chat-id]
(realm/get-one-by-field-clj @realm/account-realm :local-storage :chat-id chat-id))
(defn save
[local-storage]
(realm/save @realm/account-realm :local-storage local-storage true))

View File

@ -5,7 +5,8 @@
[status-im.data-store.realm.schemas.account.v4.core :as v4]
[status-im.data-store.realm.schemas.account.v5.core :as v5]
[status-im.data-store.realm.schemas.account.v6.core :as v6]
[status-im.data-store.realm.schemas.account.v7.core :as v7]))
[status-im.data-store.realm.schemas.account.v7.core :as v7]
[status-im.data-store.realm.schemas.account.v8.core :as v8]))
; put schemas ordered by version
(def schemas [{:schema v1/schema
@ -28,4 +29,7 @@
:migration v6/migration}
{:schema v7/schema
:schemaVersion 7
:migration v7/migration}])
:migration v7/migration}
{:schema v8/schema
:schemaVersion 8
:migration v8/migration}])

View File

@ -0,0 +1,39 @@
(ns status-im.data-store.realm.schemas.account.v8.core
(:require [status-im.data-store.realm.schemas.account.v4.chat :as chat]
[status-im.data-store.realm.schemas.account.v1.chat-contact :as chat-contact]
[status-im.data-store.realm.schemas.account.v6.command :as command]
[status-im.data-store.realm.schemas.account.v6.command-parameter :as command-parameter]
[status-im.data-store.realm.schemas.account.v7.contact :as contact]
[status-im.data-store.realm.schemas.account.v1.discover :as discover]
[status-im.data-store.realm.schemas.account.v1.kv-store :as kv-store]
[status-im.data-store.realm.schemas.account.v4.message :as message]
[status-im.data-store.realm.schemas.account.v7.pending-message :as pending-message]
[status-im.data-store.realm.schemas.account.v1.processed-message :as processed-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]
[status-im.data-store.realm.schemas.account.v5.contact-group :as contact-group]
[status-im.data-store.realm.schemas.account.v5.group-contact :as group-contact]
[status-im.data-store.realm.schemas.account.v8.local-storage :as local-storage]
[taoensso.timbre :as log]))
(def schema [chat/schema
chat-contact/schema
command/schema
command-parameter/schema
contact/schema
discover/schema
kv-store/schema
message/schema
pending-message/schema
processed-message/schema
request/schema
tag/schema
user-status/schema
contact-group/schema
group-contact/schema
local-storage/schema])
(defn migration [old-realm new-realm]
(log/debug "migrating v8 account database: " old-realm new-realm)
(contact/migration old-realm new-realm))

View File

@ -0,0 +1,7 @@
(ns status-im.data-store.realm.schemas.account.v8.local-storage)
(def schema {:name :local-storage
:primaryKey :chat-id
:properties {:chat-id "string"
:data {:type "string"
:default "{}"}}})

View File

@ -48,4 +48,10 @@
(defn web3-init [provider-address]
(str "var providerAddress = \"" provider-address "\";"
(slurp "resources/web3_init.js")))
;;
(defn local-storage-data [data]
(str "var localStorageData = "
(if data
data
"{}")
";"))