Commit Graph

7838 Commits

Author SHA1 Message Date
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
Evan Hahn
5dbc030359 Fix violations of SwiftLint's closure_parameter_position rule
This commit should just change whitespace.

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

[0]: https://realm.github.io/SwiftLint/closure_parameter_position.html
2022-06-06 13:58:23 +00:00
Jordan Rose
a97560ac38 Allow OWSOutgoingResendRequest/Response on the Note to Self thread
Otherwise, local threads with linked devices can never be reset via
DecryptionErrorMessages as other threads are.
2022-06-03 16:34:49 -07:00
Jordan Rose
98bf0aafb9 Allow quotes with attachments to be missing thumbnails
And fix the presented content type and filename for the attachments in
a quote (it should be the type and filename of the original
attachment, not the thumbnail).
2022-06-03 16:34:25 -07:00
Evan Hahn
e40f162a1e Fix compiler_protocol_init lint rule violation
This fixes our one violation of [SwiftLint's `compiler_protocol_init` rule][0].

[0]: https://realm.github.io/SwiftLint/compiler_protocol_init.html
2022-06-03 19:09:45 +00:00
Evan Hahn
24ca5abf9c Remove unneeded breaks
This fixes our violations of [the SwiftLint `unneeded_break_in_switch`
rule][0].

[0]: https://realm.github.io/SwiftLint/unneeded_break_in_switch.html
2022-06-03 17:52:28 +00:00
Jordan Rose
1c82df3bc9 Protos: Remove unused fields from DataMessage.Quote
These were never added to other clients, so we shouldn't be using
them.
2022-06-03 10:34:21 -07:00
Jordan Rose
4e05dfde5c Don't generate a new PushChallenge for every failed operation
We sometimes attempt to do N operations at once where up to N of them
end up getting caught by the rate limiter. This should *not* turn into
N push challenges, or else we'll get rate limited for that too.
2022-05-31 18:05:22 -07:00
Max Radermacher
c15df6b507
Persist Gift Badges on incoming messages 2022-05-31 11:46:33 -07:00
Jordan Rose
ce9da716e6
MediaGallery: Correctly respond to external deletion
This removes DatabaseChanges.deletedAttachmentIds and replaces it with
a notification that carries more information: the attachment's thread
and original message received-at timestamp in addition to the unique
ID. With this information, we can correctly refresh the parts of
MediaGallery that may be affected by the deletion. (The previous
implementation was correct for the original version of MediaGallery,
but not the rewritten version I implemented last year. My apologies to
all users seeing crashes here!)

In the new model, deletions from outside of MediaGallery's control 
result in reloads of the sections containing the items in question.
This may result in refetching other media that was previously loaded,
but avoids the issue in the previous implementation where existing
loaded items would now be at the wrong offsets.
2022-05-31 10:55:31 -07:00
Max Radermacher
0577775f2f
Parse GiftBadges on incoming messages
(They are still dropped, regardless of whether or not they’re valid.)
2022-05-27 15:22:19 -07:00
Max Radermacher
fa99be971d
Add GiftBadge to SignalService.proto 2022-05-27 13:32:09 -07:00
Max Radermacher
724ea55aa7 Add giftBadge property to messages
Also run `Scripts/sds_codegen/sds_codegen.sh`
2022-05-27 12:31:24 -07:00
Ehren Kret
d53c58aebf logTag needs to be explicitly called in this context 2022-05-27 00:13:17 -05:00
Ehren Kret
2c32710c6d Remove unnecessary try 2022-05-27 00:13:17 -05:00