Skip to content
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

Merged
merged 2 commits into from
Oct 16, 2017

Conversation

alwx
Copy link
Contributor

@alwx alwx commented Sep 5, 2017

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:

var send = {
    name: "send",
    scope: {
        isGlobal: false,
        personalChats: true,
        groupChats: false,
        canUseForDApps: false
    },
    icon: "money_white",
    color: "#5fc48d",
    title: I18n.t('send_title'),
    description: I18n.t('send_description'),
    params: paramsSend,
    validator: validateSend,
    handler: handleSend,
    preview: previewSend,
    shortPreview: shortPreviewSend
};

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.

@alwx alwx self-assigned this Sep 5, 2017
@alwx alwx force-pushed the feature/command-scopes branch 2 times, most recently from 91a0deb to e82184f Compare September 7, 2017 13:23
@alwx alwx changed the title WIP: Command scopes, better semantics of commands, different /send and /request for groups and personal chats Command scopes, better semantics of commands, different /send and /request for groups and personal chats Oct 2, 2017
Copy link
Contributor

@janherich janherich left a 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?]}]
Copy link
Contributor

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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.

Copy link
Contributor Author

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.

@alwx
Copy link
Contributor Author

alwx commented Oct 2, 2017

@janherich also don't like this kind of duplication (transactor_group and transactor_personal). However, if I combine them into one file, this file will be incredibly big. I think the best way we can solve this problem is by introducing the ability to specify entry points and have several files like bot.js.
It is not related to this task, but I will think about a better and not time-consuming way of solving this problem.

@@ -1,7 +1,7 @@
{
"name": "StatusIm",
"interface": "reagent",
"androidHost": "localhost",
"androidHost": "10.0.3.2",
Copy link
Contributor

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"
Copy link
Contributor

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
Copy link
Contributor

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 */,
Copy link
Contributor

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);
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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
Copy link
Contributor

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?))))
Copy link
Contributor

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.

Copy link
Contributor Author

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"})}
Copy link
Contributor

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

Copy link
Member

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

Copy link
Contributor

@oskarth oskarth Oct 2, 2017

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?

Copy link
Contributor Author

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.

@rasom
Copy link
Member

rasom commented Oct 2, 2017

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
Copy link
Member

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
Copy link
Member

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}]
Copy link
Member

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])
Copy link
Member

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?

@rasom
Copy link
Member

rasom commented Oct 2, 2017

What does canUseForDApps mean?

@alwx alwx force-pushed the feature/command-scopes branch 3 times, most recently from 16caaad to e03e2f5 Compare October 5, 2017 06:24
input-model/split-command-args
rest)
(input-model/split-command-args)
(rest))
Copy link
Contributor

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)
Copy link
Contributor

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 ?

Copy link
Contributor Author

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

Copy link
Contributor

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 ?

@asemiankevich asemiankevich self-assigned this Oct 9, 2017
@annadanchenko
Copy link

annadanchenko commented Oct 9, 2017

#2060 'Property must be of type: string' popup after providing confirmation code [feature/command-scopes] fixed in d71e7a3
#2061 No Unsigned Transaction screen is shown if send tx in chat with 2 members [feature/command-scopes] This is fixed in 0.9.10-215-g45b94306+ both android and ios
#2072 Icons for /send and /request commands are missing [feature/command-scopes] This is fixed in 0.9.10-215-g45b94306+ both android and ios This is fixed in 0.9.10-215-g45b94306+ both android and ios
#2075 /location command is not retrieving the map [feature/command-scopes] This is fixed in 0.9.10-215-g45b94306+ both android and ios

@alwx alwx force-pushed the feature/command-scopes branch 2 times, most recently from cb62dcc to 45b9430 Compare October 13, 2017 11:14
@alwx
Copy link
Contributor Author

alwx commented Oct 13, 2017

All fixes were merged.

@jeluard
Copy link
Contributor

jeluard commented Oct 16, 2017

@alwx Can you rebase on develop?

@rasom rasom merged commit fef984d into develop Oct 16, 2017
@rasom rasom deleted the feature/command-scopes branch October 16, 2017 07:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants