mirror of
https://github.com/status-im/status-react.git
synced 2025-01-11 03:26:31 +00:00
localStorage in jail
This commit is contained in:
parent
111c6f3ae0
commit
c56fa0c688
@ -227,14 +227,15 @@ function getJsSuggestions(code, context) {
|
|||||||
var doc = DOC_MAP;
|
var doc = DOC_MAP;
|
||||||
// TODO: what's /c / doing there ???
|
// TODO: what's /c / doing there ???
|
||||||
//console.debug(code);
|
//console.debug(code);
|
||||||
|
var previousMessage = localStorage.getItem("previousMessage");
|
||||||
if (!code || code == "" || code == "c ") {
|
if (!code || code == "" || code == "c ") {
|
||||||
code = "";
|
code = "";
|
||||||
//console.debug("Last message: " + context.data);
|
//console.debug("Last message: " + context.data);
|
||||||
if (context.data != null) {
|
if (previousMessage != null) {
|
||||||
suggestions.push({
|
suggestions.push({
|
||||||
title: 'Last command used:',
|
title: 'Last command used:',
|
||||||
desc: context.data,
|
desc: previousMessage,
|
||||||
pressValue: context.data
|
pressValue: previousMessage
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var keys = Object.keys(doc);
|
var keys = Object.keys(doc);
|
||||||
@ -250,13 +251,13 @@ function getJsSuggestions(code, context) {
|
|||||||
if (code.startsWith("c ")) {
|
if (code.startsWith("c ")) {
|
||||||
code = code.substring(2);
|
code = code.substring(2);
|
||||||
}
|
}
|
||||||
if (context.data != null &&
|
if (previousMessage != null &&
|
||||||
(typeof context.data === 'string' || context.data instanceof String) &&
|
(typeof previousMessage === 'string' || previousMessage instanceof String) &&
|
||||||
context.data.startsWith(code)) {
|
previousMessage.startsWith(code)) {
|
||||||
suggestions.unshift({
|
suggestions.unshift({
|
||||||
title: 'Last command used:',
|
title: 'Last command used:',
|
||||||
desc: context.data,
|
desc: previousMessage,
|
||||||
pressValue: context.data
|
pressValue: previousMessage
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
var originalCode = code;
|
var originalCode = code;
|
||||||
@ -355,7 +356,7 @@ function jsHandler(params, context) {
|
|||||||
messages = [];
|
messages = [];
|
||||||
try {
|
try {
|
||||||
result["text-message"] = JSON.stringify(eval(params.code));
|
result["text-message"] = JSON.stringify(eval(params.code));
|
||||||
localStorage.set(params.code);
|
localStorage.setItem("previousMessage", params.code);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
result.err = e;
|
result.err = e;
|
||||||
}
|
}
|
||||||
|
@ -73,13 +73,19 @@ function superSuggestion(params, context) {
|
|||||||
return {markup: view};
|
return {markup: view};
|
||||||
};
|
};
|
||||||
|
|
||||||
var cnt = 0;
|
|
||||||
|
|
||||||
status.addListener("on-message-input-change", superSuggestion);
|
status.addListener("on-message-input-change", superSuggestion);
|
||||||
status.addListener("init", superSuggestion);
|
status.addListener("init", superSuggestion);
|
||||||
status.addListener("on-message-send", function (params, context) {
|
status.addListener("on-message-send", function (params, context) {
|
||||||
|
cnt = localStorage.getItem("cnt");
|
||||||
|
if(!cnt) {
|
||||||
|
cnt = 0;
|
||||||
|
}
|
||||||
|
|
||||||
cnt++;
|
cnt++;
|
||||||
|
|
||||||
|
localStorage.setItem("cnt", cnt);
|
||||||
if (isNaN(params.message)) {
|
if (isNaN(params.message)) {
|
||||||
|
|
||||||
return {"text-message": "Seems that you don't want to send money :(. cnt = " + cnt};
|
return {"text-message": "Seems that you don't want to send money :(. cnt = " + cnt};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,5 +15,5 @@ android {
|
|||||||
dependencies {
|
dependencies {
|
||||||
compile 'com.facebook.react:react-native:+'
|
compile 'com.facebook.react:react-native:+'
|
||||||
compile 'com.instabug.library:instabug:3+'
|
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')
|
||||||
}
|
}
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
<artifactItem>
|
<artifactItem>
|
||||||
<groupId>status-im</groupId>
|
<groupId>status-im</groupId>
|
||||||
<artifactId>status-go-ios-simulator</artifactId>
|
<artifactId>status-go-ios-simulator</artifactId>
|
||||||
<version>hackaton-alt-gd3704fa</version>
|
<version>jail-signals-gfe007d5</version>
|
||||||
<type>zip</type>
|
<type>zip</type>
|
||||||
<overWrite>true</overWrite>
|
<overWrite>true</overWrite>
|
||||||
<outputDirectory>./</outputDirectory>
|
<outputDirectory>./</outputDirectory>
|
||||||
|
@ -276,3 +276,12 @@ console = (function (old) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
}(console));
|
}(console));
|
||||||
|
|
||||||
|
localStorage.setItem = function(key, value) {
|
||||||
|
localStorageData[key] = value;
|
||||||
|
localStorage.set(JSON.stringify(localStorageData));
|
||||||
|
};
|
||||||
|
|
||||||
|
localStorage.getItem = function(key) {
|
||||||
|
return localStorageData[key];
|
||||||
|
};
|
||||||
|
@ -10,7 +10,8 @@
|
|||||||
[status-im.constants :refer [console-chat-id]]
|
[status-im.constants :refer [console-chat-id]]
|
||||||
[status-im.i18n :refer [get-contact-translated]]
|
[status-im.i18n :refer [get-contact-translated]]
|
||||||
[taoensso.timbre :as log]
|
[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!
|
(defn command-handler!
|
||||||
[_ [chat-id
|
[_ [chat-id
|
||||||
@ -86,6 +87,7 @@
|
|||||||
(handlers/side-effect! suggestions-events-handler!))
|
(handlers/side-effect! suggestions-events-handler!))
|
||||||
|
|
||||||
(reg-handler :set-local-storage
|
(reg-handler :set-local-storage
|
||||||
(fn [{:keys [current-chat-id] :as db} [{:keys [data] :as event}]]
|
(handlers/side-effect!
|
||||||
(log/debug "Got event: " event)
|
(fn [{:keys [current-chat-id] :as db} [{:keys [data chat_id] :as event}]]
|
||||||
(assoc-in db [:local-storage current-chat-id] data)))
|
(local-storage/set-data {:chat-id chat_id
|
||||||
|
:data data}))))
|
||||||
|
@ -16,7 +16,8 @@
|
|||||||
[status-im.utils.random :as random]
|
[status-im.utils.random :as random]
|
||||||
[status-im.chat.sign-up :as sign-up]
|
[status-im.chat.sign-up :as sign-up]
|
||||||
[status-im.bots.constants :as bots-constants]
|
[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!
|
(defn load-commands!
|
||||||
@ -76,16 +77,18 @@
|
|||||||
[_ [{{:keys [whisper-identity]} :contact
|
[_ [{{:keys [whisper-identity]} :contact
|
||||||
:keys [callback]}
|
:keys [callback]}
|
||||||
file]]
|
file]]
|
||||||
(status/parse-jail
|
(let [data (local-storage/get-data whisper-identity)
|
||||||
whisper-identity file
|
local-storage-js (js-res/local-storage-data data)]
|
||||||
(fn [result]
|
(status/parse-jail
|
||||||
(let [{:keys [error result]} (json->clj result)]
|
whisper-identity (str local-storage-js file)
|
||||||
(log/debug "Parsing commands results: " error result)
|
(fn [result]
|
||||||
(if error
|
(let [{:keys [error result]} (json->clj result)]
|
||||||
(dispatch [::loading-failed! whisper-identity ::error-in-jail error])
|
(log/debug "Parsing commands results: " error result)
|
||||||
(do
|
(if error
|
||||||
(dispatch [::add-commands whisper-identity file result])
|
(dispatch [::loading-failed! whisper-identity ::error-in-jail error])
|
||||||
(when callback (callback))))))))
|
(do
|
||||||
|
(dispatch [::add-commands whisper-identity file result])
|
||||||
|
(when callback (callback)))))))))
|
||||||
|
|
||||||
(defn validate-hash
|
(defn validate-hash
|
||||||
[db [_ file]]
|
[db [_ file]]
|
||||||
|
9
src/status_im/data_store/local_storage.cljs
Normal file
9
src/status_im/data_store/local_storage.cljs
Normal 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))
|
10
src/status_im/data_store/realm/local_storage.cljs
Normal file
10
src/status_im/data_store/realm/local_storage.cljs
Normal 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))
|
@ -5,7 +5,8 @@
|
|||||||
[status-im.data-store.realm.schemas.account.v4.core :as v4]
|
[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.v5.core :as v5]
|
||||||
[status-im.data-store.realm.schemas.account.v6.core :as v6]
|
[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
|
; put schemas ordered by version
|
||||||
(def schemas [{:schema v1/schema
|
(def schemas [{:schema v1/schema
|
||||||
@ -28,4 +29,7 @@
|
|||||||
:migration v6/migration}
|
:migration v6/migration}
|
||||||
{:schema v7/schema
|
{:schema v7/schema
|
||||||
:schemaVersion 7
|
:schemaVersion 7
|
||||||
:migration v7/migration}])
|
:migration v7/migration}
|
||||||
|
{:schema v8/schema
|
||||||
|
:schemaVersion 8
|
||||||
|
:migration v8/migration}])
|
||||||
|
39
src/status_im/data_store/realm/schemas/account/v8/core.cljs
Normal file
39
src/status_im/data_store/realm/schemas/account/v8/core.cljs
Normal 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))
|
@ -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 "{}"}}})
|
@ -48,4 +48,10 @@
|
|||||||
(defn web3-init [provider-address]
|
(defn web3-init [provider-address]
|
||||||
(str "var providerAddress = \"" provider-address "\";"
|
(str "var providerAddress = \"" provider-address "\";"
|
||||||
(slurp "resources/web3_init.js")))
|
(slurp "resources/web3_init.js")))
|
||||||
;;
|
|
||||||
|
(defn local-storage-data [data]
|
||||||
|
(str "var localStorageData = "
|
||||||
|
(if data
|
||||||
|
data
|
||||||
|
"{}")
|
||||||
|
";"))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user