Commit Graph

7498 Commits

Author SHA1 Message Date
Igor Solomennikov
2128a2f7f2 Lint. 2022-04-12 17:38:21 -07:00
Igor Solomennikov
56217c1c7b Add methods for convert TimeInterval and Int into localized string.
• OWSFormat.localizedDecimalString(from:) would convert Int into
  a localized string using `decimal` style (preferred style for displaying
  in the UI).
• OWSFormat.localizedDurationString(from:) would convert a time interval
  into localized string like "HH:mm:ss", using current locale.
2022-04-12 17:38:21 -07:00
Evan Hahn
b743b4efc7 Remove donation receipts feature flag
As we discussed, let's remove this flag and just release normally.
2022-04-12 13:38:12 -05:00
Jordan Rose
d91a5775cb Don't create PNI pre-keys on a linked device without an identity key
We already have this sort of check on the Refresh/Rotate jobs, but for
the Create job you should always have an identity key at the time
creation is requested. That's not true when mixing a new linked device
with an old primary, though. Add some defensive checks so the linked
device won't generate an identity key and try to upload it; it should
skip the job instead and ask the primary for its identity key later.
2022-04-11 16:37:20 -07:00
Jordan Rose
7ba2a8ee2d Avoid deserializing envelope data more than necessary
Our envelopes go through a lot of transformations during processing:
0. If using REST, JSON delivered by the server is converted to
   SSKProtoEnvelope (MessageFetcherJob.buildEnvelope(messageDict:))
1a. If using REST, envelopes are serialized and enqueued for individual
    jobs (MessageFetcherJob.fetchMessagesViaRest())
1b. If using the web socket, the message is deserialized from protobuf
    (MessageProcessor.processEncryptedEnvelopeData(...))
2. If the envelope uses sealed sender, the sender is written into
   a new proto and reserialized
   (OWSMessageDecryptor.decryptUnidentifiedSenderEnvelope(...))
3. The serialized envelope is deserialized *again* for preprocessing,
   GV2 discard mode checking, and (potentially) actual processing.
   (MessageProcessor.processEnvelope(_:transaction:))
4. If the envelope is delayed, it'll be deserialized when it's finally
   processed
   (IncomingGroupsV2MessageJob.envelope)

This commit improves the situation by
- skipping the serialization in step #1a
- skipping the serialization in step #2
- reusing the SSKProtoEnvelope from decryption in message processing,
  avoiding the deserialization in step #3
- potentially serializing in step #4 if there's no up-to-date
  serialized data (either because the envelope was modified, or
  because it came from REST and we never had it in the first place)

Note that IncomingGroupsV2MessageJob is persisted across transactions
in the database, so it needs the envelope to be serialized.
2022-04-11 15:55:39 -07:00
Jordan Rose
df5dd99293 Decide whether to discard a GV2 message without building an entire job
We already have the deserialized envelope at the point where we're
first checking, but also we don't even use any information from it
besides the source address.

This commit also stops checking whether a group context has a revision
once we've created a job; I think that's reasonable.
2022-04-11 15:55:04 -07:00
Jordan Rose
1433246f6a Stop passing SSKProtoEnvelopes to get GV2 context info
They aren't needed; the code only checked that the envelope had some
content, any content.

No functionality change in practice: all call sites already had
plaintext data alongside the envelope, where that data was assumed to
come from the envelope, proving it had content.
2022-04-11 15:55:04 -07:00
Jordan Rose
72ea40063c OWSMessageDecryptor: make it clearer when envelopeData is modified
"Only for a sealed sender message."
2022-04-11 15:55:04 -07:00
Jordan Rose
1301d1fe00 SSK: Collapse OWSMessageUtils into OWSMessageManager
No one is using the unreadCount* APIs anymore *except*
updateApplicationBadgeCount, so we can inline them and then move that
function to an existing class.
2022-04-11 15:17:39 -07:00
Jordan Rose
49608044b7 SSK: Remove obsolete OWSMessageDecryptJob
This hasn't been used since before GRDB.
2022-04-11 14:46:43 -07:00
Evan Hahn
8b072620a6 Add "Donation Receipts" view 2022-04-11 16:21:12 -05:00
Nora Trapp
3baa04026c Drop stories with pending message requests 2022-04-11 12:34:10 -07:00
Nora Trapp
73140fd1bf Drop duplicate story messages 2022-04-11 12:17:46 -07:00
Michelle Linington
9f1d45f67f Merge branch 'release/5.35.0' 2022-04-09 16:25:58 -07:00
Michelle Linington
dc3c91cf0c Bug fix from the PR feedback changes
The initial pass at this short-circuited away the insertion. This was
caught by unit tests.
2022-04-08 19:51:16 -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
Michelle Linington
31dc8a03a2 Fixes a couple bugs caught during testing 2022-04-08 19:01:43 -07:00
Michelle Linington
ac4c2caede Rewrite BlockingManager to be transaction aware
This maintains much of the spirit of the original implementation while
being almost a total rewrite of its implementation. Before,
BlockingManager would load it's entire state into memory and only touch
the database if there's a compelling reason.

This new implementation maintains this behavior. Block state is always
kept in memory (there's certainly a more efficient way to do this but
that's out-of-scope for this change). The difference is now every time
the cached state is accessed, BlockingManager consults a change tag
stored in the database.

By requiring a transaction to access block state, we can make sure that
our block state remains up-to-date in cases where the database is
changed by another process..
2022-04-08 19:01:43 -07:00
Michelle Linington
988e6b8e14 Require transactions for the remainder of BlockingManager's interface 2022-04-08 19:01:43 -07:00
Michelle Linington
dd0a7f6b80 Require transaction to check blocked address state 2022-04-08 19:01:43 -07:00
Michelle Linington
739af9372a Require transaction to check blocked thread state 2022-04-08 19:01:43 -07:00
Michelle Linington
2ef1cc02df Reload blocking manager state on an external database change 2022-04-08 19:01:43 -07:00
Jordan Rose
5ecb9519b9 Refresh PNI pre-keys along with ACI pre-keys
Pre-keys are refreshed at regular (throttled) intervals, but the
"refresh" operation will only actually upload new pre-keys if the
server says we're running low. In addition, after the "refresh",
there's a "rotation" operation for the signed pre-key if the current
one is more than two days old. This only runs if the refresh was
skipped, since uploading new one-time pre-keys is already an
opportunity to rotate the signed pre-key (and it's worth doing so,
since pre-keys running low can indicate high traffic).

None of this has changed. However, we can now do this for both ACI and
PNI pre-keys. This reworked +[TSPreKeyManager
checkPreKeysWithShouldThrottle:] quite a bit to declare the proper
operation dependencies, which isn't *strictly* necessary because the
queue they're executed on is already limited to a
maxConcurrentOperationCount of 1. We could remove that at this point
with proper use of "barrier" operations, but since all the operations
are hitting the server and account updates have to be serialized on
*that* end, there doesn't seem to be much of a benefit.
2022-04-07 14:06:27 -07:00
Jordan Rose
cdd24d5531 TSPreKeyManager: Simplify pre-key refresh throttling
No need to make an operation, then make another operation to cancel
it. Just don't schedule the main operation in the first place.
2022-04-07 14:06:27 -07:00
Jordan Rose
2b1f8c8003 Move throttling logic inside RotateSignedKeyOperation
This simplifies +[TSPreKeyManager checkPreKeysWithShouldThrottle:],
with more to come.
2022-04-07 14:06:27 -07:00
Evan Hahn
71630c85e8 "Feature flags for .qa." 2022-04-07 14:53:12 -05:00
Evan Hahn
637c139d0b "Feature flags for .beta." 2022-04-07 14:52:44 -05:00
Jordan Rose
23ad77b218 TSPreKeyManager: check for PNI signed pre-key upload failure too
After a certain number of failures over a certain number of days, the
app will refuse to send messages until a new signed pre-key can be
uploaded. This should apply to both ACI and PNI pre-key upload
failures. (If we wanted to distinguish them, we could, but this is
mostly a fallback mechanism. Normal pre-key refreshing will come
soon and will not tie the two together.)
2022-04-07 10:23:39 -07:00
Jordan Rose
f0de694156 Rotate the PNI signed pre-key along with the ACI signed pre-key
This only applies to explicit rotations of *just* the signed pre-key.
Including this for regular pre-keys as well is more complicated.
2022-04-07 10:23:39 -07:00
Jordan Rose
891fa602c6 Move pre-key update failure tracking into SSKSignedPreKeyStore
...from TSPreKeyManager. This will make it easier to track failures
for ACI and PNI pre-keys separately, and removes some indirection and
possible weird states.
2022-04-07 10:23:39 -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
849d6ee60a Generate PNI identity key and pre-keys for existing accounts
At launch time, if a primary device doesn't have a PNI identity key,
it should generate one immediately, as well as pre-keys. If a linked
device doesn't have a PNI identity key, it messages the primary to ask
for one; when it gets a response it generates its own pre-keys.
2022-04-04 15:19:10 -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
Nora Trapp
702e38e7ff Break up index migrations over multiple releases 2022-04-01 16:21:21 -07:00
Michelle Linington
f4539ab83c PR Feedback: Restrict logging 2022-04-01 14:55:30 -07:00
Michelle Linington
29dc1eefcd Lint 2022-04-01 14:55:30 -07:00
Michelle Linington
fc69576a74 Include status code in network request success log message 2022-04-01 14:55:30 -07:00
Michelle Linington
049b68c4ea Better description for OWSHTTPHeaders 2022-04-01 14:55:30 -07:00
Nora Trapp
409e89e721 Add index for story reply counts 2022-03-31 01:52:54 -07:00
Nora Trapp
60b35f3e60 Support preview only text stories 2022-03-31 00:40:47 -07:00
Nora Trapp
78eb06a812 Update story list sorting to match spec 2022-03-31 00:40:47 -07:00
Nora Trapp
378cc730d1 codegen 2022-03-31 00:37:56 -07:00
Nora Trapp
e662b099dd Check if a user is stories capable when sending group replies 2022-03-31 00:37:56 -07:00
Nora Trapp
03bdb55e21 Add context menu to group replies 2022-03-31 00:36:20 -07:00
Nora Trapp
c4b9f18a1a Properly store serverTimestamp on incoming story reactions 2022-03-31 00:34:33 -07:00
Nora Trapp
df4eed775b Make sure storyReactionEmoji is cleared when story reactions are remotely deleted 2022-03-31 00:34:33 -07:00
Nora Trapp
0b662ed6e2 Fix lint issues 2022-03-31 00:34:33 -07:00
Nora Trapp
729864b638 Support sending story reactions 2022-03-31 00:34:33 -07:00