Commit Graph

606 Commits

Author SHA1 Message Date
Jordan Rose
8d9ab17a43 Treat missing pre-keys like other decryption failures
In particular, we want to send a retry request for messages sent with
pre-keys we don't have.
2022-11-14 14:02:48 -08:00
Evan Hahn
5c55c848d1 Add card validation code
This code is currently dormant, but will be useful in an upcoming
change.

Check the tests to see how this works.
2022-11-11 14:24:41 -06:00
Evan Hahn
ec78cc3a0a
Hide Apple Pay UI when the server disallows your region
_I recommend reviewing this with whitespace changes disabled._

The server's `global.donations.apayDisabledRegions` is a list of regions
(phone number prefixes) where Apple Pay is disallowed. This respects
that.
2022-11-10 16:19:47 -06:00
Evan Hahn
859ef8e9e6
Swiftify test-only call message handler
This change should have no user impact.

This converts `OWSFakeCallMessageHandler` to Swift (renaming it to
`FakeCallMessageHandler`). It was a mechanical conversion.
2022-11-10 12:46:13 -06: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
74d8d25a04 Move SignalServiceKit string tests to correct file
_This change should have no user impact._

We add some stuff to `String` in `SignalServiceKit`.

Before, we tested this in the `SignalTests` target. Now, it's in the
`SignalServiceKitTests` target.

All I did was move some lines. I didn't change the tests at all.

I think this is a good change on its own but it may be useful in an
upcoming change.
2022-11-07 14:31:15 -08:00
Evan Hahn
771a6f5488 Swiftify OWSDisappearingMessagesJobTest
This is a test-only change.
2022-11-03 11:48:52 -07:00
Evan Hahn
b7cb7eb403
Test TSContactThread's canSendChatMessagesToThread() 2022-10-28 16:16:00 -05:00
Evan Hahn
4675434c6c Add FiatMoney type
This change should have no user impact.

We commonly pair a currency, like USD, and an amount, like 1.23. This
adds the `FiatMoney` struct. It's a simple struct with two fields.

After adding it, I tried to use it everywhere. (It's possible I missed a
spot.)

I think this is a useful change on its own, but it'll be nice for an
upcoming change, too.

See also: [Android's equivalent class][0].

[0]: cb65347bb3/core-util/src/main/java/org/signal/core/util/money/FiatMoney.java (L1)
2022-10-26 17:04:51 -05:00
Sasha Weiss
1cb90e245f
Fetch and persist remote megaphones 2022-10-26 15:03:08 -07:00
Harry
9436ee6608
Use read state for the stories tab bar badge
* Use read timestamp in story badge count

* Add StoryBadgeCountManager

* Manager stories tab bar badge count in StoryBadgeCountManager

* Don't mark stories read while the app is backgrounded. Mark them read when foregrounding and on the tab bar

* Only mark the latest story per context as read

* fix tests
2022-10-18 16:22:50 -07:00
Nora Trapp
781444df45 Drop incoming stories from non-admins in announcement groups 2022-10-18 11:09:10 -07:00
Evan Hahn
623b1909b2
Prefer Decimal over NSDecimalNumber
This change should have no user impact.

We use `NSDecimalNumber` and `Decimal`. This tries to standardize on
`Decimal` where possible (though the former is still needed in a few
places).

Mostly a mechanical change, though a few little things changed.
2022-10-18 09:43:46 -05: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
3ffa2dca2c
Fix nullability for countryNameFromCountryCode 2022-10-11 17:30:58 -07:00
Evan Hahn
1b00741b6d
Fix remaining SwiftLint failures, lint more strictly
This fixes our remaining SwiftLint violations, which were small.

It also updates the precommit script to fail if any violations are
found, even warnings. This will cause CI to fail if you include a file
that isn't SwiftLint-compatible.
2022-10-07 12:00:26 -05:00
Max Radermacher
974b643234
Reduce likelihood of flaky test failures 2022-10-07 09:36:04 -07:00
Evan Hahn
518d8dfc58
Swiftify fingerprint test
A mechanical change. I updated the code that tests the result to be a
little more thorough.
2022-10-07 09:29:28 -07:00
Evan Hahn
9274b67d86 Swiftify proto parsing test
I also moved it to the `SignalServiceKit` tests because it's part of
that target, not the `Signal` target.
2022-10-07 01:07:31 +00:00
Evan Hahn
349681ff85
Attempt to recover corrupted databases
If a user's database is corrupted, we now try to fix it. I recommend
reviewing `DatabaseRecovery` to see how this works, and
`DatabaseRecoveryViewController` for the bulk of the UI.
2022-10-06 16:42:19 -05:00
Harry Sanabria
039571e440 Fix legacy onboarding story cleanup 2022-10-06 12:10:27 -07:00
Nora Trapp
9eb1c52dca Fix test 2022-10-05 12:29:39 -07:00
Nora Trapp
1e613fe438 Use unrestricted sealed sender for story sends 2022-10-05 12:24:13 -07:00
Evan Hahn
56589799cb
Clean up registration ID generation
_This change should have no user impact._

This cleans up the way we generate registration IDs. It:

- Rewrites the generation code in Swift
- Removes the "sneaky transaction" method. I did this for clarity, and
  because we won't use it for much longer
- Turns a log warning into a regular log—generating a registration ID is
  not a problem
- Adds tests

I think this is a useful change on its own, but will be handy for an
upcoming change, too.
2022-10-05 14:09:07 +00:00
Evan Hahn
09a279e55d Swiftify fake message sender
This should only affect tests.

This was a pretty mechanical conversion. I removed some unused variables
while I was here, too.
2022-10-05 10:50:53 +00:00
Evan Hahn
b5e64e9fce Speed up link preview search code
Previously, we collected all URL matches and then searched through them.
Now, we search lazily, which should improve performance.

I added a perf test that repeats a URL a million times. The new code
finishes in ~0.001 seconds on my machine. The old code does not finish.
2022-10-04 14:09:00 -07:00
Evan Hahn
a066511a62 Remove useless test setup/teardown
We had a lot of functions like this, which are useless:

    override func setUp() {
        super.setUp()
    }

This removes them.
2022-10-04 14:06:34 -07:00
Harry
74228f424e
Add StoryContextAssociatedData to compute story tab badge count without hidden stories
* Add StoryContextAssociatedData and db migrations

* Remove hideStory from ThreadAssociatedData

* Remove lastViewedStoryTimestamp and lastReceivedStoryTimestamp from TSThread

* drop deprecated columns in db migration

* add indexes

* dump schema.sql

* Update unviewed stories SQL query

* fix thread fetching for incoming story messages

* reload story tab badge when StoryContextAssociatedData changes

* Add test for TSGroupModel backwards-compatible deserialization

* move db migration

* Only use StoryContextAssociatedData for story badge count

* update StoryContextAssociatedData lastReceivedTime when a story message is deleted

* catch group threads for outgoing story messages too

* clean up sql query

* Only update lastReceievedStoryTimestamp for remote deletions

* add latestUnexpiredTimestamp to StoryContextAssociatedData
2022-10-03 21:16:01 -07:00
Evan Hahn
4a0141be41
Omit E164 from outgoing envelopes
[Android][0] and [Desktop][1] have already removed this field. This
follows suit.

The highlights:

- `SignalService.proto` removes some fields by making them `reserved`
- `ProtoWrappers.py` updates our code generation to support addresses
  that only have a UUID (previously, you needed both a UUID and E164
  field)
- Most everything else is removing E164s

[0]: 9c266e7995
[1]: 2b0d3cab40
2022-10-03 23:55:39 +00:00
Max Radermacher
0db3fb8106 Remove unsupported localizations
Also, clean up “Known Regions” in Xcode.
2022-09-29 16:13:06 -07:00
Nora Trapp
b962b752cb Don't auto-migrate groups on app launch 2022-09-29 09:35:00 -07:00
Sasha Weiss
063acc1419
Batch messageId notification cancellations 2022-09-27 14:26:44 -07:00
Evan Hahn
e2f7ee47f4
Remove unused methods from message processing test
`MessageProcessingIntegrationTest` has some unused methods. These were
added in ec66f3b21e. According to George,
they're no longer needed and may have been added mistakenly.
2022-09-27 11:49:29 -07:00
Evan Hahn
7a357a9cd3 Harden isValidProxyLink against strange URLs 2022-09-26 13:48:00 -07:00
Evan Hahn
4da042c1d5
Clean up database corruption storage code
_This change should have no user impact._

The database corruption flag lives on `UserDefaults`. Currently, this
flag is controlled through `SSKPreferences`, but I kinda think that's
the wrong place—database corruption isn't really a user preference.

This moves it into its own file, tests it, and [drops booleans in favor
of an enum][0]. I think this is useful on its own, but also prepares us
for an upcoming change.

[0]: https://www.luu.io/posts/dont-use-booleans
2022-09-23 18:19:02 +00:00
Evan Hahn
c5b4f67613 Swiftify contact thread tests
_This change should have no user impact._

A very mechanical change. No surprises.
2022-09-22 14:41:59 -07:00
Evan Hahn
11c2cf0813
Add basic test for database migration
_This change should have no user impact._

This adds a basic test for database migration, and makes the necessary
changes to make that possible.
2022-09-22 17:24:40 +00:00
Evan Hahn
3cf796e55c
Add utility for remaining disk space 2022-09-22 09:28:42 -07:00
Igor Solomennikov
094fa0f30d
Allow attaching links to text stories with "Generate Link Previews" setting being OFF. 2022-09-21 14:55:49 -07:00
Max Radermacher
88bc6e43d8 Refactor encodeE164s
- Remove duplicate check for a `+` at the beginning of each value.

- Don’t return a big-endian UInt64 from a method. The type information
  (unfortunately) doesn’t include endianness, which makes that approach
  somewhat more error-prone.

- Add a type that tracks validated input/output pairs. Future changes
  will want to perform the validation and then use both input & output.
2022-09-21 12:47:29 -07:00
Max Radermacher
3fdaf367e1
Consolidate Int <-> Data logic 2022-09-21 12:08:45 -07:00
Max Radermacher
73c70d328f
Add UUID.from(data:) that returns the byte count
Co-authored-by: Evan Hahn <69474926+EvanHahn-Signal@users.noreply.github.com>
2022-09-21 11:34:41 -07:00
Nora Trapp
9776699137 Sync when contacts become unregistered 2022-09-15 14:09:03 -07:00
Evan Hahn
5a15f2f224
Move message padding to Data
Message padding is currently on `NSData`.

This moves it to Data, and rewrites everything in Swift.

Tested this by sending and receiving a message.
2022-09-15 12:50:20 -05:00
Nora Trapp
6807ad8f02 Properly drop stories from untrusted sources 2022-09-15 10:26:34 -07:00
Evan Hahn
95566b6952 Swiftify group thread test
A very mechanical change.
2022-09-14 02:18:33 +00:00
Evan Hahn
4445f0cedf
Improvements to PNG transcoding 2022-09-13 23:22:50 +00:00
Harry
5c5058c1d1
Sync onboarding story view state
* add hasViewedOnboardingStory to account record

* Post notifications for TSAccountManager onboarding state

* fix bug with local addressing when updating profile key data

* sync onboarding story view status with accountRecord

* do the bare minimum to keep tests working

* use asVoid
2022-09-13 14:05:34 -07:00
Evan Hahn
42055d6f50 Actually test an APNG in detector code
This change should have no user impact.

`NSData#isAnimatedPngData` detects whether something is an animated
PNG. Its tests don't actually check a real APNG, though. This adds such
a test.
2022-09-12 20:27:53 +00:00
Evan Hahn
59dde0bc05 APNG tests don't need special Signal-specific behavior
This change should have no user impact.

These tests don't need to inherit from `SSKBaseTestSwift`. They can just
inherit from `XCTestCase`.
2022-09-12 18:59:19 +00:00