Commit Graph

568 Commits

Author SHA1 Message Date
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
Nora Trapp
942ba23d87 Ignore unregistered errors from all non-contact threads 2022-09-08 09:04:07 -07:00
Sasha Weiss
07a5e95d6a
Show the MemberActionSheet for tapped names in group system messages, reapplied 2022-09-06 14:40:01 -07:00
Max Radermacher
fec0b0417b
Use UUID.data instead of reimplementing its logic
Also add a few more tests for remote config buckets.
2022-09-06 12:41:25 -07:00
Harry
d955e68468
Disable flaky SystemStoryManagerTest case 2022-09-01 13:56:31 -07:00
Harry
8206766336
Up timeout for SystemStoryManagerTest for slow CI 2022-08-31 12:27:09 -07:00
Evan Hahn
787a688b08 Rewrite PhoneNumber.tryParsePhoneNumber tests
This change should have no user impact.

This commit:

- Rewrites the tests in Swift
- Removes some redundant tests
- For North American phone numbers, uses `555-01XX` phone numbers
  (because "only 555-0100 through 555-0199 are now specifically reserved
  for fictional use; the other numbers have been reserved for actual
  assignment)
2022-08-31 00:36:06 +00:00
Evan Hahn
a6b395b11f Remove long-skipped phone number tests for Mexico
This change should have no user impact.

This removes a test that's been skipped since 2020 (see
5c976b0acd). I think this is okay given
that (1) we've skipped it for over 2 years (2) [we already have some
tests for Mexican phone numbers][0].

[0]: 895c1b7576/SignalServiceKit/tests/Contacts/PhoneNumberTest.swift (L10-L25)
2022-08-30 16:46:37 -07:00
Harry
7ee39eef63
Add SystemStoryManager
* Add OnboardingStoryManager

* mark onboarding story viewed

* Add tests and fix issues that came up from testing

* up test timeout for slower CI

* rename SystemStoryManager and put into dependency injecton container

* Use viewed state on StoryMessage itself. Have SystemStoryManager observe app lifecyle events to automatically manage the onboarding story

* use iOS assets which are now in s3

* todo cleanup

* increment timestamp for uniqueness

* pr comments

* change literal delimiter

* Add ChainedPromise utility, tests, and use in SystemStoryManager

* discretionarily observe app backgrounding in SystemStoryManager

* renaming from PR comments
2022-08-30 14:49:59 -07:00
Evan Hahn
4fc5d75793 Update libPhoneNumber-iOS
This updates our libPhoneNumber dependency. See [the libPhoneNumber-iOS
commit][0].

According to [the upstream libphonenumber release notes][1], they
updated the formatting for +49 numbers. That caused a test to break, so
I updated it (and tested a few additional dialing codes).

[0]: 8b6f552682
[1]: 90503ecef3/release_notes.txt (L21)
2022-08-28 15:31:06 +00:00
Evan Hahn
5a0f836f0d Use "timestamp" instead of "timeStamp"
This change should have no user impact.

We use "timestamp", all lowercase, in most of the codebase. This makes
it consistent.
2022-08-26 14:17:12 -05:00
Evan Hahn
92ef1610fc Actually run OutgoingGroupUpdateMessageTest
I added these tests in da322d3bf9 but
didn't actually add them to the project! This adds them and runs them.
2022-08-25 11:14:49 -05:00
Evan Hahn
f997e5c7a4 Remove some tests that were never run
I added these tests in da322d3bf9, but we
decided that they're not worth it.

Also, it seems I forgot to add them to the project! So they were never
run anyway, outside of the times I ran them while developing.
2022-08-25 11:14:43 -05:00
sashaweiss-signal
efc697af23 Re-order lines in test harness to avoid a race condition 2022-08-24 16:21:13 -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
george-signal
87533d2b67
Improve phone number parsing.
* Improve phone number parsing.

Previously, if you entered a phone number
including a country code during registration you'd
have a duplicate country code. Signal on Android
did not have this bug because it uses a different
API inlibphonenumber. This diff changes iPhone to
use the same API, which is smart enough to remove
the country code from the phone number the user
entered if needed.

Co-authored-by: Evan Hahn <evanhahn@signal.org>
2022-08-23 11:56:06 -07:00
Max Radermacher
686f99f039 Fix ContactDiscoveryOperationTest
Make `encodeE164s` a static method since it doesn’t need to access any
details from the operation instance.

Also move the test to SignalServiceKitTests.
2022-08-22 09:11:42 -07:00
Evan Hahn
da322d3bf9 Add "urgent" boolean to outgoing messages
To improve message reliability, we're adding an urgency flag to outgoing
messages. For example, outgoing calls are urgent, but delivery receipts
are not. [Android][] and [Desktop][] have already done this work.

At a high level, I added an `isUrgent` property to `TSOutgoingMessage`s.
It defaults to `true`. Some subclasses, like
`OWSReceiptsForSenderMessage`, override it to return `false`.

Builds off of a few other commits (not necessary to understand this
commit, but might be useful for posterity):

- e858a0d916
- 8c6d2ebe8c
- 402b117221
- 2ba0cd764d
- 266a4663e9
- 8e5009bbf7

[Android]: dc04c8ed98
[Desktop]: 06190b1434
2022-08-18 07:35:41 -05:00
Evan Hahn
8c6d2ebe8c Test OWSRequestFactory.submitMessageRequest 2022-08-16 14:12:35 -05:00
Evan Hahn
402b117221 Test OWSRequestFactory.submitMultiRecipientMessageRequest 2022-08-16 14:12:35 -05:00
george-signal
bb33925499
Persist quoted replies
When you compose reply to a message but do not
send it, we would persist the text you entered but
would lose the quoted message to which you were
replying.

This commit adds support for persisting that
information.

ThreadReplyInfo is a new class that uses the
key-value store to associate a single optional
reference to a message with each thread.

The following behaviors are nw:
* When you enter the CVC the input toolbar is
  updated to have the quoted message.
* When you exit the CVC the quoted message is
  saved.
* When a thread is deleted, the quoted message is
  deleted.
2022-08-11 13:44:50 -07:00
Evan Hahn
266a4663e9 Add basic test for outgoing reaction message
This change should have no direct user impact.

`OWSOutgoingReactionMessage` was untested. This adds a basic test for
its `shouldBeSaved` method.

I think this is a useful change on its own, but may make future changes
easier, too.
2022-08-07 08:57:54 -05:00
Evan Hahn
6305cdc0e6
SignalServiceKit: no longer a separate pod
SignalServiceKit is currently a separate pod. This makes merges tedious
and error-prone. Ultimately, it slows us down. It might've made sense as
a standalone library before, but it's so tightly integrated now that it
isn't useful to have it be separate.

This changes that, and makes SignalServiceKit a "normal" target.

IMO, most of this change isn't that exciting—just a bunch of changes to
scaffolding. There's one slightly spicier change: our generated
`Acknowledgements.plist` is now a little more clever.

Co-authored-by: Max Radermacher <max@signal.org>
2022-08-05 16:14:15 -05: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
Evan Hahn
8e5009bbf7
Add simple test for TypingIndicatorMessage
This change should have no direct user impact.

This tests `TypingIndicatorMessage`'s `isOnline` getter.

I plan to add additional tests to this file in a future commit, but I
think this is a useful change on its own.
2022-08-01 11:44:16 -05:00
Evan Hahn
c988fdfee6 Convert OWSAnalyticsTests to Swift
This is a test-only change that shouldn't affect users.
2022-07-28 13:03:09 -05:00
Evan Hahn
4bf9ee4ace
Fix check for sticker pack URL
This commit:

- Adds unit tests
- Checks for auth and port in the URL
2022-07-26 10:38:34 -05:00
Sasha Weiss
543d29a13b
Include banned members in comparing and rendering group memberships 2022-07-18 16:00:39 -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
Evan Hahn
bf8fd72fba
Improve Accept-Language header value, fixing registration bug
Some users [are unable to register][1] because the server [returns a 400
error][2] if passed an invalid `Accept-Language` header.

This commit helps prevent two possible error modes:

- Filters out invalid language tags. Some users reported a "Workshopx"
  language, which the server would reject because it's syntactically
  invalid. Deleting this language (at the OS level) let them register.
- If no languages are valid, we should send `*` instead of the empty
  string. There's no evidence that this happened in practice.

In addition, this commit:

- Adds tests.
- Sends a maximum of 10 languages instead of 6.
- Omits the `q` value when it's 1 because [that's the default][3].
- Marginally improves performance by iterating lazily.

[1]: https://github.com/signalapp/Signal-iOS/issues/5261
[2]: bf6d3aa324/service/src/main/java/org/whispersystems/textsecuregcm/controllers/AccountController.java (L271-L275)
[3]: https://www.rfc-editor.org/rfc/rfc9110.html#section-12.4.2

Co-authored-by: Nora Trapp <nora@signal.org>
2022-07-11 12:20:24 -05:00
Max Radermacher
ed63a2aeac
Remove trailing comma
This fixes our violation of [SwiftLint's `trailing_comma` rule][0].

[0]: https://realm.github.io/SwiftLint/trailing_comma.html
2022-07-08 08:39:47 -05:00
Max Radermacher
11d08f101f
Fix crash when deleting messages from the future
The subtraction operation produces a negative value and causes a crash
in Swift. Allow deleting these messages to match Android’s behavior.
2022-06-27 09:02:04 -07:00
Max Radermacher
e303428216 Don’t allow “Delete for Everyone” for Gift Badges 2022-06-23 10:17:53 -07:00
Max Radermacher
da16b7c392 Convert TSMessageTest to Swift 2022-06-23 10:17:53 -07:00
Evan Hahn
f4714b1a83 Basic support for sending gift badges
If you've got the `giftBadgeSending` flag enabled, you can now send gift
badges to anyone who has the capability.

This commit doesn't complete the feature, though. It is missing:

- Proper durability and error handling (to be addressed separately)
- Saving of receipts
- A few other cleanups
2022-06-22 15:50:51 +00:00
Evan Hahn
a1eb9e3042 Clean up boostCreatePaymentIntent()
This makes a few small changes to `OWSRequestFactory.boostCreatePaymentIntent()`:

- Adds tests
- Rewrites the function in Swift

I made sure I could do a boost (in staging) in the simulator.
2022-06-21 17:33:28 +00:00
george-signal
010eb64e9d
Record early receipts for server-generated DRs 2022-06-20 13:25:24 -07:00
George Nachman
f643545d4f Fix a bug where delivery receipts were flaky. [IOS-2478]
anyUpdate runs its closure twice with different
messages but the batching context applied updates
always to the same copy of the message.

Also apply lint fixes.
2022-06-14 16:43:55 -07:00