Commit Graph

398 Commits

Author SHA1 Message Date
Harry
a146e18aaf
Set up account state and exit registration
* Go to chat list view after registration

* sync system contacts during registration

* Use explicit local credentials for storage service operations during registration

* fix tests

* Quick hack to get through double pin confirmation

* Finishing touches

* lint

* fix build

* reload phone number discoverability after storage service sync

* fix tests again

* Take chat auth on account and contact record initializers

* Change around branches for clarity in OWSUserProfile

* pr comments

* Split ChatServiceAuth into the same and AuthedAccount

* fix tests

* merge woes
2023-03-09 21:54:51 -08:00
Max Radermacher
898fd2c4d5
Clean up queue names 2023-02-27 14:16:09 -08:00
Max Radermacher
59593c3c97
Add ServiceId & E164 types
* Use the new E164 type in a few places
* Use the new ServiceId type in a few places
2023-02-21 23:13:46 -08:00
Max Radermacher
c13ebc7482
Consolidate storage service code 2023-02-10 17:58:51 -08:00
Harry
003cc19e62
Update SignalCoreKit. Use explicit DispatchQueue instead of relying on the implicit type on promise 'on' params
* Use explicit DispatchQueue instead of relying on the implicit type on promise 'on' params

* Update SignalCoreKit
2023-02-07 16:14:39 -08:00
Sasha Weiss
70d018a55d
.redundantChange should not be considered retryable 2023-02-07 12:57:51 -08:00
Max Radermacher
50e0405276
Add ContactDiscoveryManager
RATE LIMITS & IS CRITICAL PRIORITY

Before this change, there was a notion of “critical” discovery tasks
that had their own rate limit, and that rate limit was used for
UUIDBackfillTask. In this change, that logic has been generalized to
consider a separate rate limit for additional request types.

QUEUE PRIORITIES

All of the discovery operations were updated to use `.userInitiated` as
their priority. Before this change, the `UUIDBackfillTask` and message
sending flow used lower priorities. However, both of those should use
higher priorities -- the former blocks receiving messages and the latter
blocks outgoing messages. This change allows the code to be simplified.

TESTS

This removes most of the existing `UUIDBackfillTaskTest` test cases
(they were commented out) and all of the `ContactDiscoveryTaskTest` test
cases (which were for the rate limiter, which has been moved elsewhere).

It introduces a few new tests. These aren’t meant to be exhausive;
instead, they’re meant to hit most of the code in the new classes and a
few specific edge cases that aren’t likely to be hit in normal use.
2022-11-15 13:37:28 -08:00
Sasha Weiss
242dfd2bce
Add all JobQueues to environment, via a wrapper
Currently, only some `JobQueue` types are initialized during startup
(as part of `Environment`, or `SSKEnvironment`). Initialization is
required, however, for a `JobQueue` type to restart any latent jobs.
That means that, for example, a durable `SendGiftBadge` job that failed,
and should be reattempted at a later date, will not in fact be restarted
since no `SendGiftBadgeJobQueue` will be initialized at launch.

This change adds `SSKJobQueues` and `SignalMessagingJobQueues` types,
which are intended to be singletons that hold within them a singleton
job queue for each of our `JobQueue` types. These wrappers are added to
`SSKEnvironment` and `Environment` (from SignalMessaging) respectively,
ensuring that all the `JobQueue`s they contain are initialized as part
of environment setup. The wrappers also avoid the need to add a new
property to the (already large) environment types for each new future
`JobQueue`.

This change also updates all existing call sites that accessed a
`JobQueue` from an environment object, to direct that access now through
the wrapper type.
2022-11-09 14:08:44 -06:00
Evan Hahn
a941c82c14
Prefer isEmpty with strings
This change may improve performance slightly but should have no other
user impact.

`myString.isEmpty` is faster than `myString.count == 0` or equivalent,
because computing `count` may require iterating over the string.

I tried to fix all occurrences of this.

Tested this by sending a message in a group and doing a full
re-registration, just in case I broke something there.
2022-11-01 17:53:46 -05:00
Max Radermacher
3e129edfcd Limit scope of undiscoverable gv2 phone numbers
If we’ve recently discovered that a phone number can’t be discovered,
there isn’t much benefit to checking again.

However, for other parts of the migration flow, we still want to
consider such users. For example, sometimes we want to require all users
to have a UUID to perform a migration. Before this change, we might
return a false positive after performing a CDS lookup since we wouldn’t
check whether or not recently undiscoverable users have a UUID.

In another case, we’re intentionally excluding users without UUIDs. In
this case, the end result is the same whether we drop them during the
first pass or the second pass, but the intent is more clear if we drop
all such users during the second pass.

Lastly, we want to fetch profiles even for undiscoverable users, even
though this operation is likely to fail.
2022-10-24 10:21:05 -07:00
Max Radermacher
66a6b428bb Remove internal-only profile key merging code
This is no longer necessary.
2022-10-17 09:27:55 -07:00
Evan Hahn
370ff654e7
Change license to AGPL
Change license to AGPL

This commit:

- Updates the `LICENSE` file

- Start every file with something like:

      // Copyright YEAR_FIRST_PUBLISHED Signal Messenger, LLC
      // SPDX-License-Identifier: AGPL-3.0-only

---

First, I removed existing license headers with this Ruby 3.1.2 script:

    require 'set'

    EXTENSIONS_TO_CHECK = Set['.h', '.hpp', '.cpp', '.m', '.mm', '.pch', '.swift']

    same = 0
    different = 0

    all_files = `git ls-files`.lines.map { |line| line.strip }
    all_files.each do |relative_path|
      if relative_path == 'Pods'
        next
      end

      unless EXTENSIONS_TO_CHECK.include? File.extname(relative_path)
        next
      end

      path = File.expand_path(relative_path)

      contents = File.read(path)
      new_contents = contents.sub(/\/\/\n\/\/  Copyright .*\n\/\/\n\n/, '')

      if contents == new_contents
        same += 1
      else
        different += 1
      end

      File.write(path, new_contents)
    end

    puts "updated #{different} file(s), left #{same} untouched"

I'm sure this script could be improved, but it worked well enough.

Then, I created `Scripts/lint/lint-license-headers` and ran it to auto-
fix a lot of files. This changed the mode of some files, but I think
that's actually desirable. For example,
`SignalServiceKit/src/Util/AppContext.m` previously had a mode of
`0755/-rwxr-xr-x`, and it's now `0644/-rw-r--r--`.

Then I fixed some stragglers and updated the precommit script.

See [a similar change in the Desktop app][0].

[0]: 8bfaf598af
2022-10-13 08:25:37 -05:00
Max Radermacher
56bfcf3d72
Remove redundant fetches during gv2 migration
The `attemptToMigrateByCreatingOnService` method has a single caller,
and that caller also calls `tryToPrepareMembersForMigration` first. The
former is called when `migrationMode`’s `canMigrateToService` is true,
and the latter does a CDS lookup & profile key fetches if
`migrationMode`’s `isOnlyUpdatingIfAlreadyMigrated` is false; these two
conditions are true in the same situations. As a result, these CDS
lookups and profile key fetches aren’t necessary.

(This also removes an extra `firstly` block. I’d recommend ignoring
whitespace while reviewing the change.)
2022-10-12 10:17:26 -07:00
Nora Trapp
b962b752cb Don't auto-migrate groups on app launch 2022-09-29 09:35:00 -07:00
Nora Trapp
6930ffe2fa Remove old group capabilities 2022-09-29 09:35:00 -07:00
Sasha Weiss
ac97aeba92
Migrate to using ExpiredProfileKeyCredentials 2022-09-26 14:33:57 -07:00
Sasha Weiss
bb03be620e
Use "modern" proto fields instead of presentation for incoming group changes 2022-09-20 10:44:42 -07:00
Sasha Weiss
fb1a4979d4
Remove guard around bannedAtTimestamp 2022-09-14 13:36:19 -07:00
Sasha Weiss
edc9b13ba3
Use a dedicated error to recover from conflicts when updating a group on the service 2022-09-13 15:28:51 -07:00
Sasha Weiss
640cb03a79
Do not retry for GroupsV2Error.conflictingChange 2022-09-13 11:31:03 -07:00
Nora Trapp
ad34089ffe Sync group stories with storage service 2022-09-12 12:00:14 -07:00
Sasha Weiss
74852a3ebd
Merge almost-identical profile key fetch methods 2022-09-09 16:21:09 -07:00
Sasha Weiss
f80ed7964a
Only recover from errors in performServiceRequestAttempt 2022-09-09 09:47:57 -07:00
Sasha Weiss
f37a0040ad
Replace AuthCredential with AuthCredentialWithPni 2022-09-07 15:39:50 -07:00
Sasha Weiss
4085771309
Centralize force-casts in a VersionedProfilesSwift dependency 2022-09-07 12:43:09 -07:00
Sasha Weiss
569cdb2aad
Durable jobs for leaving groups 2022-08-26 13:13:23 -07:00
Sasha Weiss
11e2729c49
Auto-leave groups when added by a blocked contact 2022-08-25 16:20:15 -07:00
Sasha Weiss
24d3d0e68d
Remove requiredRevision arg from updateExistingGroupOnService, and make it private 2022-08-25 12:41:55 -07:00
Sasha Weiss
56b9b2c139
Wait for group updates before doing profile key updates 2022-08-25 11:54:01 -07:00
Harry
33e26b6c4c
Migrate OWSSignalService from objc to swift, and split it into a protocol and implementation
* Split OWSSignalService into a swift protocol and implementation, migrated from objc

* Put OWSSignalService under SSKEnvironment and use mock in mock environment

* Rename from basename + impl to protocol + basename

* extend mock functionality a bit

* pr feedback
2022-08-24 14:36:52 -07:00
Harry
2950667ac9
Split OWSURLSession into a protocol and implementation
* Split OWSURLSession into a protocol and implementation

* Add OWSURLSessionMock

* Rename from basename + impl to protocol + basename

* add simple init for mock session

* nits from pr comments

* pr comments 2
2022-08-24 13:33:27 -07:00
Sasha Weiss
7146a02821
Serialize group updates using OWSOperation 2022-08-17 13:18:31 -07:00
Sasha Weiss
c5f21a2e53
Allow a bannedAtTimestamp of 0 for incoming banned members 2022-08-17 12:52:48 -07:00
Sasha Weiss
9ff8c07e7e
Only auto-refresh groups that we know we are members of 2022-08-16 12:58:57 -07:00
Sasha Weiss
43943ca621
Organize GroupV2UpdatesImpl.swift 2022-08-10 16:50:23 -07:00
Sasha Weiss
7cf14333ad
Prevent empty group updates from clobbering that a member joined via invite link
Group snapshots fetched from the service do not store the
`didJoinFromInviteLink` field on their members, and when we parse a
snapshot into a group model we hardcode this value to `false` for all
members. However, we store that field locally on a `GroupMembership`'s
`MemberStateMap` when processing an "add members" change action, as the
field is provided in the `AddMember` change action proto.

This becomes an issue, since when we refresh the group's state from the
service (which we do periodically, e.g. when opening a group for the
first time after launch) the `GroupMembership` from the group's snapshot
on the service will not match the `GroupMembership` we have locally,
even though they are from the same revision, due to mismatched
`didJoinFromInviteLink` values (hardcoded in the snapshot).
Consequently, we believed we were "updating the group model in a user-
facing way", but the only change therein was clobbering a
`didJoinFromInviteLink: true` to `...: false`, which was 1) wrong and
2) did not have a description to show.

This commit changes `GroupMembership` to ignore values for
`didJoinFromInviteLink` when comparing equality. This means that when we
parse a snapshot into a `TSGroupModel` with all those values hardcoded
to false, but otherwise identical to our local, we will no longer see it
as different from our local (and subsequently clobber our local and
generate an empty update).
2022-08-03 15:04:31 -05:00
Sasha Weiss
5c69126ce0
Allow outgoing changes with only ban actions 2022-07-18 15:03:33 -07:00
Sasha Weiss (Signal)
9f6f4f1b5c
Remove correct request-denied-because-banned error from behind a feature flag 2022-07-18 11:18:35 -07:00
Sasha Weiss (Signal)
42e9608c73
Remove user from local group on request-to-join denied 2022-07-18 11:17:58 -07:00
Sasha Weiss (Signal)
9334ed3077
Ban and unban users as part of add/remove/deny group actions 2022-07-15 09:41:19 -07:00
Sasha Weiss (Signal)
98151dfd0d
Don't need transactions to build group models 2022-07-12 10:23:12 -07:00
Sasha Weiss (Signal)
ac341fdbbc
DRY out V2 group updates 2022-07-08 15:47:45 -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
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
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
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
Max Radermacher
2589f1e217
Remove GV2 rollout properties
* Remove manual groups v2 migration banner
* Remove “No UUID” subtitle when creating group
* Remove `areMigrationsBlocking`
* Remove `canManuallyMigrate`
* Remove `areManualMigrationsAggressive`
* Remove `canAutoMigrate`
* Remove `areAutoMigrationsAggressive`
2022-05-20 11:07:15 -07:00
Jordan Rose
4c8d7662a6 Add OWSIdentityManager.shouldSharePhoneNumber(with:transaction:)
When someone sends a message to your PNI, your responses (from your
ACI) must include a PNI signature, and the sealed sender certificate
you use during this period should include your phone number. This
confirms to the other user that your ACI is associated with your PNI.

This commit adds the state tracking that and ensures that both
TSOutgoingMessage and OWSUDManager check that state when building 1:1
messages and choosing certificates, respectively. Later commits will
set and clear this flag as needed.
2022-05-19 14:20:53 -07:00
Evan Hahn
29c0ddf60e Fix violations of SwiftLint's attributes rule
_I recommend reviewing this with whitespace changes disabled._

Most of these were `@objc` being on the same line, which I fixed with [a
silly script][1]—probably could've used `sed` if I were wiser. The rest
were manual fixes.

See [the SwiftLint documentation for this rule][0].

[0]: https://realm.github.io/SwiftLint/attributes.html
[1]: https://gist.github.com/EvanHahn-Signal/d353c93fa269c82b96baca0a1086521f
2022-05-14 09:07:42 -05: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