Commit Graph

170 Commits

Author SHA1 Message Date
Andrea Maria Piana 54cf783d5b
Move group chats to status-go
This commit completely remove transit for group chats. All the
processing is now done in status-go.
Also introuduces parsing and handling of mentions, needed so that system
messages can be easily built in status-go.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-12-10 16:18:26 +01:00
Andrea Maria Piana 78d694f52f
Move message processing to status-go and introduce protobuf
This commit moves all the processing of messages to status-go.

Messages are going arrive to status-react already saved an processed.

Receiving/sending/retrieving from db is now using the same identical
structure. The only processing left in status-react is to mark the
messages as seen and update the unviewed count locally (only
status-react knows whether the count should be updated).

Partially remove commands as well as won't be used anymore.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-12-05 17:30:30 +01:00
yenda 94c7953f30
remove commands before replacement by gui commands
Signed-off-by: yenda <eric@status.im>
2019-12-03 15:07:56 +01:00
yenda 572e028f32
fix 9394 select mailserver based on ping
- if not mailserver was actively selected by user,
use rpc call to get latency for known mailservers
and use the best one
- this happens when `set-current-mailserver` is called which happens
in `change-mailserver` when user unpins his preferred mailserver and when
there's been too many failed attemps to fetch messages or to connect to
then current mailserverm as well as when user logs in.

Signed-off-by: yenda <eric@status.im>
2019-11-28 23:31:39 +01:00
Andrea Maria Piana efcb35504d
[Fixes: #9489] Correctly pass `now` in cofx when receiving messages
`now` was not passed anymore in cofx, this fixes the issue.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-11-20 12:27:30 +01:00
Andrea Maria Piana 9a9c0ce526
Render markdown
Fixes: https://github.com/status-im/trailofbits-audit/issues/47
Fixes: https://github.com/status-im/trailofbits-audit/issues/46
Fixes: https://github.com/status-im/trailofbits-audit/issues/44
Fixes: https://github.com/status-im/security-reports/issues/13
Fixes: https://github.com/status-im/security-reports/issues/5
Fixes: https://github.com/status-im/status-react/issues/8995

This commits re-introduce rendering of markdown text and implent a few
changes:

1) Parsing of the message content is now in status-go, this includes
markdown, line-count, and rtl. Parsing is not nested, as there's some
rendering degradation involved as we nest components, unclear exactly if
it's react-native or clojure, haven't looked too deeply into it.
2) Emojii type messages are not parsed on the sending side, not the
receiving one, using the appropriate content-type
3) Fixes a few issues with chat input rendering, currrently we use
`chats/current-chat` subscription which is very heavy and should not be
used unless necessary, and means that
any change to chat will trigger a re-render, which caused re-rendering
of input container on each received message. Also to note that
input-container is fairly heavy to render, and it's rendered twice at
each keypress on input.

The inline markdow supported is:

*italic* or _italic_
**bold** or __bold__
`inline code`
http://test.com links
\#status-tag

The block markdown supported is:

\# Headers
```
code blocks
```
> Quotereply

The styling is very basic at the moment, but can be improved.
Adding other markdown (photo,mentions) is straightforward and should
come at little performance cost (unless the component to render is
heavy, i.e a photo for example).

There are some behavioral changes with this commit:

1) Links are only parsed if starting with http:// or https://, meaning that
blah.com won't be parsed, nor www.test.com. This behavior is consistent
with discord for example and allows faster parsing at little expense to
ser experience imo. Fixes a few security issues as well.

2) Content is not anymore capped (regression), that's due to the fact that
before we only rendered text and react-native allowed us easily to limit
the number of lines, but adding markdown support means that this
strategy is not viable anymore. Performance of rendering don't see to be
very much impacted by this, I would re-introduce it if necessary, but
I'd rather do that in a separate PR.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-11-15 10:23:25 +01:00
Andrea Maria Piana 13b01ce879
Fix replies, clear-history, logout bug
Fixes #9433 : this was due to the fact that `.-response-to` was
returning nil, because of the dash in the name, instead in this cases
`(aget .. "response-to")` should be used.

Fixes #9431 : This was a left-over from the move from message-groups to
message-list, and the code was not updated.

Fixes #9430 #9429 Both of these were due to the same issue, cofx were
wrongly passed to the function resulting in the db being updated but the
fxs being discarded.

There's still a separate issue that might result in messages not being
saved on logout, because of a race condition (if you logout while is
fetching messages, some of the message might not be saved). I will
address that separately as we might be able to just save messages as
they come in status-go, rather then having to pass them to status-react
and back to status-go for saving.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-11-12 11:27:26 +01:00
Andrea Maria Piana 2bb7c70216
[Fixes: #1520] Enable ens
Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-11-08 13:03:42 +01:00
yenda 36ad6fb762
support for local notification service on Android
- add option in profile on Android to enable local notifications
- use foreground service to keep the app alive when running in the background
- implement enable and disbable notification function in status module

When enabling notifications, a foreground service is started that displays
a sticky notification to make the user aware that the app is running in the
background.
Notifications are updated whenever a new.message signal is handled on java side.
Currently only one to one chats are generating notifications but that can be
easily extended to other types of messages, including mentions and keywords.
The ens name of the user as well as keywords to follow should then be passed
to the native side when calling the enable function.

Signed-off-by: yenda <eric@status.im>
2019-11-07 09:59:12 +01:00
Andrea Maria Piana 5fe385c225
Parse messages in status-go
This commit enables parsing of messages in status-go.
Currently only a few messages are supported in status-protocol-go.
For now we only enable Message types.
Status-react will conditionally use the parsed version if present.
Eventually this can be moved to a separate signal/different structure,
but for the time being is best to validate with the minimum amount of
changes.

The next step would be handle validation and processing of the field in
status-go, so we can skip saving the message from status-react.

This commit should improve performance of receiving messages from a
chat, although haven't had time to validate that.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-11-06 19:30:47 +01:00
Andrea Maria Piana c69863cda2
Fix message ordering and improve performance rec. messages
This commit does a few things:

==== Ordering of messages ====

Change the ordering of messages from a mixture of timestamp/clock-value to use
only clock-value.

Datemarks are now not used for sorting anymore, which means that the
order of messages is always causally related (not the case before, as we
were breaking this property by sorting by datemark), but datemark
calculation is unreliable (a reply to a message might have a timestamp <
then the message that is replied to).
So for timestamp calculation we
naively group them ignoring "out-of-order timestamp" messages, although
there's much to improve.
It fixes an issue whereby the user would change their time and the
message will be displayed in the past, although it is still possible to
craft a message with a lower clock value and order it in the past
(there's no way we can prevent this to some extent, but there are ways
to mitigate, but outside the scope of this PR).

==== Performance of receiving messages ====

The app would freeze on pulling messages from a mailserver (100 or so).
This is due to the JS Thread being hogged by CPU calculation, coupled
with the fact that we always tried to process messages all in one go.

This strategy can't scale, and given x is big enough (200,300,1000) the
UI will freeze.

Instead, each message is now processed separately, and we leave a gap
between processing each message for the UI to respond to user input
(otherwise the app freezes again).
Pulling messages will be longer overall, but the app will be usuable
while this happen (albeit it might slow down).
Other strategies are possible (calculate off-db and do a big swap,
avoiding many re-renders etc), but this is the reccommended strategy by
re-frame author (Solving the CPU Hog problem), so sounds like a safe
base point.

The underlying data structure for holding messages was also changed, we
used an immutable Red and Black Tree, same as a sorted map for clojure, but we use
a js library as is twice as performing then clojure sorted map.

We also don't sort messages again each time we receive them O(nlogn), but we
insert them in order O(logn).

Other data structures considered but discarded:
1) Plain vector, but performance prepending/insertion in the middle
(both O(n)) were not great, as not really suited for these operations.

2) Linked list, appealing as append/prepend is O(1), while insertion is
O(n). This is probably acceptable as messages tend to come in order
(from the db, so adding N messages is O(n)), or the network (most of
them prepends, or close to the head), while mailserver would not follow this path.
An implementation of a linked list was built, which performed roughtly the
same as a clojure sorted-map (although faster append/prepend), but not
worth the complexity of having our own implementation.

3) Clojure sorted-map, probably the most versatile, performance were
acceptable, but nowhere near the javascript implementation we decided on

4) Priority map, much slower than a sorted map (twice as slow)

5) Mutable sorted map, js implementation, (bintrees), not explored this very much, but from
just a quick benchmark, performance were much worse that clojure
immutable sorted map

Given that each message is now processed separately, saving the chat /
messages is also debounced to avoid spamming status-go with network
requests. This is a temporary measure for now until that's done directly
in status-go, without having to ping-pong with status-react.

Next steps performance wise is to move stuff to status-go, parsing of
transit, validation, which is heavy, at which point we can re-consider
performance and how to handle messages.

Fixes also an issue with the last message in the chat, we were using the
last message in the chat list, which might not necessarely be the last
message the chat has seen, in case messages were not loaded and a more
recent message is the database (say you fetch historical messages for
1-to-1 A, you don't have any messages in 1-to-1 chat B loaded, you receive an
historical message for chat B, it sets it as last message).

Also use clj beans instead of js->clj for type conversion

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-11-01 23:59:26 +01:00
yenda 7bb45fdd8f
remove firebase
Signed-off-by: yenda <eric@status.im>
2019-10-29 15:03:58 +01:00
Andrea Maria Piana 9cd891365a
Use payload & avoid transforming in clojure objects.
This commit includes a few performance fixes:
1) Pass a string payload instead of an hex encoded string, to avoid
unecessary conversion
2) Don't js->clj on messages, as that's fairly expensive and we can get
away without
3) Don't use `pr-str` `read-string`, rather convert to json

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-10-23 15:52:32 +02:00
Andrea Maria Piana 57b1722863
Verify ens names on messages and contact requests
This commits verifies ens names when new messages or contact requests
come through.
A batch of ens names is sent to status-go which will then verifying them
and the result will be passed back in a callback to status-react.

Also temporary skipped test_ens_in_public_chat until we merge the ENS
code (blocked currently by 1.9 upgrade)

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-10-23 12:32:28 +02:00
Andrea Maria Piana acd7e56d1d
Add gfycat/identicon from status-go
Signed-off-by: yenda <eric@status.im>
2019-09-26 14:12:43 +02:00
yenda 1147466362
integrate status-go mailserver api 2019-09-05 18:07:17 +02:00
yenda ff2b24b1c6
cleanup shh/post
Signed-off-by: yenda <eric@status.im>
2019-08-22 14:56:10 +02:00
yenda 75ce7da50c
remove realm chat-transport usages 2019-08-22 14:55:50 +02:00
yenda 1c475e5b1e
replace last remains of web3.js by json-rpc 2019-08-20 17:42:02 +02:00
yenda d7cd2b8a74
integrate status-go accounts 2019-08-20 17:42:02 +02:00
Andrea Maria Piana dcb7415208
Move messages to status-go
This commit does a few things:

1) Move messages to status-go
2) Use message-id computed from status-go
3) Remove old replies

Old message id was used for compatibility of replies with older clients.
Given that v1 is breaking, this is not needed anymore and simplifies
moving messages to status-go. No protocol/data-store change is made, to minimize
changes.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-08-20 13:25:05 +02:00
Andrea Maria Piana 370bc207bc
Add datasync confirmations, enable device-to-device by default
This commit adds datasync confirmations and enables device-to-device for
all the communications, as that's what we will go with v1.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-08-12 19:52:37 +02:00
Andrea Maria Piana fe9d4e9cd8
Move contacts to status-go
Contacts are now in status-go, no migration of contacts is provided so
all contacts will be lost upon installing this build.

I have left the initialization of filters a bit sketchy (we wait that
load-filters is called twice), as the next step will be to avoid calling
load-filters altogether, as now that both contacts & chats are in
status-go, there's no reason to call it from status-react, and can be
called directly from status-go on loading.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-08-07 13:39:59 +02:00
Andrea Maria Piana 6fa482a776
Move chats to status-go
This commit moves chats to status-go.

I have changed the logic to load all chats in one go for simplicity and
while that might have a performance impact, I think it's premature to
  optimize this flow as there will be more changes to the login flow.

Also currently this is likely to be slower as we need to wait for the
 status-service to be initialized, as well as realm.

No migration is provided as we are past the point of no return, so by
installing this version you will lose your chats.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-08-05 16:08:24 +02:00
Andrea Maria Piana 1e655540da
Fix loading of filters
Currently on some devices there are still some legacy chats(?) that are
one-to-one but don't have a public key as an id (transactor,demo-bot).
We were wrongly sending those to status-go to create filters.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-07-30 20:25:59 +02:00
yenda c3c4a5170a
[multiaccount] rename multiaccount to account
Signed-off-by: yenda <eric@status.im>
2019-07-22 11:14:44 +02:00
Julien Eluard 28f7ea0408
Enable stickers on all envs. Use contenthash to identify stickers
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
2019-07-11 15:06:32 +02:00
Andrea Maria Piana de0d98da20
Use a signal for messages
This commits changes the behavior to read from a signal instead of
polling each filter.

We receive a signal from status-go every 0.3 seconds, only if new
messages are received. We receive a single signal for all the chats, and
we don't dispatch anymore on every message.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-07-04 15:07:59 +02:00
Andrea Maria Piana 138ade3b8d
Move installations to status-go
This commit moves the management of installations to status-go, and
migrates the data from realm.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-07-03 12:50:23 +02:00
Julien Eluard e1bcaebd2c
Resolve ENS name in chats and profiles
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
2019-07-02 19:41:07 +02:00
Andrea Maria Piana 532664ab84
Adds topic negotiation and partitioned topic
All the code has been implemented in statusgo: status-im/status-go#1466

Basically all the whisper filter management is done at that level.

Technical description
On startup we load all chats and send a list of them to status go:
For a public chat: {:chatId "status"}, we create a single filter, based on the name of the chat.

For each contact added by us, each user in a group chat and each one to one chat open, we send:
{:chatId "0x", :oneToOne true}. This will create a chats, to listen to their contact code.

Any previously negotiated topic is also returned.

Once loaded, we create our filters, and upsert the mailserver topics, both of which are solely based on the filters loaded.
In order to remove a chat, we delete/stopwatching first the the filter in status-react and then ask status-go to remove the filter. For a public chat we always remove, for a one-to-one we remove only if the user is not in our contacts, or in a group chat or we have a chat open. Negotiated topics are never removed, as otherwise the other user won't be able to contact us anymore.

On stopping whisper we don't have to ask status-go to remove filters as they are removed automatically.

Some more logic can be pushed in status-go, but that will be in subsequent PRs.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-06-24 13:54:43 +02:00
Roman Volosovskyi 908f730b1d
[perf] network module 2019-06-13 09:33:18 +03:00
yenda 04de022eae
[refactor] replace web3-prototype
- replace web3-prototype wherever possible
- currently only the money namespace is left
for future refactoring, the ideal solution
would be to use strings for big numbers all
the time and only convert for arithmetic operations
- use json-rpc call to replace trivial web3 calls

Signed-off-by: yenda <eric@status.im>
2019-06-06 15:57:34 +02:00
yenda 1ae42ea424
[perf] upgrade realm and improve schemas/queries
- upgrade to realm 2.28 to benefit from perf improvements
- remove user-statuses and replace by seen and outgoing-status fields
to get rid of a lot of bloat queries and computations
- remove unused seen message, bottom-infos
- remove unused fields in transport schema
- use objectForPrimaryKey whenever possible instead of get by field

Signed-off-by: yenda <eric@status.im>
2019-06-04 23:36:35 +02:00
yenda 1cb7f3b83f
[perf] remove unused schemas and properties
Signed-off-by: yenda <eric@status.im>
2019-06-03 18:24:34 +02:00
Vitaliy Vlasov 04ccd0e7d8
Add TtT chat flow
Signed-off-by: yenda <eric@status.im>
2019-06-03 15:31:30 +02:00
Roman Volosovskyi c7c7b50281
RAM bundle basic setup 2019-05-27 17:34:17 +03:00
Andrea Maria Piana 494772a35d
Fix broken contact syncing
Signed-off-by: Igor Mandrigin <i@mandrigin.ru>
2019-04-25 12:45:20 +02:00
Roman Volosovskyi c98f547349
Multiple messages gaps per chat 2019-04-24 22:33:08 +03:00
bitsikka cd1dfb67f4
[#7917] fix - Contacts are not synced between 0.11.0 and current nightly
Signed-off-by: Jakub Sokołowski <jakub@status.im>
2019-04-16 21:33:46 +02:00
Roman Volosovskyi a4d8f57b09
Fetch missed range of messages 2019-04-12 16:22:44 +03:00
yenda 26b97ddf43
introduce system-tags
Signed-off-by: yenda <eric@status.im>
2019-03-25 16:55:09 +01:00
Roman Volosovskyi 7f76e2fbf0
Enable partitioned topic 2019-03-18 13:52:13 +02:00
Andrea Maria Piana 4f89073ae8
Add network info in about, with copy to clipboard
In network we show peer infos about you and the connect peers.
Any entry is about is clickable and will copy the value to the
clipboard. Copy info will copy all the info in a JSON string.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-02-26 17:31:55 +01:00
Andrea Maria Piana 6a42580fc2
Remove separate topic from group chats
Currently the separate topic was not used, as it's a bit tricky to
coordinate when multiple devices from different versions are present,
with the partitioned topic, probably this optimisation is not necessary
anymore, so removing this for now.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-02-26 17:18:26 +01:00
Andrea Maria Piana dac323a3de
Remove automatic sending of contact request 2019-02-18 09:37:35 +01:00
Andrea Maria Piana becb32d5e7
Use dedup-id instead of raw-payload
This is a backward/forward compatible change with status-go.
We are changing the way messages are confirmed from passing the
raw-object to status-go to a dedup-id instead, which needs to be sent
back.
Based on the response from status-go we detect whether they are ids or
object and act accordingly.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-02-17 23:05:25 +01:00
Andrea Maria Piana bddae03ab2
Allow multiple push notifications
We keep tokens synchronized across devices, so that the user can notify
us on any paired device.
Currently we record the installation id associated to the fcm-token even
though is not necessary, but it will be once we send device-to-device
messages, in which case we want to notify only those devices.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-02-14 16:33:50 +01:00
Andrey Shovkoplyas fca51beaaa
[#7445] Sticker detail view in chat
Signed-off-by: Julien Eluard <julien.eluard@gmail.com>
2019-02-12 16:31:22 +01:00
Andrea Maria Piana 7960fdef85
Publish contact updates periodically
Currently it's very easy for contact details to get out of sync, the
simplest example is:
A & B are contacts.
A changes name.
B receives the updated name.
B re-install the app.
Until A changes name again, B will not see their name, picture and won't
be able to send push notifications.

This PR changes the behavior to publish account informations to contacts
every 24 hrs, to add some redundancy in this cases.

It also publishes a contact code every 12hrs.

Signed-off-by: Andrea Maria Piana <andrea.maria.piana@gmail.com>
2019-02-12 14:20:45 +01:00