Commit Graph

7852 Commits

Author SHA1 Message Date
Sasha Weiss (Signal)
98151dfd0d
Don't need transactions to build group models 2022-07-12 10:23:12 -07:00
Max Radermacher
47e75ab251 Put @objc on the line before let variables
This fixes our violations of [SwiftLint's `attributes` rule][0].

[0]: https://realm.github.io/SwiftLint/attributes.html
2022-07-11 16:40:48 -07:00
george-signal
80565fb43f
Revert "Remove GRDB's memory management. (#4521)" (#4546)
This reverts commit a202f6204e.

It also uses the new facility in GRDB to disable
automatic memory management.

For context see:
https://github.com/groue/GRDB.swift/pull/1253
2022-07-11 14:37:29 -07:00
Nora Trapp
4aae9b4eb1 Allow configuring who can view 'My Story' 2022-07-11 10:23:06 -07:00
Evan Hahn
bf8fd72fba
Improve Accept-Language header value, fixing registration bug
Some users [are unable to register][1] because the server [returns a 400
error][2] if passed an invalid `Accept-Language` header.

This commit helps prevent two possible error modes:

- Filters out invalid language tags. Some users reported a "Workshopx"
  language, which the server would reject because it's syntactically
  invalid. Deleting this language (at the OS level) let them register.
- If no languages are valid, we should send `*` instead of the empty
  string. There's no evidence that this happened in practice.

In addition, this commit:

- Adds tests.
- Sends a maximum of 10 languages instead of 6.
- Omits the `q` value when it's 1 because [that's the default][3].
- Marginally improves performance by iterating lazily.

[1]: https://github.com/signalapp/Signal-iOS/issues/5261
[2]: bf6d3aa324/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java (L271-L275)
[3]: https://www.rfc-editor.org/rfc/rfc9110.html#section-12.4.2

Co-authored-by: Nora Trapp <nora@signal.org>
2022-07-11 12:20:24 -05:00
Sasha Weiss (Signal)
ac341fdbbc
DRY out V2 group updates 2022-07-08 15:47:45 -07:00
Evan Hahn
64462ac1b0 Save a receipt when you send someone a badge
This commit:

1. Adds a new donation receipt type: gifts.
2. Saves receipts when sending someone a gift.

The first part was the main challenge. Previously, donation receipts had
logic like this (pseudocode):

     def getReceiptType(self):
       if self.subscriptionLevel:
         return "subscription"
       else:
         return "one-time"

Now, we explicitly encode the type and have logic to handle "legacy"
receipts that don't have a type encoded.
2022-07-08 13:17:30 -05:00
Max Radermacher
ed63a2aeac
Remove trailing comma
This fixes our violation of [SwiftLint's `trailing_comma` rule][0].

[0]: https://realm.github.io/SwiftLint/trailing_comma.html
2022-07-08 08:39:47 -05:00
Evan Hahn
951f5c3708 Remove trailing whitespace
This is a whitespace-only change that fixes a SwiftLint violation.
2022-07-07 17:39:05 -07:00
Evan Hahn
57c47ced2c Fix operator_whitespace SwiftLint violations
This fixes violations of [SwiftLint's `operator_whitespace` rule][0].
This is a whitespace-only change.

[0]: https://realm.github.io/SwiftLint/operator_whitespace.html
2022-07-07 17:38:38 -07:00
Evan Hahn
e25772183d Prefer foo != nil to _ = foo
This fixes our violations of [SwiftLint's `unused_optional_binding`
rule][0].

[0]: https://realm.github.io/SwiftLint/unused_optional_binding.html
2022-07-07 11:09:00 -07:00
Max Radermacher
369118b045 Add support for replying to gift messages 2022-07-07 10:49:20 -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
Max Radermacher
4fb4c29c80 Don’t coalesce viewed receipts 2022-07-07 10:46:37 -07:00
george-signal
a202f6204e
Remove GRDB's memory management. (#4521)
This disgusting hack removes GRDB's notification
center observers, which prevents it from calling
`DatabasePool.releaseMemory()`.

`releaseMemory` is harmful because it places all
future reads behind a dispatch barrier. The effect
is that even very short reads block on any db
reads that precede the barrier. Some of those can
be very slow, such as orphan message handling.

The practical effect of this barrier is that the
main thread gets stuck on what should be a very
quick operation, such as loading your own avatar
data. iOS can kill the app with 8badf00d.

This change is a temporary workaround. A proper
solution has been added to a PR that I sent to
GRDB, which you can see here:

https://github.com/groue/GRDB.swift/pull/1253

Once that is accepted upstream we should update
GRDB and revert this commit.

This change should fix IOS-2474 and doubtless many
other issues.
2022-07-06 13:27:13 -07:00
Max Radermacher
10469e29f5 Remove unused descriptionFor… methods
This are unused since things got refactored in ec66f3b21e. It
appears as though `contentDescription` is just called directly rather
than calling these wrappers.
2022-07-06 12:52:58 -07:00
Max Radermacher
09fd1a39d2
Send viewed receipts when redeeming gift badges 2022-07-06 12:39:41 -07:00
Evan Hahn
f5556d1857
Use durable job for sending badge gifts
Previously, sending a gift badge was not a durable operation, which
meant that crashes/failures could cause users to have their payment
methods charged without actually sending the badge.

Now, the flow is split up into two steps: non-durable parts before the
charge is attempted, and durable parts afterward.

The high-level flow is:

1. Prepare the payment, which involves a couple of repeatable network
   requests.
2. Enqueue a job with the prepared payment, that:
   1. Charges the payment method (idempotently)
   2. Requests a receipt credential (idempotently)
   3. Enqueues a gift message, and optionally a text message
3. When the job completes, open the conversation in the UI.
2022-07-01 17:10:31 -05:00
Max Radermacher
f7f66d6436
Add support for redeeming gift badges 2022-07-01 14:07:24 -07:00
Max Radermacher
7bef47f356
Use serial queue for SDSTransactable.asyncWrite
The database writes are ultimately serial, so there’s little benefit to
scheduling each of these on its own queue. If another slow-ish write is
already happening, there’s a chance that we may see thread explosion,
with many threads waiting to write to the database.
2022-06-30 08:38:54 -07:00
Sasha Weiss (Signal)
86d9b8ea0a
Remove args always passed as nil that were later unused anyway 2022-06-29 09:19:02 -07:00
Max Radermacher
c9fcee9cc3 Clean up incoming reaction processing 2022-06-27 11:10:26 -07:00
Max Radermacher
4976462238 Add missing fields to sync message descriptions 2022-06-27 09:03:47 -07:00
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
Evan Hahn
d0c7de494a Computed accessors shold always be in the same order
`get`, then `set`. This fixes violations of [SwiftLint's
`computed_accessors_order` rule][0].

A very mechanical change.

[0]: https://realm.github.io/SwiftLint/computed_accessors_order.html
2022-06-24 09:35:07 -07:00
Nora Trapp
477f312c1e Send and receive sync transcripts for story messages 2022-06-24 00:35:31 -04:00
Nora Trapp
b13c7dbfdb Don't include yourself in private story recipients 2022-06-24 00:35:31 -04:00
george-signal
e528ea8824
Add source device to manifest record
* Populate the source device in manifests we create.
* Log the source device in manifests we fetch.
2022-06-23 17:50:44 -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
5696c50d7d Make some outgoing message params optional
We frequently send outgoing messages with some parameters, like "link
preview" or "quoted reply", empty.

This change lets those parameters be omitted (instead of explicitly
empty) for brevity.

This is a stylistic change and should have no user impact.

Tested this by sending a regular message, a message with a link preview,
and two messages with photos.
2022-06-23 12:53:05 +00:00
Max Radermacher
dea9919d17 Add chat list preview for Gift Badges 2022-06-23 02:16:06 +00:00
Sasha Weiss (Signal)
5695809776
Prevent non-temporary-file attachments from being deleted when shared 2022-06-22 13:15:04 -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
Max Radermacher
304bae4eda Enable Gift Badge receiving in internal builds 2022-06-22 08:33:04 -07:00
Max Radermacher
c0a85b888b
Add rendering support for Gift Badges
Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
2022-06-22 08:05:25 -07:00
Max Radermacher
af7e902e9f Disable HSM discovery task in staging 2022-06-22 13:26:17 +00:00
Nora Trapp
b458e29355 Use sender key for story sends 2022-06-21 21:06:45 -04:00
Max Radermacher
ea627259fb
Run migrations with immediate foreign key checks
This fixes an issue where unrelated foreign key violations may cause
migrations to fail.
2022-06-21 14:52:32 -07: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
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
Evan Hahn
83a00eddae Enable (incomplete) gift badge send UI for internal builds 2022-06-10 21:54:11 +00:00
Evan Hahn
ddad327212 Clear invalid legacy avatars, instead of crashing
A migration (introduced in b2c0e975b6)
tries to save legacy avatars to disk. However, if that legacy avatar
data is invalid, we'd crash on launch.

A user encountered this.

Our possible solutions:

1. If legacy avatar data is invalid, just drop it.
2. If legacy avatar data is invalid, try to repair it. (For example, if
   it's too large, try to resize it.) This might not fix the user's
   issue—unfortunately, we don't know why the avatar was invalid.
3. Loosen our definition of a valid avatar. (For example, increase the
   maximum size.) This also might not fix things—we don't know how the
   avatar was invalid.

I went with the first solution.

This was difficult to test. While developing, I made a temporary button
that (1) updated a group, giving it an empty legacy avatar buffer (2)
tried to migrate it.

(Thanks to c5bd634ff1 for making this easy
to diagnose!)
2022-06-10 21:50:16 +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
Evan Hahn
5b9f737b46 Fix indentation in ProfileFetcherJob.swift
This is a whitespace-only change.
2022-06-09 16:34:49 -05:00
Evan Hahn
e679707038 Fix SwiftLint shorthand_operator violations
The gist is:

```diff
-foo = foo + 1
+foo += 1
```

Most of the violations were in generated files, so I changed and re-ran the generator.

A few of these violations required implementing some new methods, which I added tests for.

See [the docs for this rule][0].

[0]: https://realm.github.io/SwiftLint/shorthand_operator.html
2022-06-07 14:51:57 +00:00
Evan Hahn
c2e7f0ca93 Prefer implicit getters
_I recommend reviewing this with whitespace changes disabled._

This fixes violations of [SwiftLint's `implicit_getter` rule][0] by
removing explicit getters when an implicit one would do.

[0]: https://realm.github.io/SwiftLint/implicit_getter.html
2022-06-06 14:00:15 +00:00