Commit Graph

7736 Commits

Author SHA1 Message Date
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
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
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
Martin Böttcher
9f66cce5e1 made iterating job records more stable 2022-04-19 19:47:44 +02:00
Martin Böttcher
04892da490 error iterating job records does not crash the app anymore 2022-04-19 19:47:44 +02:00
Evan Hahn
ef6c044a54 Remove legacy donation view
_I recommend reviewing this with whitespace changes disabled._

We have a kill switch that disables badge acquisition. If that kill
switch is active, we show a one-time donation view.

That kill switch has been off since January of 2021, so I think we can
remove this one-time donation view. That lets us remove hundreds of
lines of code, but it will also make future donation-related changes a
bit easier.
2022-04-19 10:46:04 -05:00
Jordan Rose
c8de10815a Remove internal lock from OWSIdentityManager
This isn't protecting any local state and wasn't being used
consistently, and it can result in lock inversion deadlocks if
-readWithUnfairLock: is called within a database write transaction.
2022-04-18 18:19:31 -07:00
Jordan Rose
a61088b76f Add "Export Database" to the internal settings, for debugging 2022-04-18 17:36:42 -07:00
Max Radermacher
bc53916301 Convert all(Testable)?Flags to functions 2022-04-18 16:28:01 -07:00
Max Radermacher
a353e8d757 free() the result of class_copyPropertyList
The docs say that the caller must `free()` the result.
2022-04-18 14:52:26 -07:00
Max Radermacher
c097b1189c Extract allPropertyNames from allFlags
This isolates all of the Obj-C runtime code in its own function.

If a class doesn’t have any properties, `class_copyPropertyList` may
return `NULL`. Previously, this would have resulted in an error while
force unwrapping the result, but all `BaseFlags` subclasses have
properties, so that wasn’t a problem in practice. Now, an empty array
will be returned, which seems correct when there aren’t any properties.
2022-04-18 14:52:26 -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
ad8ab4a386 Implement findTestableFlags via buildFlagMap
The testable flags are a subset of all flags, so call the existing code.

This will cause the flags to be returned in an arbitrary order, but that
is fine since they’re only used in [one place][1], and that place sorts
the results before using them.

[1]: c77939a907/Signal/src/ViewControllers/AppSettings/Internal/TestingViewController.swift (L45-L48)
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
Nora Trapp
27e03b6a70 Render 1:1 story replies 2022-04-15 19:28:14 -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