Commit Graph

525 Commits

Author SHA1 Message Date
Max Radermacher
11d08f101f
Fix crash when deleting messages from the future
The subtraction operation produces a negative value and causes a crash
in Swift. Allow deleting these messages to match Android’s behavior.
2022-06-27 09:02:04 -07:00
Max Radermacher
e303428216 Don’t allow “Delete for Everyone” for Gift Badges 2022-06-23 10:17:53 -07:00
Max Radermacher
da16b7c392 Convert TSMessageTest to Swift 2022-06-23 10:17:53 -07:00
Evan Hahn
f4714b1a83 Basic support for sending gift badges
If you've got the `giftBadgeSending` flag enabled, you can now send gift
badges to anyone who has the capability.

This commit doesn't complete the feature, though. It is missing:

- Proper durability and error handling (to be addressed separately)
- Saving of receipts
- A few other cleanups
2022-06-22 15:50:51 +00:00
Evan Hahn
a1eb9e3042 Clean up boostCreatePaymentIntent()
This makes a few small changes to `OWSRequestFactory.boostCreatePaymentIntent()`:

- Adds tests
- Rewrites the function in Swift

I made sure I could do a boost (in staging) in the simulator.
2022-06-21 17:33:28 +00:00
george-signal
010eb64e9d
Record early receipts for server-generated DRs 2022-06-20 13:25:24 -07:00
George Nachman
f643545d4f Fix a bug where delivery receipts were flaky. [IOS-2478]
anyUpdate runs its closure twice with different
messages but the batching context applied updates
always to the same copy of the message.

Also apply lint fixes.
2022-06-14 16:43:55 -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
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
Sasha Weiss (Signal)
0a089cb63c
Make "Keep Muted Chats Archived" option available publicly 2022-05-26 10:44:43 -04:00
Jordan Rose
309230a086 Set the "share my number" flag when receiving a message at our PNI
Enables the receipt of messages addressed to the local PNI, and sets
the necessary state so that replies will have a PNI signature
included.
2022-05-20 10:48:22 -07:00
Jordan Rose
16c1249b24 PNP: Clear phone number sharing flag after getting a delivery receipt
When someone sends a message to your PNI, your responses (from your
ACI) must include a PNI signature, and the sealed sender certificate
you use during this period should include your phone number. This
confirms to the other user that your ACI is associated with your PNI.

However, as soon as they have processed a PniSignature, there's no
need to keep wasting space in messages. Detect this using the
following conditions:
- You received a delivery receipt from them.
- The original message was sent via sealed sender (so the server
  can't synthesize a delivery receipt).
- All their other devices have already sent delivery receipts for this
  message.
- The original message actually had a PniSignature in it.
- The original message's PniSignature matches your current PNI
  (relevant if you change your number and then get an incoming message
  from the same person at your new PNI).

Additionally, reset phone number sharing for *everyone* when you
change your number; they've contacted you at your old PNI,
representing your old number, and even if you reply you can no longer
claim that PNI as yours.
2022-05-20 10:48:22 -07:00
Jordan Rose
4c8d7662a6 Add OWSIdentityManager.shouldSharePhoneNumber(with:transaction:)
When someone sends a message to your PNI, your responses (from your
ACI) must include a PNI signature, and the sealed sender certificate
you use during this period should include your phone number. This
confirms to the other user that your ACI is associated with your PNI.

This commit adds the state tracking that and ensures that both
TSOutgoingMessage and OWSUDManager check that state when building 1:1
messages and choosing certificates, respectively. Later commits will
set and clear this flag as needed.
2022-05-19 14:20:53 -07:00
Jordan Rose
36426db3e7 Port TSOutgoingMessageTests to Swift
Take the opportunity to combine related tests and ensure we're testing
the right things.
2022-05-19 13:44:21 -07:00
Evan Hahn
baddc85564 Add first gift badge screen
This adds the first screen for badge gifting. It lets you see the gift
badge, pick the currency, and advance to the next screen.

It also adds a skeleton for the next screen, so there's somewhere to
advance to, but that screen is unfinished.

All of this is behind disabled flags, so this should have no user
impact.
2022-05-19 14:07:23 +00:00
Jordan Rose
926178abe1 Port OWSIdentityManagerTests to Swift
...for testing Swift-side things soon.
2022-05-18 11:28:39 -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
Max Radermacher
919e744333 Show "0:00", not "0", for audio message playback
If the formatter was fed a fractional number of seconds, it would try to
render it with `durationFormatterS` and would get back "0".
2022-05-06 11:43:04 -07:00
Evan Hahn
8f3eba01a3 Add message to all XCTFails
SwiftLint [gets upset][0] when `XCTFail` doesn't have a message. We had
two tests that lacked these, so I added them.

Part of my ongoing quest to get to "SwiftLint zero".

[0]: https://realm.github.io/SwiftLint/xctfail_message.html
2022-05-04 09:54:46 -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
Evan Hahn
5be42da750 Change references from master to main
_I recommend reviewing this with whitespace changes disabled._

Signal has renamed its primary branch to `main`. This updates references
to the old name, `master`, to either reference `main` or a specific
commit hash.

I also fixed a couple of small whitespace issues in a file I was
editing.
2022-05-02 10:30:40 -05:00
igor-signal
4a6473b448
Localize user-visible file sizes.
Use ByteCountFormatter with default settings to localize any download sizes that user might see.
2022-04-29 09:57:56 -05:00
Igor Solomennikov
f3b2118d0e [IOS-2364] Fix zero TimeInterval formatted as "0" instead of "0:00". 2022-04-28 10:55:11 -07:00
Jordan Rose
d7e6cfd901 Be more cautious treating sealed senders as high-trust e164-UUID mappings
We can only *really* trust this once the certificate validates, and
even then the certificate could be out of date. So now the mapping is
only treated as high-trust when the inner messages decrypts
successfully too.
2022-04-25 14:30:14 -07:00
Michelle Linington
2e7671b3f5 More project cleanup 2022-04-20 16:26:54 -07:00
Evan Hahn
0cf8a30bf9 Test Subscription struct
This test-only change adds tests for [`Subscription`][0].

I did this because I'll be adding additional behavior to this struct and
want to be ready to test that logic. I think this is a useful change on
its own, however, so I split it out into its own change.

[0]: 2693c55232/SignalMessaging/Subscriptions/SubscriptionManager.swift (L70-L104)
2022-04-20 12:47:50 -05:00
Max Radermacher
bc53916301 Convert all(Testable)?Flags to functions 2022-04-18 16:28:01 -07:00
Max Radermacher
05b0112c88 Rename buildFlagMap()allFlags
This matches the naming scheme used for `allFeatureFlags`.
2022-04-18 14:52:26 -07:00
Max Radermacher
91512d745c Don’t pass class or value lookup block
The class can be computed from `self`, and the lookup block is always
the same (essentially `self.value(forKey:)`), so there’s no need to
provide separate implementations for each subclass. The superclass can
provide a single implementation for all subclasses to share.
2022-04-18 14:52:26 -07:00
Max Radermacher
450b8035f3 Add unit tests for BaseFlags’ reflection APIs 2022-04-18 14:52:26 -07:00
Jordan Rose
9132234a54 Fix for non-messages being filtered out of interaction results
Messages always have an isGroupStoryReply of true or false (1 or 0),
but non-messages don't have this field, and GRDB treats that as NULL
rather than falling back to the table default.
2022-04-15 15:42:33 -07:00
Michelle Linington
41f78c5d12 Merge branch 'release/5.35.1' 2022-04-14 18:16:01 -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
Michelle Linington
e22bfcdc9b Add some version comparison tests 2022-04-14 16:44:16 -07:00
Michelle Linington
d54d654cfc PR Feedback: Remove notImplemented altogether 2022-04-13 20:21:47 -07:00
Michelle Linington
6b2f8d31d6 Lint 2022-04-13 20:21:46 -07:00
Michelle Linington
cca09295e6 Adopt notImplemented() where it's unadopted
notImplemented() ends up forwarding to fatalError() anyway, but before
it does so it flushes our logs. That's probably good to have. I think
most of these come from the default implementations Xcode provides for
you with a fix-it.
2022-04-13 20:21:46 -07:00
Igor Solomennikov
bd653bee3b Lint. 2022-04-12 17:38:21 -07:00
Igor Solomennikov
25810e0887 Add OWSFormatTest. 2022-04-12 17:38:21 -07:00
Michelle Linington
84be44880e PR Feedback 2022-04-08 19:36:27 -07:00
Michelle Linington
a36671c4c2 Lint 2022-04-08 19:01:43 -07:00
Michelle Linington
78e00e310e Adds a bunch of tests 2022-04-08 19:01:43 -07:00
Jordan Rose
f50412f26f Move pre-key culling logic from TSPreKeyManager to the stores 2022-04-07 10:23:39 -07:00
Jordan Rose
039dcc1d48 -[SSKPreKeyStore storePreKeyRecords:] should take a transaction
...so it can use an existing one when there is one, which in practice
there always is because we never refresh one-time pre-keys without
rotating our signed pre-key too.
2022-04-04 15:19:10 -07:00
Chris Eager
978445edf2 Fix failing testGroupEncryptDecrypt_Failure 2022-03-28 14:55:47 -07:00
Nora Trapp
05313c3725 Update to LibSignalClient v0.15.0 2022-03-24 11:55:45 -07:00
Evan Hahn
de105468a4 Assume everyone is GV2-capable 2022-03-22 17:11:57 -05:00
Jordan Rose
30adb219d6 Recognize destinationUuid on envelopes, and filter out non-ACI
We're very close to being able to decrypt messages sent to our PNI,
but *until* that point it's best to just drop any such messages. This
should make testing easier.
2022-03-18 14:15:00 -07:00
Jordan Rose
1c252fd6f6 Add PNI-related fields to the ProvisioningMessage proto
This allows linked devices to receive the PNI identity key as part of
provisioning.
2022-03-18 13:03:55 -07:00
Dimitris Apostolou
62724cf0be Fix typos 2022-03-18 11:31:06 -07:00