Commit Graph

421 Commits

Author SHA1 Message Date
Sasha Weiss
063acc1419
Batch messageId notification cancellations 2022-09-27 14:26:44 -07:00
Evan Hahn
11c2cf0813
Add basic test for database migration
_This change should have no user impact._

This adds a basic test for database migration, and makes the necessary
changes to make that possible.
2022-09-22 17:24:40 +00:00
Harry
7ee39eef63
Add SystemStoryManager
* Add OnboardingStoryManager

* mark onboarding story viewed

* Add tests and fix issues that came up from testing

* up test timeout for slower CI

* rename SystemStoryManager and put into dependency injecton container

* Use viewed state on StoryMessage itself. Have SystemStoryManager observe app lifecyle events to automatically manage the onboarding story

* use iOS assets which are now in s3

* todo cleanup

* increment timestamp for uniqueness

* pr comments

* change literal delimiter

* Add ChainedPromise utility, tests, and use in SystemStoryManager

* discretionarily observe app backgrounding in SystemStoryManager

* renaming from PR comments
2022-08-30 14:49:59 -07:00
Max Radermacher
fdc8633ab0 Remove ConversationConfigurationSyncOperation
It’s unused (except in debug code) since 8c0196077f.
2022-08-26 14:42:57 -07:00
Max Radermacher
5449a4de9b Remove unused code from MockSSKEnvironment
As of 86b8eb08b8, the database initialization no longer has
asychronous components. The current code returns an already-resolved
promise in all situations, so remove the asynchronous infra entirely.
2022-08-25 09:53:08 -07:00
Harry
33e26b6c4c
Migrate OWSSignalService from objc to swift, and split it into a protocol and implementation
* Split OWSSignalService into a swift protocol and implementation, migrated from objc

* Put OWSSignalService under SSKEnvironment and use mock in mock environment

* Rename from basename + impl to protocol + basename

* extend mock functionality a bit

* pr feedback
2022-08-24 14:36:52 -07:00
Nora Trapp
f340250194 Support remote delete of stories 2022-08-19 14:23:59 -07:00
harry-signal
2a23f61a3f
Video Story muting/unmuting
* Start muted, unmute when pressing volume buttons

* move ringer switch observation into its own class

* observe ringer switch in stories

* add foreground time to AppContext; use to drive mute foregrounding behavior

* dont double observe

* mix story volume with others, show volume controls
2022-08-10 16:25:49 -07:00
Sasha Weiss
698180fbb3
Index name components if available 2022-08-02 11:52:20 -07:00
Nora Trapp
2ab53b2b14 Sync story distribution lists 2022-07-15 15:05:03 -07:00
Max Radermacher
ea0986b676 Parse gift badges on incoming sync messages
This allows outgoing gift messages from other devices to be shown.
2022-07-07 10:46:50 -07:00
george-signal
010eb64e9d
Record early receipts for server-generated DRs 2022-06-20 13:25:24 -07:00
Nora Trapp
7bd167f815
Initial story sending support
* Little fix for context menu

* Add 'My Stories' section to stories tab

* Add new story thread types

* Show stories in conversation picker

* Support for sending stories

* Update story list when sending stories

* Add basic 'My Stories' view controller

* Initial stories settings screens

* Consolidate TSPrivateStoryThread and TSMyStoryThread into one class

* Require an explicit read transaction to initialize an outgoing message

* Fix linting

* Allow enabling group story from internal settings

* Fix tests

* PR Feedback
2022-06-10 22:28:03 -04:00
Evan Hahn
8009206c18 Respect recipient capabilities when sending gift badges
This respects the `giftBadges` capability when trying to send gift
badges. In other words, it prevents you from sending gift badges to
someone who lacks the capability.

The bulk of this change involves fetching and saving of this new
capability. The rest of the code involves showing it on the "choose
recipient" screen (and some debug screens).
2022-06-10 22:37:22 +00:00
george-signal
ec66f3b21e
Break envelope processing into two parts (#4340)
The purpose of this change is to alleviate the
main source of CPU-grinding after sending a
message to a large group: about 20% of the total
time is spent decoding and re-encoding messages as
they are fetched from the DB and then updated with
info about which recipients have acknowledged
delivery.

Prior to this commit, we decrypted the payload and
then processed the message in a single rather deep
call tree that began in `processNextBatch`. There
are two completely different paths through this
tree that lead to handling a delivery receipt
because server-generated delivery receipts have
the necessary info in plaintext in the envelope
and client-generated delivery receipts have it in
the ciphertext.

The idea here is to break incoming envelope
handling into two parts.

In the first part, each envelope is decrypted and
other common activities (like handling sender key
distribution messages) are performed. A processing
request is created for each. Next, processing
requests are handled. It's easy to examine a
processing request to determine if it is a
delivery receipt, and if so, for what outgoing
message. Doing so allows the new
DeliveryReceiptContext class to cache message
fetches and combine updates to the same message.

Processing requests are grouped together so that
sequential delivery receipt requests enjoy caching
of messages and coalescing of updates into a
single fetch/decode/encode/commit. Other kinds of
envelopes are handled immediately to avoid
increasing memory pressure that caching multiple
messages could cause.
2022-06-09 16:40:34 -07:00
Max Radermacher
c15df6b507
Persist Gift Badges on incoming messages 2022-05-31 11:46:33 -07:00
Jordan Rose
42c18bcc0b Use a mock reachability manager for testing
The normal reachability manager would never get configured during
testing because it waited for AppReadiness. However, it still created
an OWSURLSession, and if between tests the previous reachability
manager wasn't destroyed fast enough, trying to set up a new one would
create a second URL session with the same background identifier, which
isn't allowed.

Fix this by providing a MockSSKReachabilityManager, which is never
reachable by default, and while here update the background identifier
to be something descriptive.
2022-05-25 13:09:14 -07:00
Jordan Rose
e9b6439518 Un-nest builders for our proto wrapper types
We expose many of these builders to Objective-C, but Swift is unable
to map forward-declarations of those types (@class) back to the real
Swift classes because they're nested within the protos. Since we're
already using fully-qualified names even in Swift (e.g.
"SSKProtoContentBuilder"), nesting isn't worth the trouble it's
causing.
2022-05-19 15:40:21 -07:00
Jordan Rose
a301452f0c Test phone number sharing modes for sealed sender
Sealed sender certificates come in two flavors: one with our local
phone number, and one without. Add an automated test for picking the
right one based on our phone number sharing mode (everybody,
contacts-only, nobody).

This commit also adds a convenience helper for tests that want to wait
on promises that might run on the main thread.
2022-05-18 10:21:53 -07:00
Evan Hahn
29c0ddf60e Fix violations of SwiftLint's attributes rule
_I recommend reviewing this with whitespace changes disabled._

Most of these were `@objc` being on the same line, which I fixed with [a
silly script][1]—probably could've used `sed` if I were wiser. The rest
were manual fixes.

See [the SwiftLint documentation for this rule][0].

[0]: https://realm.github.io/SwiftLint/attributes.html
[1]: https://gist.github.com/EvanHahn-Signal/d353c93fa269c82b96baca0a1086521f
2022-05-14 09:07:42 -05:00
Evan Hahn
04d7bb7462 Stop using arc4random in Swift files
This removes calls to `arc4random` and `arc4random_uniform` and replaces
them with calls to `Int.random` or equivalent.

These are a little less readable, which may be [why SwiftLint doesn't
like them][0]. (SwiftLint calls them "legacy", possibly because they're
not strong random number generators, but I couldn't find a clear
explanation for this anywhere, including [the original PR][1].)

This is the kind of change that's error-prone, so I wrote [a simple
script to help avoid regressions][2]. The script runs 10,000 iterations
of the old and new RNG and compares the ranges, reporting differences.
(Some differences are likely, like the ones that involve floats; others
are very unlikely to have differences.)

`git grep arc4random | grep swift` returns no results after this change.
Same for [everything else SwiftLint checks for][3].

[0]: https://realm.github.io/SwiftLint/legacy_random.html
[1]: https://github.com/realm/SwiftLint/pull/2419
[2]: https://gist.github.com/EvanHahn-Signal/9c75c9f484f4778149cbde3eafc9b285
[3]: ea6cc50890/Source/SwiftLintFramework/Rules/Idiomatic/LegacyRandomRule.swift (L23-L27)
2022-05-03 10:19:07 -05:00
Nora Trapp
27e03b6a70 Render 1:1 story replies 2022-04-15 19:28:14 -07:00
Jordan Rose
a2edd320bb OWSMessageDecrypter should use destinationUuid to choose local stores
Note that on its own this doesn't change behavior of the app;
OWSMessageProcessor still drops non-ACI messages even attempting to
decrypt them.
2022-04-14 16:47:46 -07:00
Jordan Rose
f58ab2ae07 Separate IdentityStore from IdentityManager
*Most* of the identity store's duties are about the identity keys of
people you talk to, but it also provides the local identity key (and
registration ID), and the local identity key differs by PNI.

This design fetches the local identity key up front in preparation for
supporting Change Number flows better, where you may need to use a
past PNI identity key to decrypt a message. (That's just one possible
implementation strategy, though.)
2022-04-14 16:47:46 -07:00
Jordan Rose
5ecb9519b9 Refresh PNI pre-keys along with ACI pre-keys
Pre-keys are refreshed at regular (throttled) intervals, but the
"refresh" operation will only actually upload new pre-keys if the
server says we're running low. In addition, after the "refresh",
there's a "rotation" operation for the signed pre-key if the current
one is more than two days old. This only runs if the refresh was
skipped, since uploading new one-time pre-keys is already an
opportunity to rotate the signed pre-key (and it's worth doing so,
since pre-keys running low can indicate high traffic).

None of this has changed. However, we can now do this for both ACI and
PNI pre-keys. This reworked +[TSPreKeyManager
checkPreKeysWithShouldThrottle:] quite a bit to declare the proper
operation dependencies, which isn't *strictly* necessary because the
queue they're executed on is already limited to a
maxConcurrentOperationCount of 1. We could remove that at this point
with proper use of "barrier" operations, but since all the operations
are hitting the server and account updates have to be serialized on
*that* end, there doesn't seem to be much of a benefit.
2022-04-07 14:06:27 -07:00
Jordan Rose
f0de694156 Rotate the PNI signed pre-key along with the ACI signed pre-key
This only applies to explicit rotations of *just* the signed pre-key.
Including this for regular pre-keys as well is more complicated.
2022-04-07 10:23:39 -07:00
Jordan Rose
849d6ee60a Generate PNI identity key and pre-keys for existing accounts
At launch time, if a primary device doesn't have a PNI identity key,
it should generate one immediately, as well as pre-keys. If a linked
device doesn't have a PNI identity key, it messages the primary to ask
for one; when it gets a response it generates its own pre-keys.
2022-04-04 15:19:10 -07:00
Nora Trapp
e662b099dd Check if a user is stories capable when sending group replies 2022-03-31 00:37:56 -07:00
Nora Trapp
0e54e5cf11 Add support for incoming reaction story replies 2022-03-31 00:34:33 -07:00
Nora Trapp
9494498d70 Add support for sending group replies to stories 2022-03-31 00:34:32 -07:00
Nora Trapp
b88b3ce396 Process incoming story context 2022-03-31 00:34:32 -07:00
Nora Trapp
05313c3725 Update to LibSignalClient v0.15.0 2022-03-24 11:55:45 -07:00
Jordan Rose
a43f005d8d Add initial support for the PniIdentity sync message
This communicates the PNI identity key to existing linked devices,
which is important for linked devices to initially learn about a PNI,
or for the change of identity that comes with changing your number
(and therefore your PNI). The exact contents of this message will
probably change going forward, but here's a baseline to work off of.
2022-03-23 11:48:08 -07:00
Jordan Rose
39042a8234 Create PNI identity keys and pre-keys upon registration
This doesn't handle
- device linking (we need to send the PNI identity key as well as the
  ACI identity key)
- existing devices that need PNI keys (that'll be an explicit check)
2022-03-18 12:34:11 -07:00
George Nachman
b66b1ab866 Batch fetch of user names.
This stacks on top of PR #4065.

This is a simple change that uses the existing
batch profile fetching to get user names.

It adds a test for OWSProfileManager.
2022-03-17 15:05:39 -07:00
George Nachman
22c1cb8a22 Fetch phone numbers in a batch.
This is the first meaty part of optimizing
fetching display names.

Some contacts fall back to phone numbers as their
display names. This PR fetches them in a single
SQL query via
`OWSContactsManager.phoneNumbers(for:, transaction)`.

To achieve this, this PR introduces
`GRDBSignalAccountFinder.signalAccounts(for:,transaction:)`
to fetch many accounts at once.

In order to fetch many accounts at once, we need
to be able to fetch many values from a
ModelReadCache at once. So this PR introduces
`ModelReadCache.readValues(for:,transaction:)` and
`ModelReadCache.getValues(for:,transaction:,returnNilOnCacheMiss:)`.

Existing methods that operate on a single value
were refactored to use the batch methods.

This PR adds tests for this functionality, which
necessitated changing the visibility of various
private symbols and also improving the fake
profile manager to make it more configurable.

There's also a tiny optimization for Refinery to
avoid calling a closure that has no work to do.
This helps elide do-nothing SQL queries that would
otherwise have been introduced.
2022-03-17 12:46:33 -07:00
Jordan Rose
7448b377fb Parameterize the 1:1 stores by identity (ACI or PNI)
This allows two stores to coexist in the database. Note that
everything *using* the stores will still always use the ACI stores at
this point.
2022-03-16 14:31:06 -07:00
Jordan Rose
2e39dab9b2 Support two SignalProtocolStores in SSKEnvironment
'sessionStore', 'preKeyStore', and 'signedPreKeyStore' are no longer
directly accessible; you have to go through
'signalProtocolStore(for:)' instead. This commit mechanically changes
all use sites to use `signalProtocolStore(for: .aci)`, with the
understanding that they will need cleanup in the future.

This is not enough to actually support multiple stores; they still
store in the database under the same keys. That's coming in the next
commit.
2022-03-16 14:31:06 -07:00
Jordan Rose
49d4684013 Teach OWSIdentityManager about PNI identity keys
And make all callers explicitly say which one they want (which for now
is always the ACI identity key).
2022-03-16 13:29:20 -07:00
Jordan Rose
8a29fdd71c Store the local PNI alongside the local ACI and phone number
Save the PNI after registration and when verifying or updating our
current phone number. (Also, show it in the Internal settings like the
phone number and ACI.)
2022-03-14 12:59:44 -07:00
Michelle Linington
259cf01376 Lint 2022-03-04 14:16:29 -08:00
Michelle Linington
05ea13c8c9 LightweightCallManager will now post NSE group call alerts 2022-03-04 14:16:29 -08:00
George Nachman
36119e4367 Introduce Refinery to help batch DB queries.
This PR is the first in a series that will
optimize looking up full names of group members.

The biggest source of slowness when opening a
group chat is looking up the full names of group
members in the search for duplicates. It is slow
because it requires multiple db queries for each
member.

The characterstic feature of this algorithm is the
iterative process of assigning names to signal
addresses. For example, some contacts' names may
be cached. For others, their profiles must be
fetched. For those without profiles, their phone
numbers must be formatted (which requires fetching
SignalAccounts). For those without phone numbers,
their user names must be formatted.

This PR creates a class called Refinery. Its job
is to make it easy to assign values to keys
through multiple passes, where each pass may
succeed only for a subset of keys.

This is useful because we will eventually issue a
single DB query for some of these passes.
2022-03-04 10:44:07 -08:00
George Nachman
7702463524 Temporarily increase user profile cache size.
PR 2982 optimized
ConversationViewController.createGroupMembershipCollisionBannerIfNecessary`
that fetches user profiles off the main thread and
then, when that completes, uses them on the main
thread to find duplicate display names.

The optimization doesn't work for large groups.
Because `UserProfileReadCache` is backed by an
LRUCache with a maximum capacity of 32, there is
effectively no cache and profiles get fetched
twice.

The main purpose of this commit is to fix this
optimization for large groups without expanding
memory usage unnecessarily. While increasing the
LRU cache's size to 1000 (or some other arbitrary
value) would fix the problem very simply, my gut
tells me that we're going to keep running into
this problem.

Rather than pick an arbitrary "large enough"
value, this commit increases the cache size to be
just large enough for its intended purpose and to
keep it that size for just long enough to do its
job.

This commit introduces the concept of a "lease" on
a larger cache size. The cache's size is defined
as the largest of all its leases plus its
"regular" size (the size it was initialized with).
For now only the user profile cache uses it.
2022-02-11 13:20:12 -08:00
Nora Trapp
aeaf5d86d6 Don't show subscription megaphone again until your subscription has been expired for at least 2 weeks 2022-02-11 13:09:20 -08:00
Igor Solomennikov
71ac19adae Do not use -[UIApplication setStatusBarHidden:animated:].
Deprecated in iOS 9.
2022-01-31 15:15:18 -08:00
Nora Trapp
9ed5e74b79 Sync additional badge info with storage service 2021-12-17 13:54:20 -08:00
Nora Trapp
64b399f3e3 Fix badge expiry 2021-12-17 13:54:20 -08:00
Eugene Bistolas
61989e9363 [Badging] Signal devices when subscription status changes 2021-12-02 21:04:47 -10:00
Eugene Bistolas
ddafbd32ff Merge branch 'release/5.26.1' 2021-11-23 11:57:03 -10:00