Commit Graph

7591 Commits

Author SHA1 Message Date
Max Radermacher
385ae60bc8
Fix some codegen designated initializers
* Ignore `exclusiveProcessIdentifier` parameter

This was added in fee1bbddad, but the `NS_UNAVAILABLE` declarations
weren’t updated, which led to warnings in Xcode.

* Ignore `TSThread` initializer in subclasses

* Fix `TSAttachmentPointer` ignored initializer

* Add missing initializers to `TSMessage` subclasses

This only handles the immediate subclasses. There’s still more warnings
in the extended hierarchy, but those don’t seem to have been handled as
consistently in the first place, so updating them is more involved.
2022-05-09 13:59:38 -07:00
Max Radermacher
1149f8fe91 Remove “Record id is null” debug check
This was added in 04892da490, but it changes generated code, so
re-running the generated removes it. Remove it so that the next codegen
can change only the things related to that codegen.
2022-05-09 09:54:22 -07:00
Max Radermacher
d4adfaff91
Fix protocol conformance warnings
There are some Swift-only features that are part of these protocols, so
they were split into Obj-C and Swift variants. However, the class itself
only reports conformance to the Swift variant, which leads to warnings
when using the class in Objective-C.
2022-05-09 11:44:05 -05:00
Max Radermacher
f7f129cdc5 Remove unnecessary error handler wrapper
This only calls the block, and the formatting in the old design made it
particularly difficult to read. (It also makes this path and the success
path more similar in their construction.)
2022-05-09 09:41:25 -07:00
Max Radermacher
3e5b48f727 Remove redundant Promise.recover call
If the recover block *always* throws the error, then it’s equivalent to
not calling `recover()` at all.
2022-05-09 09:39:27 -07:00
Jordan Rose
1577bcf7ac Move emoji availability cache out of the database
Emoji availability is tested by *drawing the emoji to a graphics
context* and seeing if it comes out as a replacement character glyph.
This is not the fastest operation, so we cache it, and update the
cache whenever the user updates their version of iOS. This cache
previously lived in SDSKeyValueStore, i.e. in a shared table in the
database. Reading it took longer than we might like even before we get
to updating it, and it's not even secret data at all.

This commit replaces the SDSKeyValueStore with a plist file and adds a
migration to remove the SDSKeyValueStore data.
2022-05-06 18:04:09 -07:00
Max Radermacher
c5bd634ff1 Don’t allow migration blocks to throw
In a01ad40f22, migration blocks were wrapped in `do {} catch {}`
blocks so that crash stack traces would identify the specific migration
that encountered an error.

This commit enforces the recommendation from [this comment][1].

It also updates a few migrations that weren’t following the
recommendation. Errors in these migrations still result in a [crash][2],
but the stack trace doesn’t include the specific migration that failed.

[1]: 873ba1e511/SignalServiceKit/src/Storage/Database/GRDBSchemaMigrator.swift (L241-L242)
[2]: 873ba1e511/SignalServiceKit/src/Storage/Database/GRDBSchemaMigrator.swift (L25)
2022-05-06 12:42:31 -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
Martin Böttcher
81f0a0ac1e
Use plural-aware strings in SignalServiceKit
Co-authored-by: Martin Böttcher <martin.boettcher@greenbytes.de>
2022-05-06 10:09:03 -05:00
Jordan Rose
2225e976bc Use query arguments for full-text search 2022-05-06 09:45:45 -05:00
Max Radermacher
96824402df Remove createV1Schema
This is unused & isn’t being updated when the db schema changes. Remove
it to avoid confusion.
2022-05-05 19:27:39 -07:00
Nora Trapp
3797764d75 Enable storiesMigration4 2022-05-05 13:38:12 -07:00
Jordan Rose
b80f177c11 SSK: Fix PNI identity key check
As we come into a PNI-capable world, the primary device checks to see
if the server has the correct PNI identity key, due to possible
failures in the initial upload. Unfortunately, I got the check for
that backwards. Fix that and add more logging.
2022-05-05 12:56:49 -05:00
Evan Hahn
dd12c2c4c4 Fix SwiftLint type_name rule violations
This change:

1. Configures [SwiftLint's `type_name` rule][0] to allow for very long
   types, which we use, and to allow `Id` as a type name
2. Fixes a few trivial violations of the rule that weren't covered by
   that

[0]: https://realm.github.io/SwiftLint/type_name.html
2022-05-05 10:13:27 -05:00
Evan Hahn
23e27d3741 Regenerate .pb.swift files
This undoes some of the SwiftLint changes we had previously.

[swift-protobuf 1.19.0][0], released on 2022-03-02, added some new code for Swift 5.5+.

[0]: https://github.com/apple/swift-protobuf/releases/tag/1.19.0
2022-05-03 12:16:57 -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
Jordan Rose
0428f91e1f Fix deletion of a message after deleting all its attachments
Each attachment-to-be-removed may have a different model object
representing the message, and there may have also been previous
deletions without refreshing these models. So asking whether the
message has any attachments left might give an out-of-date answer. Fix
this by doing an explicit database query to count remaining
attachments, and refreshing the message model before deletion if
necessary.
2022-05-02 12:33:55 -07:00
Nora Trapp
672163a183 Enable storiesMigration3 2022-05-02 12:28:21 -07: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
Max Radermacher
bae945b312 Fix crash while running avatar migration
The stack trace is below, but we attempt to synchronously execute on a
concurrent queue within the execution of a barrier block. This results
in the following error/crash:

```
BUG IN CLIENT OF LIBDISPATCH: dispatch_sync called on queue already owned by current thread
```

Fetching the localAddress with a transaction should cause it to be
available in-memory when it’s needed by the code in this stack trace.

Example backtrace for longevity:

```
0   libdispatch.dylib        __DISPATCH_WAIT_FOR_QUEUE__ + 476
1   libdispatch.dylib        _dispatch_sync_f_slow + 144
2   libdispatch.dylib        _dispatch_sync_f_slow + 144
3   libswiftDispatch.dylib   implicit closure #2 in implicit closure #1 in OS_dispatch_queue.sync<A>(execute:) + 180
4   libswiftDispatch.dylib   partial apply for implicit closure #2 in implicit closure #1 in OS_dispatch_queue.sync<A>(execute:) + 56
5   libswiftDispatch.dylib   OS_dispatch_queue._syncHelper<A>(fn:execute:rescue:) + 396
6   libswiftDispatch.dylib   OS_dispatch_queue.sync<A>(execute:) + 168
7   GRDB                     Pool.get() + 179 (Pool.swift:66)
8   GRDB                     Pool.get<A>(block:) + 95 (Pool.swift:93)
9   GRDB                     DatabasePool.read<A>(_:) + 151
10  GRDB                     DatabasePool.read<A>(_:) + 31
11  SignalServiceKit         GRDBDatabaseStorageAdapter.read(block:) + 31 (GRDBDatabaseStorageAdapter.swift:556) [inlined]
12  SignalServiceKit         @objc GRDBDatabaseStorageAdapter.read(block:) + 143 (<compiler-generated>:541)
13  SignalServiceKit         closure #1 in SDSDatabaseStorage.read(file:function:line:block:) + 279 (SDSDatabaseStorage.swift:354)
14  SignalServiceKit         specialized static InstrumentsMonitor.measure(category:parent:name:block:) + 215 (InstrumentsMonitor.swift:148)
15  SignalServiceKit         specialized static InstrumentsMonitor.measure(category:parent:name:block:) + 47 (<compiler-generated>:0) [inlined]
16  SignalServiceKit         SDSDatabaseStorage.read(file:function:line:block:) + 47 (SDSDatabaseStorage.swift:352) [inlined]
17  SignalServiceKit         SDSDatabaseStorage.readObjC(block:file:function:line:) + 47 (SDSDatabaseStorage.swift:370) [inlined]
18  SignalServiceKit         @objc SDSDatabaseStorage.readObjC(block:file:function:line:) + 195 (<compiler-generated>:369)
19  SignalServiceKit         -[TSAccountManager loadAccountStateWithSneakyTransaction] + 175 (TSAccountManager.m:378)
20  SignalServiceKit         -[TSAccountManager getOrLoadAccountStateWithSneakyTransaction] + 143 (TSAccountManager.m:371)
21  SignalServiceKit         -[TSAccountManager localAddress] + 31 (TSAccountManager.m:563)
22  SignalServiceKit         +[TSAccountManager localAddress] + 47 (TSAccountManager.m:556)
23  SignalServiceKit         SignalServiceAddress.isLocalAddress.getter + 11 (SignalServiceAddress.swift:291) [inlined]
24  SignalServiceKit         @objc SignalServiceAddress.isLocalAddress.getter + 67 (<compiler-generated>:290)
25  SignalServiceKit         +[OWSUserProfile isLocalProfileAddress:] + 111 (OWSUserProfile.m:219)
26  SignalServiceKit         +[OWSUserProfile resolveUserProfileAddress:] + 47 (OWSUserProfile.m:225)
27  SignalMessaging          -[OWSProfileManager getUserProfileForAddress:transaction:] + 63 (OWSProfileManager.m:1551)
28  SignalMessaging          -[OWSProfileManager fullNameForAddress:transaction:] + 23 (OWSProfileManager.m:1443)
29  SignalMessaging          -[OWSContactsManager displayNameForAddress:transaction:] + 179 (OWSContactsManager.m:721)
30  SignalServiceKit         closure #1 in variable initialization expression of static AnySearchIndexer.recipientIndexer + 127 (FullTextSearchFinder.swift:538)
31  SignalServiceKit         specialized SearchIndexer.index(_:transaction:) + 11 (FullTextSearchFinder.swift:503) [inlined]
32  SignalServiceKit         closure #1 in variable initialization expression of static AnySearchIndexer.groupMemberIndexer + 99 (FullTextSearchFinder.swift:522)
33  SignalServiceKit         specialized SearchIndexer.index(_:transaction:) + 19 (FullTextSearchFinder.swift:503) [inlined]
34  SignalServiceKit         specialized static AnySearchIndexer.indexContent(object:transaction:) + 307 (FullTextSearchFinder.swift:574)
35  SignalServiceKit         static AnySearchIndexer.indexContent(object:transaction:) + 11 (<compiler-generated>:0) [inlined]
36  SignalServiceKit         specialized static GRDBFullTextSearchFinder.modelWasInserted(model:transaction:) + 391 (FullTextSearchFinder.swift:257)
37  SignalServiceKit         static GRDBFullTextSearchFinder.modelWasInserted(model:transaction:) + 11 (<compiler-generated>:0) [inlined]
38  SignalServiceKit         closure #2 in closure #19 in GRDBSchemaMigrator.registerDataMigrations(migrator:) + 35 (GRDBSchemaMigrator.swift:1982) [inlined]
```
2022-04-30 14:08:47 -07:00
Jordan Rose
2e5832f7fa MediaGallery: Create "album" objects on demand
Previously, MediaGallery built "album" objects as it loaded items,
adding them to the album as they were loaded. This could be a problem
if items were ever *re*loaded, because then the old model would be in
the album and the new model in the top-level "sections" table. Having
potentially-inconsistent models floating around already isn't great,
but MediaGalleryAlbum and MediaGalleryItem also formed a reference
cycle.

Now, MediaGalleryAlbums are built on demand when showing the "page"
view by walking forward and backwards from an item. GalleryRailView
uses object identity to check whether we've changed albums, so
MediaPageViewController now keeps track of the most recent album and
checks its items to see if it needs to refresh it. This is a linear
check, but that's just not that bad for a message album, which will
only ever have a handful of attachments. (Even if this gets up to,
say, 100 items, that's just not that much work for a modern phone.)
2022-04-29 18:14:03 -07:00
Igor Solomennikov
bee4567dac Address PR feedback. 2022-04-29 17:35:11 -07:00
Igor Solomennikov
c90b282f97 Renames as suggested by GRDB. 2022-04-29 17:35:11 -07:00
Igor Solomennikov
fa71411c92 Remove unused default cases per compiler recommendation. 2022-04-29 17:35:11 -07:00
Michelle Linington
b5c17b6c1c Improved handling of group bans 2022-04-29 14:47:48 -07:00
Evan Hahn
d72dfa60ec "Feature flags for .qa." 2022-04-29 14:26:52 -05:00
Evan Hahn
a12b94e6ef "Feature flags for .beta." 2022-04-29 14:26:14 -05:00
Max Radermacher
88a28c3457 Fix typos: Reciept → Receipt 2022-04-29 12:14:09 -07:00
george-signal
a06c706bab
Add avatar repair. (#4091)
There was a bug that caused avatars to be
encrypted with the wrong key, causing them to be
undecryptable both by ourselves and others.

That bug (IOS-2262) was fixed in #4078.

The purpose of this PR is to replace the broken
avatars with good ones.
2022-04-29 10:14:05 -07: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
Jordan Rose
411ac936c5 Check that the server has our PNI identity key on launch
PNI identity keys for existing accounts are uploaded the first time
the primary notices that it doesn't have a PNI identity key. However,
if that upload is interrupted, the local state would be out of sync
with the server. We can try to be more careful about that, but *this*
PR will manually get them out of that state by explicitly doing a
profile fetch for our own PNI and seeing if the identity key we get
back is what we expect. If not, we upload it again as if it were the
first time.
2022-04-28 11:59:50 -07:00
Igor Solomennikov
f3b2118d0e [IOS-2364] Fix zero TimeInterval formatted as "0" instead of "0:00". 2022-04-28 10:55:11 -07:00
Martin Böttcher
54b743de2d
moved older stringsdict changes into new branch; minor changes (#4205)
moved older stringsdict changes into new branch
2022-04-28 17:41:43 +02:00
Michelle Linington
82e9f8d0b2 Wait for stories migrations 2022-04-27 12:25:46 -07:00
Michelle Linington
cb8436faca Lint 2022-04-27 12:25:10 -07:00
Michelle Linington
98846da1f1 Adjust disappearing message index
The existing index was not useful for the query we needed. Running this
query would open a write transaction for several seconds on every
launch. This new index should be much faster.
2022-04-27 12:25:10 -07:00
Michelle Linington
1ef694e241 Enable native websocket in prod 2022-04-25 21:23:55 -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
Jordan Rose
36ec5454e9 Reset the identity key if initial pre-key creation fails
If the CreatePreKeysOperation fails on registration, we don't ever
retry it, and registration is considered to have failed anyway. If it
fails for the first time we create PNI keys, though, the identity key
will still be saved locally, and therefore we won't try again until
regular pre-key rotation happens. To guard against this, wipe a
newly-generated identity key if the upload to the service fails.
2022-04-22 18:11:42 -07:00
Jordan Rose
497853fc63 Eagerly send PniIdentity sync message after initial generation
If an existing account ever generates a new PNI identity key, it
should immediately tell its linked devices. This is faster than
waiting for a sync request, and also better for keeping linked devices
on the same page.
2022-04-22 17:45:37 -07:00
Evan Hahn
0cb796bff6 "Feature flags for .qa." 2022-04-21 16:26:12 -05:00
Evan Hahn
d5589e0069 "Feature flags for .beta." 2022-04-21 16:23:54 -05:00
Nora Trapp
ecd9b2f6e8 Enable storiesMigration2 2022-04-21 11:01:22 -07:00
Nora Trapp
7acb6aa640 Fix DM timer handling for story replies 2022-04-21 11:00:12 -07:00
Nora Trapp
f2473a01a0 Fix quoting story reactions 2022-04-21 11:00:12 -07:00
Nora Trapp
1ce7bdd672 Support sending 1:1 story replies 2022-04-21 10:58:28 -07:00
Nora Trapp
65c6960ae7 Fix story replies queries 2022-04-21 10:58:28 -07:00
Evan Hahn
cefce5b2f2 Clean up donate URL code
This small change cleans up two things for the donate URL:

1. Moves it into a constant in `TSConstants`
2. Adds a trailing slash to the URL (because the server will redirect
   you without one)

I think these cleanups are useful by themselves, but I'll be using the
constant again in an upcoming change and split this off into its own
small commit.

Made sure I could still open the URL in the app.
2022-04-21 12:23:37 -05:00
Jordan Rose
7238e957ec Allow running a SQLite integrity check when the app fails to launch
The results are *not* automatically logged in case they contain
sensitive data. (They shouldn't, but we don't control this output
format.)
2022-04-21 09:47:05 -07:00
Evan Hahn
636b417390 Upgrade GRDB to version 5.23.0
This upgrades [GRDB][0] from v4.3.0 to v5.23.0, the latest version.

I closely followed the [migration guide][1] and stole from a prior
attempt at this upgrade. I also made sure to test the media gallery,
because that allegedly had problems before.

[0]: https://github.com/groue/GRDB.swift
[1]: 6d3f309cad/Documentation/GRDB5MigrationGuide.md
2022-04-20 09:08:50 -05:00