-
Notifications
You must be signed in to change notification settings - Fork 982
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Command scopes, better semantics of commands, different /send and /request for groups and personal chats #1754
Conversation
91a0deb
to
e82184f
Compare
e82184f
to
9cd2f82
Compare
42d0fd5
to
3525ec0
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the scopes are step in the right direction, I like the, also how it simplifies suggestions on the RN side.
The only thing which I'm little bit uneasy with is the duplication in transactor_group/bot.js
and transactor_personal/bot.js
commands, we should lift common code into some other file up in the hierarchy, so it's reused.
[clojure.string :as str] | ||
[taoensso.timbre :as log])) | ||
|
||
(defn scope->int [{:keys [global? registered-only? personal-chats? group-chats? can-use-for-dapps?]}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we rename this to scope->hash
and provide proper docstring describing how hash is computed by bitwise OR operation ?
Otherwise it could be quite cryptic at first glance if the person working on the code is not familiar with how catalog of commands is structured in status.js
and how scope hash is used as second level index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This scope->int calculation is pretty self-descriptive, isn't it? And doing this kind of calculation is a common practice.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, when somebody looks at any place in code where it's used (mostly when constructing path for jail call), scope->int
is little bit vague and she/he needs to jump to function definition before it starts making sense, but with scope->hash
it's immediately clear that we are computing hash out of the scope map.
But not a big deal, I'm fine with either way.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@janherich got it. Will fix.
@janherich also don't like this kind of duplication ( |
@@ -1,7 +1,7 @@ | |||
{ | |||
"name": "StatusIm", | |||
"interface": "reagent", | |||
"androidHost": "localhost", | |||
"androidHost": "10.0.3.2", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remove this from the PR?
@@ -15,8 +15,8 @@ | |||
(re-frame.core/dispatch [:load-commands!])) | |||
|
|||
(figwheel/watch-and-reload | |||
:websocket-url "ws://localhost:3449/figwheel-ws" | |||
:websocket-url "ws://10.0.3.2:3449/figwheel-ws" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same here with entire file (and env/ios
)
ios/Podfile.lock
Outdated
@@ -44,4 +44,4 @@ SPEC CHECKSUMS: | |||
|
|||
PODFILE CHECKSUM: d05403e3fce258b6985bd3b614ffe02a0e01b9f7 | |||
|
|||
COCOAPODS: 1.3.1 | |||
COCOAPODS: 1.2.1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please don't downgrade COCOAPODS version
@@ -947,6 +947,7 @@ | |||
A97BA941B2FB44B4B66EE6D3 /* Frameworks */, | |||
1E7837547A9A40E18AD63CF3 /* Resources */, | |||
5C1C8762251D6EF495FB2384 /* Pods */, | |||
B280E73E1F7E6CB000B5E1A6 /* Recovered References */, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What changes does API have to do with iOS project settings?
@@ -284,7 +284,11 @@ function validateSend(params, context) { | |||
params["bot-db"] = {}; | |||
} | |||
|
|||
if (!params["bot-db"]["public"] || !params["bot-db"]["public"]["recipient"] || !params["bot-db"]["public"]["recipient"]["address"]) { | |||
console.log(context); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this log have sensitive info? Do we need it?
(get-in contacts [identity :dapp?])) | ||
chat-contacts)))))))) | ||
|
||
(defn parse-command-message-content |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Since this is in commands namespace, do we need command in name?
[view st/comand-request-view | ||
[touchable-highlight | ||
{:on-press on-press-handler} | ||
[view st/command-request-message-view | ||
(if (and @markup |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, lots of weird derefs in existing code here. I think this might get rid of some bugs, nice one :)
:schemaVersion 15 | ||
:migration v15/migration} | ||
{:schema v16/schema | ||
:schemaVersion 16 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need two schema bumps? What is the reason for not doing it in v15 alone?
(or (true? pending?) | ||
(bots-constants/hidden-bots whisper-identity))) contacts) | ||
(true? mixable?)))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't think you need (true? ...)
here, as long as mixable
is truthy or falsy, which it should be based on its name.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right, it's just a leftover.
@@ -3,7 +3,7 @@ | |||
[status-im.chat.models.input :as input])) | |||
|
|||
(def fake-db | |||
{:global-commands {:command1 {:name "global-command1"}} | |||
{:global-commands {:command1 '({:name "global-command1"})} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you explain why we need this quoting? It's only tests but I don't understand why
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
just to create a list i suppose. But maybe better to use list
here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it is just changing collection type from map to list-like a vector seems more idiomatic. Is there something list-specific about this?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's keep lists here because we use lists in the real db. I will replace '(...)
with (list ...)
to improve readability.
I would prefer to have something like scopes: ['personal-chat'], instead of scope: {
isGlobal: false,
personalChats: true,
groupChats: false,
canUseForDApps: false
}, just a suggestion |
@@ -0,0 +1,40 @@ | |||
(ns status-im.data-store.realm.schemas.account.v16.core |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@alwx can you merge v15 and v16?
@@ -0,0 +1,47 @@ | |||
(ns status-im.data-store.realm.schemas.account.v12.contact |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we adding v12 contact here?
@@ -113,7 +113,7 @@ | |||
(data-store/save message')))) | |||
|
|||
(defn update | |||
[{:keys [message-id] :as message}] | |||
[{:keys [message-id preview] :as message}] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
preview
is not used
@@ -5,7 +5,8 @@ | |||
[status-im.utils.utils :refer [update-if-present]] | |||
[clojure.walk :refer [stringify-keys keywordize-keys]] | |||
[cljs.reader :refer [read-string]] | |||
[status-im.constants :as c]) | |||
[status-im.constants :as c] | |||
[taoensso.timbre :as log]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
was any logging added in this ns?
What does |
16caaad
to
e03e2f5
Compare
src/status_im/chat/events/input.cljs
Outdated
input-model/split-command-args | ||
rest) | ||
(input-model/split-command-args) | ||
(rest)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nitpicking, but there is no need to add parenthesis in this case
@@ -283,6 +282,8 @@ | |||
:chat-id chat-id | |||
:jail-id (or owner-id jail-id) | |||
:content {:command (:name command) | |||
:scope (when-not (:to-message-id metadata) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the purpose of this expression, why is :scope nil when :to-message-id
is present in metadata ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because we don't use scopes for requests and :to-message-id
is the indication of request
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So we have no better way of distinguishing command-request message from command message other then inspecting :to-message-id
key in the metadata ?
8bca994
to
d5eccb1
Compare
d5eccb1
to
d57f9bb
Compare
#2060 'Property must be of type: string' popup after providing confirmation code [feature/command-scopes] fixed in d71e7a3 |
9a4ef51
to
d7b7862
Compare
d71e7a3
to
a958c32
Compare
cb62dcc
to
45b9430
Compare
All fixes were merged. |
@alwx Can you rebase on develop? |
45b9430
to
77ef5f6
Compare
Ok, this PR is quite big, and there will be a lot of text here.
What happens?
This PR is a part of API refactoring/restructuring, and this PR changes the way commands look and work. It removes any need in hardcoded
/send
and/request
-related things and also makes mailman-like behavior accessible for 3rd-party developers. It also introduces scopes for commands and removes 99% of hardcoded things. By doing it, we make our API better and remove almost all the internal "magic" which was previously unavailable for 3rd-party developers.1. Scopes
The most important part of this PR is scopes for commands.
The best way to demonstrate scopes is this extract from the new
/send
:The important thing is that we can create two or more commands with the same name, but different scopes and a different set of parameters. It allows us to get rid of contact selector for
/send
in 1-to-1 chats and allows 3rd-party devs to make commands more flexible.2. Mailman
Mailman is no longer something special. Everybody can create the same contact whos commands will be mixed with other contact's commands. In combination with scopes, it allows creating something super crazy and flexible.
3. Less magic for /send and /request
There are still some hardcoded things for /send and /request, but the number of them has decreased drastically.
4. Commands model
I moved some common commands-related things to a separate model. It is less complicated and structured better than it was before.
5. Tons of code quality improvements
Yay!
6. One more thing — text input should work faster
We don't call
:update-suggestions
each time user types a character since now, so the speed of text input should increase.