From 52060ac9fd0d8220d85639b8175217b5d0d2f8cf Mon Sep 17 00:00:00 2001 From: Mikunj Date: Wed, 1 Apr 2020 14:16:31 +1100 Subject: [PATCH 01/27] Fix avatar and names on Note to self --- .../securesms/conversation/ConversationActivity.java | 4 +++- .../securesms/loki/redesign/views/ProfilePictureView.kt | 8 ++++++-- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 763496b9cd..d1b9136ddd 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -3152,7 +3152,9 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity subtitleTextView.setVisibility(View.GONE); } } else if (PublicKeyValidation.isValid(recipient.getAddress().toString())) { - subtitleTextView.setText(recipient.getAddress().toString()); + String ourMasterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(this); + String hexEncodedPublicKey = (recipient.isLocalNumber() && ourMasterHexEncodedPublicKey != null) ? ourMasterHexEncodedPublicKey : recipient.getAddress().toPhoneString(); + subtitleTextView.setText(hexEncodedPublicKey); } else { subtitleTextView.setVisibility(View.GONE); } diff --git a/src/org/thoughtcrime/securesms/loki/redesign/views/ProfilePictureView.kt b/src/org/thoughtcrime/securesms/loki/redesign/views/ProfilePictureView.kt index 55b89dd85f..8cc1788852 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/views/ProfilePictureView.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/views/ProfilePictureView.kt @@ -15,6 +15,7 @@ import org.thoughtcrime.securesms.database.Address import org.thoughtcrime.securesms.loki.JazzIdenticonDrawable import org.thoughtcrime.securesms.mms.GlideRequests import org.thoughtcrime.securesms.recipients.Recipient +import org.thoughtcrime.securesms.util.TextSecurePreferences // TODO: Look into a better way of handling different sizes. Maybe an enum (with associated values) encapsulating the different modes? @@ -60,12 +61,15 @@ class ProfilePictureView : RelativeLayout { fun setProfilePictureIfNeeded(imageView: ImageView, hexEncodedPublicKey: String, @DimenRes sizeID: Int) { glide.clear(imageView) if (hexEncodedPublicKey.isNotEmpty()) { - val signalProfilePicture = Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false).contactPhoto + val recipient = Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false); + val signalProfilePicture = recipient.contactPhoto if (signalProfilePicture != null && (signalProfilePicture as? ProfileContactPhoto)?.avatarObject != "0" && (signalProfilePicture as? ProfileContactPhoto)?.avatarObject != "") { glide.load(signalProfilePicture).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView) } else { val size = resources.getDimensionPixelSize(sizeID) - val jazzIcon = JazzIdenticonDrawable(size, size, hexEncodedPublicKey) + val primaryAddress = TextSecurePreferences.getMasterHexEncodedPublicKey(context) + val profileAddress = if (recipient.isLocalNumber && primaryAddress != null) primaryAddress else hexEncodedPublicKey + val jazzIcon = JazzIdenticonDrawable(size, size, profileAddress) glide.load(jazzIcon).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView) } } else { From 1f6ea3b55c4a4a516169dcc26f95b4f2fd5a9caa Mon Sep 17 00:00:00 2001 From: gmbnt Date: Mon, 6 Apr 2020 14:34:19 +1000 Subject: [PATCH 02/27] Maintain consistent code style --- .../securesms/loki/redesign/views/ProfilePictureView.kt | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/redesign/views/ProfilePictureView.kt b/src/org/thoughtcrime/securesms/loki/redesign/views/ProfilePictureView.kt index 8cc1788852..bc43369461 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/views/ProfilePictureView.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/views/ProfilePictureView.kt @@ -67,9 +67,9 @@ class ProfilePictureView : RelativeLayout { glide.load(signalProfilePicture).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView) } else { val size = resources.getDimensionPixelSize(sizeID) - val primaryAddress = TextSecurePreferences.getMasterHexEncodedPublicKey(context) - val profileAddress = if (recipient.isLocalNumber && primaryAddress != null) primaryAddress else hexEncodedPublicKey - val jazzIcon = JazzIdenticonDrawable(size, size, profileAddress) + val masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context) + val hepk = if (recipient.isLocalNumber && masterHexEncodedPublicKey != null) masterHexEncodedPublicKey else hexEncodedPublicKey + val jazzIcon = JazzIdenticonDrawable(size, size, hepk) glide.load(jazzIcon).diskCacheStrategy(DiskCacheStrategy.ALL).circleCrop().into(imageView) } } else { From 562deec218caadc25d6f71f510c751ca28e6474f Mon Sep 17 00:00:00 2001 From: gmbnt Date: Tue, 7 Apr 2020 10:49:32 +1000 Subject: [PATCH 03/27] Fix copy --- res/layout-sw400dp/fragment_enter_chat_url.xml | 2 +- res/layout/activity_create_closed_group.xml | 2 +- res/layout/fragment_enter_chat_url.xml | 2 +- res/layout/fragment_open_group_suggestion_bottom_sheet.xml | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/res/layout-sw400dp/fragment_enter_chat_url.xml b/res/layout-sw400dp/fragment_enter_chat_url.xml index e895f99639..0fcac50855 100644 --- a/res/layout-sw400dp/fragment_enter_chat_url.xml +++ b/res/layout-sw400dp/fragment_enter_chat_url.xml @@ -41,6 +41,6 @@ android:textColor="@color/text" android:alpha="0.6" android:textAlignment="center" - android:text="Open groups can be joined by anyone and do not provide full metadata protection" /> + android:text="Open groups can be joined by anyone and do not provide full privacy protection" /> \ No newline at end of file diff --git a/res/layout/activity_create_closed_group.xml b/res/layout/activity_create_closed_group.xml index 67d64f3697..55ccb98171 100644 --- a/res/layout/activity_create_closed_group.xml +++ b/res/layout/activity_create_closed_group.xml @@ -32,7 +32,7 @@ android:textColor="@color/text" android:alpha="0.6" android:textAlignment="center" - android:text="Closed groups are end-to-end encrypted group chats for up to 10 members. They provide the same privacy protections as one-on-one sessions." /> + android:text="Closed groups support up to 10 members and provide the same privacy protections as one-on-one sessions." /> + android:text="Open groups can be joined by anyone and do not provide full privacy protection" /> \ No newline at end of file diff --git a/res/layout/fragment_open_group_suggestion_bottom_sheet.xml b/res/layout/fragment_open_group_suggestion_bottom_sheet.xml index b26d9f86dc..d586f461c2 100644 --- a/res/layout/fragment_open_group_suggestion_bottom_sheet.xml +++ b/res/layout/fragment_open_group_suggestion_bottom_sheet.xml @@ -58,6 +58,6 @@ android:textColor="@color/text" android:alpha="0.6" android:textAlignment="center" - android:text="Open groups can be joined by anyone and do not provide full metadata protection" /> + android:text="Open groups can be joined by anyone and do not provide full privacy protection" /> From c98e7b3642cd1fe78aaff1962cfd382860f603d0 Mon Sep 17 00:00:00 2001 From: Niels Andriesse <9340958+nielsandriesse@users.noreply.github.com> Date: Wed, 8 Apr 2020 08:59:27 +1000 Subject: [PATCH 04/27] Update README.md --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2fac36fe4e..d1578d60de 100644 --- a/README.md +++ b/README.md @@ -6,13 +6,13 @@ ## Summary -Session integrates directly with [Loki Service Nodes](https://lokidocs.com/ServiceNodes/SNOverview/), which are a set of distributed, decentralized and Sybil resistant nodes. Service Nodes act as servers which store messages offline, and a set of nodes which allow for onion routing functionality obfuscating users IP addresses. For a full understanding of how Session works, read the [Session Whitepaper](https://getsession.org/whitepaper). +Session integrates directly with [Loki Service Nodes](https://lokidocs.com/ServiceNodes/SNOverview/), which are a set of distributed, decentralized and Sybil resistant nodes. Service Nodes act as servers which store messages offline, and a set of nodes which allow for onion routing functionality obfuscating users' IP addresses. For a full understanding of how Session works, read the [Session Whitepaper](https://getsession.org/whitepaper). ![AndroidSession](https://i.imgur.com/0YC9TyI.png) ## Want to Contribute? Found a Bug or Have a feature request? -Please search for any [existing issues](https://github.com/loki-project/session-android/issues) that describe your bugs in order to avoid duplicate submissions. Submissions can be made by making a pull request to our development branch. If you don't know where to start contributing , try reading the Github issues page for ideas. +Please search for any [existing issues](https://github.com/loki-project/session-android/issues) that describe your bugs in order to avoid duplicate submissions. Submissions can be made by making a pull request to our development branch. If you don't know where to start contributing, try reading the Github issues page for ideas. ## Build instruction From 4f8b3e4a1cf4ee7c4ea56d575f225968d8f1bf32 Mon Sep 17 00:00:00 2001 From: Niels Andriesse <9340958+nielsandriesse@users.noreply.github.com> Date: Wed, 8 Apr 2020 08:59:57 +1000 Subject: [PATCH 05/27] Update bug_report.md --- .github/ISSUE_TEMPLATE/bug_report.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md index 00542bd888..efa0e2bcbb 100644 --- a/.github/ISSUE_TEMPLATE/bug_report.md +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -8,18 +8,23 @@ assignees: '' --- **Describe the bug** + A clear and concise description of what the bug is. **To reproduce** + Steps to reproduce the behavior: **Screenshots or logs** + If applicable, add screenshots or logs to help explain your problem. **Smartphone (please complete the following information):** + - Device: [e.g. Samsung Galaxy S8] - OS: [e.g. Android Pie] - - Version of Loki Messenger or latest commit hash + - Version of Session or latest commit hash **Additional context** + Add any other context about the problem here. From 342e22d692dbe396c92d8f37a54f7534826feb4c Mon Sep 17 00:00:00 2001 From: Niels Andriesse <9340958+nielsandriesse@users.noreply.github.com> Date: Wed, 8 Apr 2020 09:02:53 +1000 Subject: [PATCH 06/27] Update ISSUE_TEMPLATE.md --- .github/ISSUE_TEMPLATE.md | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/.github/ISSUE_TEMPLATE.md b/.github/ISSUE_TEMPLATE.md index 5a116b751a..c08052c43b 100644 --- a/.github/ISSUE_TEMPLATE.md +++ b/.github/ISSUE_TEMPLATE.md @@ -14,7 +14,6 @@ Let's begin with a checklist: Replace the empty checkboxes [ ] below with checke - [ ] I have searched open and closed issues for duplicates - [ ] I am submitting a bug report for existing functionality that does not work as intended -- [ ] I have read https://github.com/signalapp/Signal-Android/wiki/Submitting-useful-bug-reports - [ ] This isn't a feature request or a discussion topic ---------------------------------------- @@ -27,8 +26,13 @@ Describe here the issue that you are experiencing. - list the steps - that reproduce the bug -**Actual result:** Describe here what happens after you run the steps above (i.e. the buggy behaviour) -**Expected result:** Describe here what should happen after you run the steps above (i.e. what would be the correct behaviour) +**Actual result:** + +Describe here what happens after you run the steps above (i.e. the buggy behaviour) + +**Expected result:** + +Describe here what should happen after you run the steps above (i.e. what would be the correct behaviour) ### Screenshots @@ -36,10 +40,14 @@ Describe here the issue that you are experiencing. ### Device info + **Device:** Manufacturer Model XVI + **Android version:** 0.0.0 -**Signal version:** 0.0.0 + +**Session version:** 0.0.0 ### Link to debug log + From 547a8bd0003eafb5abad09d3fcab680901feafc9 Mon Sep 17 00:00:00 2001 From: Niels Andriesse <9340958+nielsandriesse@users.noreply.github.com> Date: Wed, 8 Apr 2020 09:05:36 +1000 Subject: [PATCH 07/27] Update BUILDING.md --- BUILDING.md | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/BUILDING.md b/BUILDING.md index 4f97d9a014..a9c3f96dc7 100644 --- a/BUILDING.md +++ b/BUILDING.md @@ -1,21 +1,21 @@ -Building Signal +Building Session =============== Basics ------ -Signal uses [Gradle](http://gradle.org) to build the project and to maintain +Session uses [Gradle](http://gradle.org) to build the project and to maintain dependencies. However, you needn't install it yourself; the "gradle wrapper" `gradlew`, mentioned below, will do that for you. -Building Signal +Building Session --------------- -The following steps should help you (re)build Signal from the command line. +The following steps should help you (re)build Session from the command line. -1. Checkout the Signal-Android project source with the command: +1. Checkout the session-android project source with the command: - git clone https://github.com/signalapp/Signal-Android.git + git clone https://github.com/loki-project/session-android.git 2. Make sure you have the [Android SDK](https://developer.android.com/sdk/index.html) installed. 3. Ensure that the following packages are installed from the Android SDK manager: @@ -41,8 +41,8 @@ Source assets tend to be large binary blobs, which are best stored outside of gi Sample command for generating our audio placeholder image: ```bash -pngs_from_svg.py ic_audio.svg /path/to/Signal/res/ 150 --color #000 --opacity 0.54 --suffix _light -pngs_from_svg.py ic_audio.svg /path/to/Signal/res/ 150 --color #fff --opacity 1.00 --suffix _light +pngs_from_svg.py ic_audio.svg /path/to/Session/res/ 150 --color #000 --opacity 0.54 --suffix _light +pngs_from_svg.py ic_audio.svg /path/to/Session/res/ 150 --color #fff --opacity 1.00 --suffix _light ``` Setting up a development environment @@ -55,7 +55,7 @@ Setting up a development environment 3. From the Quickstart panel, choose "Configure" then "SDK Manager". 4. In the SDK Tools tab of the SDK Manager, make sure that the "Android Support Repository" is installed, and that the latest "Android SDK build-tools" are installed. Click "OK" to return to the Quickstart panel. 5. From the Quickstart panel, choose "Checkout from Version Control" then "git". -6. Paste the URL for the Signal-Android project when prompted (https://github.com/signalapp/Signal-Android.git). +6. Paste the URL for the session-android project when prompted (https://github.com/loki-project/session-android.git). 7. Android studio should detect the presence of a project file and ask you whether to open it. Click "yes". 9. Default config options should be good enough. 9. Project initialisation and build should proceed. @@ -64,11 +64,3 @@ Contributing code ----------------- Code contributions should be sent via github as pull requests, from feature branches [as explained here](https://help.github.com/articles/using-pull-requests). - -Mailing list ------------- - -Development discussion happens on the whispersystems mailing list. -[To join](https://lists.riseup.net/www/info/whispersystems) -Send emails to whispersystems@lists.riseup.net - From 65e6e0437c32155046950aff8f05cefbec719486 Mon Sep 17 00:00:00 2001 From: gmbnt Date: Wed, 8 Apr 2020 10:44:55 +1000 Subject: [PATCH 08/27] Update seed node pool --- res/xml/network_security_configuration.xml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/res/xml/network_security_configuration.xml b/res/xml/network_security_configuration.xml index c62b3d962e..b38993a466 100644 --- a/res/xml/network_security_configuration.xml +++ b/res/xml/network_security_configuration.xml @@ -1,11 +1,10 @@ - imaginary.stream - chat.getsession.org + 149.56.148.124 storage.seed1.loki.network storage.seed2.loki.network - public.loki.foundation:22023 + public.loki.foundation file-dev.lokinet.org 127.0.0.1 From 407f6aa3a55b39260419d119a76528a892d608fa Mon Sep 17 00:00:00 2001 From: Audric Ackermann Date: Thu, 9 Apr 2020 09:32:35 +1000 Subject: [PATCH 09/27] trigger register on press enter --- .../redesign/activities/DisplayNameActivity.kt | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/DisplayNameActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/DisplayNameActivity.kt index b6eaf24444..2c9b06e47e 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/DisplayNameActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/DisplayNameActivity.kt @@ -2,7 +2,10 @@ package org.thoughtcrime.securesms.loki.redesign.activities import android.content.Intent import android.os.Bundle +import android.view.KeyEvent +import android.view.inputmethod.EditorInfo import android.view.inputmethod.InputMethodManager +import android.widget.TextView.OnEditorActionListener import android.widget.Toast import kotlinx.android.synthetic.main.activity_display_name.* import network.loki.messenger.R @@ -21,6 +24,19 @@ class DisplayNameActivity : BaseActionBarActivity() { setUpActionBarSessionLogo() setContentView(R.layout.activity_display_name) displayNameEditText.imeOptions = displayNameEditText.imeOptions or 16777216 // Always use incognito keyboard + displayNameEditText.setOnEditorActionListener( + OnEditorActionListener { _, actionId, event -> + // Handle validation from keyboard to trigger registration + if (actionId == EditorInfo.IME_ACTION_SEARCH || + actionId == EditorInfo.IME_ACTION_DONE || + (event.action === KeyEvent.ACTION_DOWN + && event.keyCode === KeyEvent.KEYCODE_ENTER)) { + this.register(); + return@OnEditorActionListener true + } + // Return true if you have consumed the action, else false. + false + }) registerButton.setOnClickListener { register() } } From 3ec5974210e6441105e10eb892b32acbfe3c3700 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 9 Apr 2020 09:41:01 +1000 Subject: [PATCH 10/27] Correctly display when user was kicked or added --- .../groups/GroupMessageProcessor.java | 46 +++++++++---------- 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index c9145e77e1..a0dff036ac 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -146,40 +146,40 @@ public class GroupMessageProcessor { } } - Set
recordMembers = new HashSet<>(groupRecord.getMembers()); - Set
messageMembers = new HashSet<>(); + Set
currentMembers = new HashSet<>(groupRecord.getMembers()); + Set
newMembers = new HashSet<>(); for (String messageMember : group.getMembers().get()) { - messageMembers.add(Address.fromExternal(context, messageMember)); + newMembers.add(Address.fromExternal(context, messageMember)); } - Set
addedMembers = new HashSet<>(messageMembers); - addedMembers.removeAll(recordMembers); + // Added members are the members who are present in newMembers but not in currentMembers + Set
addedMembers = new HashSet<>(newMembers); + addedMembers.removeAll(currentMembers); - Set
missingMembers = new HashSet<>(recordMembers); - missingMembers.removeAll(messageMembers); + // Kicked members are members who are present in currentMembers but not in newMembers + Set
removedMembers = new HashSet<>(currentMembers); + removedMembers.removeAll(newMembers); GroupContext.Builder builder = createGroupContext(group); builder.setType(GroupContext.Type.UPDATE); - if (addedMembers.size() > 0) { - Set
unionMembers = new HashSet<>(recordMembers); - unionMembers.addAll(messageMembers); - database.updateMembers(id, new LinkedList<>(unionMembers)); - - builder.clearMembers(); - - for (Address addedMember : addedMembers) { - builder.addMembers(addedMember.serialize()); - } - } else { - builder.clearMembers(); + // Update our group members if they're different + if (!currentMembers.equals(newMembers)) { + database.updateMembers(id, new LinkedList<>(newMembers)); } - if (missingMembers.size() > 0) { - for (Address removedMember : missingMembers) { - builder.addMembers(removedMember.serialize()); - } + builder.clearMembers(); + + // We add any new or removed members to the group context + // This will allow us later to iterate over them to check if they left or were added for UI display + + for (Address addedMember : addedMembers) { + builder.addMembers(addedMember.serialize()); + } + + for (Address removedMember : removedMembers) { + builder.addMembers(removedMember.serialize()); } if (group.getName().isPresent() || group.getAvatar().isPresent()) { From 4a36ed333db138a8ae2e067451d9443efd9f55ce Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 9 Apr 2020 10:47:18 +1000 Subject: [PATCH 11/27] Disable chat if we were removed from the group. --- .../securesms/groups/GroupMessageProcessor.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index a0dff036ac..4e53e6273b 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -173,7 +173,6 @@ public class GroupMessageProcessor { // We add any new or removed members to the group context // This will allow us later to iterate over them to check if they left or were added for UI display - for (Address addedMember : addedMembers) { builder.addMembers(addedMember.serialize()); } @@ -182,6 +181,13 @@ public class GroupMessageProcessor { builder.addMembers(removedMember.serialize()); } + // If we were removed then we need to disable the chat + String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context); + String ourHexEncodedPublicKey = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context); + if (removedMembers.contains(Address.fromSerialized(ourHexEncodedPublicKey))) { + database.setActive(id, false); + } + if (group.getName().isPresent() || group.getAvatar().isPresent()) { SignalServiceAttachment avatar = group.getAvatar().orNull(); database.update(id, group.getName().orNull(), avatar != null ? avatar.asPointer() : null); From f149065a30c8221d05e9df8a44d27ce54a6006b5 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 9 Apr 2020 13:17:00 +1000 Subject: [PATCH 12/27] Fix GroupDescriptions updating dynamically. This shouldn't happen, rather it should have the snapshot of the group state per message. --- .../groups/GroupMessageProcessor.java | 38 ++++++----- .../securesms/util/GroupUtil.java | 63 +++++++------------ 2 files changed, 45 insertions(+), 56 deletions(-) diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index 4e53e6273b..719a7dd7d8 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -137,13 +137,25 @@ public class GroupMessageProcessor { GroupDatabase database = DatabaseFactory.getGroupDatabase(context); String id = GroupUtil.getEncodedId(group); - // Only update group if admin sent the message + String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context); + String ourHexEncodedPublicKey = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context); + if (group.getGroupType() == SignalServiceGroup.GroupType.SIGNAL) { + // Only update group if admin sent the message String hexEncodedPublicKey = getMasterHexEncodedPublicKey(context, content.getSender()); if (!groupRecord.getAdmins().contains(Address.fromSerialized(hexEncodedPublicKey))) { Log.d("Loki - Group Message", "Received a group update message from a non-admin user for " + id +". Ignoring."); return null; } + + // We should only process update message if we were in the group + Address ourAddress = Address.fromSerialized(ourHexEncodedPublicKey); + if (!groupRecord.getMembers().contains(ourAddress) && + !group.getMembers().or(Collections.emptyList()).contains(ourHexEncodedPublicKey)) { + Log.d("Loki - Group Message", "Received a group update message from a group we are not members in: " + id + " . Ignoring."); + database.setActive(id, false); + return null; + } } Set
currentMembers = new HashSet<>(groupRecord.getMembers()); @@ -169,23 +181,14 @@ public class GroupMessageProcessor { database.updateMembers(id, new LinkedList<>(newMembers)); } - builder.clearMembers(); - // We add any new or removed members to the group context // This will allow us later to iterate over them to check if they left or were added for UI display for (Address addedMember : addedMembers) { - builder.addMembers(addedMember.serialize()); + builder.addNewMembers(addedMember.serialize()); } for (Address removedMember : removedMembers) { - builder.addMembers(removedMember.serialize()); - } - - // If we were removed then we need to disable the chat - String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context); - String ourHexEncodedPublicKey = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context); - if (removedMembers.contains(Address.fromSerialized(ourHexEncodedPublicKey))) { - database.setActive(id, false); + builder.addRemovedMembers(removedMember.serialize()); } if (group.getName().isPresent() || group.getAvatar().isPresent()) { @@ -197,10 +200,15 @@ public class GroupMessageProcessor { builder.clearName(); } - if (!groupRecord.isActive()) database.setActive(id, true); + // If we were removed then we need to disable the chat + if (removedMembers.contains(Address.fromSerialized(ourHexEncodedPublicKey))) { + database.setActive(id, false); + } else { + if (!groupRecord.isActive()) database.setActive(id, true); - if (group.getMembers().isPresent()) { - establishSessionsWithMembersIfNeeded(context, group.getMembers().get()); + if (group.getMembers().isPresent()) { + establishSessionsWithMembersIfNeeded(context, group.getMembers().get()); + } } return storeMessage(context, content, group, builder.build(), outgoing); diff --git a/src/org/thoughtcrime/securesms/util/GroupUtil.java b/src/org/thoughtcrime/securesms/util/GroupUtil.java index 907a21217e..0029d5f6a4 100644 --- a/src/org/thoughtcrime/securesms/util/GroupUtil.java +++ b/src/org/thoughtcrime/securesms/util/GroupUtil.java @@ -10,7 +10,6 @@ import com.google.protobuf.ByteString; import org.thoughtcrime.securesms.database.Address; import org.thoughtcrime.securesms.database.DatabaseFactory; import org.thoughtcrime.securesms.database.GroupDatabase; -import org.thoughtcrime.securesms.database.GroupDatabase.GroupRecord; import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage; import org.thoughtcrime.securesms.recipients.Recipient; @@ -159,7 +158,7 @@ public class GroupUtil { @NonNull private final Context context; @Nullable private final GroupContext groupContext; - private final List members; + private final List newMembers; private final List removedMembers; private boolean ourDeviceWasRemoved; @@ -167,35 +166,35 @@ public class GroupUtil { this.context = context.getApplicationContext(); this.groupContext = groupContext; - this.members = new LinkedList<>(); + this.newMembers = new LinkedList<>(); this.removedMembers = new LinkedList<>(); this.ourDeviceWasRemoved = false; - if (groupContext != null && !groupContext.getMembersList().isEmpty()) { - List memberList = groupContext.getMembersList(); - List
currentMembers = getCurrentGroupMembers(); + if (groupContext != null) { + List newMembers = groupContext.getNewMembersList(); + for (String member : newMembers) { + this.newMembers.add(this.toRecipient(member)); + } - // Add them to the member or removed members lists - for (String member : memberList) { - Address address = Address.fromSerialized(member); - Recipient recipient = Recipient.from(context, address, true); - if (currentMembers == null || currentMembers.contains(address)) { - this.members.add(recipient); - } else { - this.removedMembers.add(recipient); - } + List removedMembers = groupContext.getRemovedMembersList(); + for (String member : removedMembers) { + this.removedMembers.add(this.toRecipient(member)); } // Check if our device was removed if (!removedMembers.isEmpty()) { String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context); String hexEncodedPublicKey = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context); - Recipient self = Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false); - ourDeviceWasRemoved = removedMembers.contains(self); + ourDeviceWasRemoved = removedMembers.contains(hexEncodedPublicKey); } } } + private Recipient toRecipient(String hexEncodedPublicKey) { + Address address = Address.fromSerialized(hexEncodedPublicKey); + return Recipient.from(context, address, false); + } + public String toString(Recipient sender) { // Show the local removed message if (ourDeviceWasRemoved) { @@ -211,10 +210,10 @@ public class GroupUtil { String title = groupContext.getName(); - if (!members.isEmpty()) { + if (!newMembers.isEmpty()) { description.append("\n"); description.append(context.getResources().getQuantityString(R.plurals.GroupUtil_joined_the_group, - members.size(), toString(members))); + newMembers.size(), toString(newMembers))); } if (!removedMembers.isEmpty()) { @@ -224,8 +223,8 @@ public class GroupUtil { } if (title != null && !title.trim().isEmpty()) { - if (!members.isEmpty()) description.append(" "); - else description.append("\n"); + String separator = (!newMembers.isEmpty() || !removedMembers.isEmpty()) ? " " : "\n"; + description.append(separator); description.append(context.getString(R.string.GroupUtil_group_name_is_now, title)); } @@ -233,8 +232,8 @@ public class GroupUtil { } public void addListener(RecipientModifiedListener listener) { - if (!this.members.isEmpty()) { - for (Recipient member : this.members) { + if (!this.newMembers.isEmpty()) { + for (Recipient member : this.newMembers) { member.addListener(listener); } } @@ -252,23 +251,5 @@ public class GroupUtil { return result; } - - private List
getCurrentGroupMembers() { - if (groupContext == null) { return null; } - GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context); - byte[] decodedGroupId = groupContext.getId().toByteArray(); - String signalGroupId = getEncodedId(decodedGroupId, false); - String publicChatId = getEncodedPublicChatId(decodedGroupId); - String rssFeedId = getEncodedRSSFeedId(decodedGroupId); - GroupRecord groupRecord = null; - if (!groupDatabase.isUnknownGroup(signalGroupId)) { - groupRecord = groupDatabase.getGroup(signalGroupId).orNull(); - } else if (!groupDatabase.isUnknownGroup(publicChatId)) { - groupRecord = groupDatabase.getGroup(publicChatId).orNull(); - } else if (!groupDatabase.isUnknownGroup(rssFeedId)) { - groupRecord = groupDatabase.getGroup(rssFeedId).orNull(); - } - return (groupRecord != null) ? groupRecord.getMembers() : null; - } } } From a6bfd142850f2afc4063719cafee5e8806c201fa Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 9 Apr 2020 13:38:15 +1000 Subject: [PATCH 13/27] Update for core changes --- .../thoughtcrime/securesms/ApplicationContext.java | 14 +++++++++----- .../securesms/CreateProfileActivity.java | 4 ++-- .../securesms/components/QuoteView.java | 2 +- .../securesms/components/TypingStatusSender.java | 4 ++-- .../conversation/ConversationActivity.java | 6 +++--- .../conversation/ConversationFragment.java | 4 ++-- .../securesms/conversation/ConversationItem.java | 4 ++-- .../database/helpers/SQLCipherOpenHelper.java | 2 +- .../database/loaders/DeviceListLoader.java | 2 +- .../securesms/groups/GroupMessageProcessor.java | 2 +- .../securesms/jobs/AttachmentUploadJob.java | 2 +- .../securesms/jobs/PushDecryptJob.java | 10 +++++----- .../securesms/jobs/PushGroupSendJob.java | 4 ++-- .../securesms/jobs/PushMediaSendJob.java | 2 +- .../securesms/jobs/PushTextSendJob.java | 2 +- .../securesms/loki/LokiPublicChatManager.kt | 2 +- .../securesms/loki/LokiThreadDatabase.kt | 2 +- .../loki/MultiDeviceOpenGroupUpdateJob.kt | 2 +- .../securesms/loki/MultiDeviceUtilities.kt | 6 +++--- .../loki/redesign/activities/LandingActivity.kt | 2 +- .../redesign/activities/LinkedDevicesActivity.kt | 4 ++-- .../redesign/activities/LinkedDevicesLoader.kt | 2 +- .../loki/redesign/activities/SettingsActivity.kt | 2 +- .../redesign/dialogs/LinkDeviceMasterModeDialog.kt | 6 +++--- .../redesign/dialogs/LinkDeviceSlaveModeDialog.kt | 6 +++--- .../redesign/messaging/BackgroundPollWorker.kt | 3 ++- .../loki/redesign/messaging/LokiAPIDatabase.kt | 4 ++-- .../redesign/messaging/LokiPublicChatPoller.kt | 6 +++++- .../loki/redesign/messaging/LokiRSSFeedPoller.kt | 4 ++-- .../loki/redesign/utilities/OpenGroupUtilities.kt | 2 +- .../loki/redesign/views/MentionCandidateView.kt | 2 +- .../securesms/mms/PushMediaConstraints.java | 2 +- .../securesms/notifications/MarkReadReceiver.java | 2 +- .../thoughtcrime/securesms/sms/MessageSender.java | 2 +- 34 files changed, 67 insertions(+), 58 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 0687981f55..573394d264 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -92,14 +92,16 @@ import org.whispersystems.libsignal.logging.SignalProtocolLoggerProvider; import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope; import org.whispersystems.signalservice.api.util.StreamDetails; import org.whispersystems.signalservice.internal.push.SignalServiceProtos; +import org.whispersystems.signalservice.loki.api.LokiAPI; import org.whispersystems.signalservice.loki.api.LokiAPIDatabaseProtocol; -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI; import org.whispersystems.signalservice.loki.api.LokiP2PAPI; import org.whispersystems.signalservice.loki.api.LokiP2PAPIDelegate; import org.whispersystems.signalservice.loki.api.LokiPoller; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; -import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; -import org.whispersystems.signalservice.loki.api.LokiRSSFeed; +import org.whispersystems.signalservice.loki.api.LokiSwarmAPI; +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChatAPI; +import org.whispersystems.signalservice.loki.api.rssfeeds.LokiRSSFeed; import java.io.File; import java.io.FileInputStream; @@ -464,7 +466,9 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc if (userHexEncodedPublicKey == null) return; LokiAPIDatabase lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(this); Context context = this; - lokiPoller = new LokiPoller(userHexEncodedPublicKey, lokiAPIDatabase, broadcaster, protos -> { + LokiSwarmAPI.Companion.configureIfNeeded(lokiAPIDatabase); + LokiAPI.Companion.configureIfNeeded(userHexEncodedPublicKey, lokiAPIDatabase, broadcaster); + lokiPoller = new LokiPoller(userHexEncodedPublicKey, lokiAPIDatabase, protos -> { for (SignalServiceProtos.Envelope proto : protos) { new PushContentReceiveJob(context).processEnvelope(new SignalServiceEnvelope(proto)); } diff --git a/src/org/thoughtcrime/securesms/CreateProfileActivity.java b/src/org/thoughtcrime/securesms/CreateProfileActivity.java index f819a8ffbd..d0db3ae370 100644 --- a/src/org/thoughtcrime/securesms/CreateProfileActivity.java +++ b/src/org/thoughtcrime/securesms/CreateProfileActivity.java @@ -58,8 +58,8 @@ import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.crypto.ProfileCipher; import org.whispersystems.signalservice.api.util.StreamDetails; import org.whispersystems.signalservice.loki.api.LokiDotNetAPI; -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI; -import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChatAPI; import java.io.ByteArrayInputStream; import java.io.File; diff --git a/src/org/thoughtcrime/securesms/components/QuoteView.java b/src/org/thoughtcrime/securesms/components/QuoteView.java index b4943f9993..690ce585cb 100644 --- a/src/org/thoughtcrime/securesms/components/QuoteView.java +++ b/src/org/thoughtcrime/securesms/components/QuoteView.java @@ -31,7 +31,7 @@ import org.thoughtcrime.securesms.recipients.RecipientModifiedListener; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.thoughtcrime.securesms.util.ThemeUtil; import org.thoughtcrime.securesms.util.Util; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat; import java.util.List; diff --git a/src/org/thoughtcrime/securesms/components/TypingStatusSender.java b/src/org/thoughtcrime/securesms/components/TypingStatusSender.java index 1c851247ea..b573020b22 100644 --- a/src/org/thoughtcrime/securesms/components/TypingStatusSender.java +++ b/src/org/thoughtcrime/securesms/components/TypingStatusSender.java @@ -11,8 +11,8 @@ import org.thoughtcrime.securesms.database.ThreadDatabase; import org.thoughtcrime.securesms.jobs.TypingSendJob; import org.thoughtcrime.securesms.recipients.Recipient; import org.thoughtcrime.securesms.util.Util; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI; import java.util.HashMap; import java.util.Map; diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index d1b9136ddd..1377386fe5 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -228,10 +228,10 @@ import org.thoughtcrime.securesms.util.concurrent.SettableFuture; import org.thoughtcrime.securesms.util.views.Stub; import org.whispersystems.libsignal.InvalidMessageException; import org.whispersystems.libsignal.util.guava.Optional; -import org.whispersystems.signalservice.loki.api.DeviceLink; +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLink; import org.whispersystems.signalservice.loki.api.LokiAPI; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat; import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus; import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus; import org.whispersystems.signalservice.loki.messaging.Mention; diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java b/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java index cb3b53f007..5978be024e 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationFragment.java @@ -101,8 +101,8 @@ import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.concurrent.SimpleTask; import org.thoughtcrime.securesms.util.task.ProgressDialogAsyncTask; import org.whispersystems.libsignal.util.guava.Optional; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; -import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChatAPI; import java.io.IOException; import java.io.InputStream; diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java index 2fdb040c7b..c4bc562d79 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationItem.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationItem.java @@ -112,8 +112,8 @@ import org.thoughtcrime.securesms.util.Util; import org.thoughtcrime.securesms.util.ViewUtil; import org.thoughtcrime.securesms.util.views.Stub; import org.whispersystems.libsignal.util.guava.Optional; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; -import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChatAPI; import java.util.Collections; import java.util.HashSet; diff --git a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java index 38ff02ee8a..a593c57943 100644 --- a/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java +++ b/src/org/thoughtcrime/securesms/database/helpers/SQLCipherOpenHelper.java @@ -45,7 +45,7 @@ import org.thoughtcrime.securesms.notifications.NotificationChannels; import org.thoughtcrime.securesms.service.KeyCachingService; import org.thoughtcrime.securesms.util.GroupUtil; import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat; import java.io.File; diff --git a/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java b/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java index 7a7a67d535..87df483995 100644 --- a/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java +++ b/src/org/thoughtcrime/securesms/database/loaders/DeviceListLoader.java @@ -11,7 +11,7 @@ import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.redesign.utilities.MnemonicUtilities; import org.thoughtcrime.securesms.util.AsyncLoader; import org.thoughtcrime.securesms.util.TextSecurePreferences; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; import org.whispersystems.signalservice.loki.crypto.MnemonicCodec; import java.io.File; diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index c9145e77e1..916491ac71 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -36,7 +36,7 @@ import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage; import org.whispersystems.signalservice.api.messages.SignalServiceGroup; import org.whispersystems.signalservice.api.messages.SignalServiceGroup.Type; import org.whispersystems.signalservice.api.push.SignalServiceAddress; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; import org.whispersystems.signalservice.loki.utilities.PromiseUtil; import java.util.Collections; diff --git a/src/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java b/src/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java index 3bb54e43d9..16d1b09b85 100644 --- a/src/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java +++ b/src/org/thoughtcrime/securesms/jobs/AttachmentUploadJob.java @@ -27,7 +27,7 @@ import org.whispersystems.signalservice.api.SignalServiceMessageSender; import org.whispersystems.signalservice.api.messages.SignalServiceAttachment; import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer; import org.whispersystems.signalservice.api.push.SignalServiceAddress; -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI; +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI; import java.io.IOException; import java.io.InputStream; diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 29d3a12172..0ecea52e29 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -137,12 +137,12 @@ import org.whispersystems.signalservice.api.messages.multidevice.StickerPackOper import org.whispersystems.signalservice.api.messages.multidevice.VerifiedMessage; import org.whispersystems.signalservice.api.messages.shared.SharedContact; import org.whispersystems.signalservice.api.push.SignalServiceAddress; -import org.whispersystems.signalservice.loki.api.DeviceLink; -import org.whispersystems.signalservice.loki.api.DeviceLinkingSession; +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLink; +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLinkingSession; import org.whispersystems.signalservice.loki.api.LokiAPI; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat; import org.whispersystems.signalservice.loki.crypto.LokiServiceCipher; import org.whispersystems.signalservice.loki.messaging.LokiMessageFriendRequestStatus; import org.whispersystems.signalservice.loki.messaging.LokiServiceMessage; diff --git a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java index ef9fa207ac..7d497dea60 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushGroupSendJob.java @@ -50,8 +50,8 @@ import org.whispersystems.signalservice.api.messages.SignalServiceGroup; import org.whispersystems.signalservice.api.messages.shared.SharedContact; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; -import org.whispersystems.signalservice.loki.api.LokiPublicChat; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat; import org.whispersystems.signalservice.loki.utilities.PromiseUtil; import java.io.IOException; diff --git a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java index 1447b5bafd..0ce7521000 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushMediaSendJob.java @@ -45,7 +45,7 @@ import org.whispersystems.signalservice.api.messages.shared.SharedContact; import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException; import org.whispersystems.signalservice.loki.api.LokiAPI; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; import org.whispersystems.signalservice.loki.messaging.LokiSyncMessage; import org.whispersystems.signalservice.loki.utilities.PromiseUtil; diff --git a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java index 5ce7dd3442..2b9e034c4f 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushTextSendJob.java @@ -33,7 +33,7 @@ import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSy import org.whispersystems.signalservice.api.push.SignalServiceAddress; import org.whispersystems.signalservice.api.push.exceptions.UnregisteredUserException; import org.whispersystems.signalservice.loki.api.LokiAPI; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; import org.whispersystems.signalservice.loki.messaging.LokiSyncMessage; import org.whispersystems.signalservice.loki.utilities.PromiseUtil; diff --git a/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt b/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt index 0a959521f5..e49ff67090 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiPublicChatManager.kt @@ -13,7 +13,7 @@ import org.thoughtcrime.securesms.groups.GroupManager import org.thoughtcrime.securesms.loki.redesign.messaging.LokiPublicChatPoller import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.Util -import org.whispersystems.signalservice.loki.api.LokiPublicChat +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat class LokiPublicChatManager(private val context: Context) { private var chats = mutableMapOf() diff --git a/src/org/thoughtcrime/securesms/loki/LokiThreadDatabase.kt b/src/org/thoughtcrime/securesms/loki/LokiThreadDatabase.kt index 0decbdd0c5..adb3a6e165 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiThreadDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiThreadDatabase.kt @@ -12,7 +12,7 @@ import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.libsignal.loki.LokiSessionResetStatus import org.whispersystems.signalservice.internal.util.JsonUtil -import org.whispersystems.signalservice.loki.api.LokiPublicChat +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat import org.whispersystems.signalservice.loki.messaging.LokiThreadDatabaseProtocol import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus import org.whispersystems.signalservice.loki.utilities.PublicKeyValidation diff --git a/src/org/thoughtcrime/securesms/loki/MultiDeviceOpenGroupUpdateJob.kt b/src/org/thoughtcrime/securesms/loki/MultiDeviceOpenGroupUpdateJob.kt index 683eea84b6..7ae1a94f1e 100644 --- a/src/org/thoughtcrime/securesms/loki/MultiDeviceOpenGroupUpdateJob.kt +++ b/src/org/thoughtcrime/securesms/loki/MultiDeviceOpenGroupUpdateJob.kt @@ -12,7 +12,7 @@ import org.thoughtcrime.securesms.logging.Log import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.signalservice.api.SignalServiceMessageSender import org.whispersystems.signalservice.api.messages.multidevice.SignalServiceSyncMessage -import org.whispersystems.signalservice.loki.api.LokiPublicChat +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat import java.util.concurrent.TimeUnit import javax.inject.Inject diff --git a/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt b/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt index 8cbf546901..9411932aee 100644 --- a/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/MultiDeviceUtilities.kt @@ -18,9 +18,9 @@ import org.thoughtcrime.securesms.recipients.Recipient import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage import org.whispersystems.signalservice.api.push.SignalServiceAddress -import org.whispersystems.signalservice.loki.api.DeviceLink -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLink +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus import org.whispersystems.signalservice.loki.utilities.recover import org.whispersystems.signalservice.loki.utilities.retryIfNeeded diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/LandingActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/LandingActivity.kt index 8744131638..e15be3140f 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/LandingActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/LandingActivity.kt @@ -26,7 +26,7 @@ import org.whispersystems.curve25519.Curve25519 import org.whispersystems.libsignal.ecc.Curve import org.whispersystems.libsignal.ecc.ECKeyPair import org.whispersystems.libsignal.util.KeyHelper -import org.whispersystems.signalservice.loki.api.DeviceLink +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLink import org.whispersystems.signalservice.loki.utilities.hexEncodedPublicKey import org.whispersystems.signalservice.loki.utilities.retryIfNeeded diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesActivity.kt index 0e09697740..16ffae7b35 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesActivity.kt @@ -23,9 +23,9 @@ import org.thoughtcrime.securesms.loki.redesign.dialogs.* import org.thoughtcrime.securesms.loki.signAndSendDeviceLinkMessage import org.thoughtcrime.securesms.sms.MessageSender import org.thoughtcrime.securesms.util.TextSecurePreferences -import org.whispersystems.signalservice.loki.api.DeviceLink +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLink import org.whispersystems.signalservice.loki.api.LokiAPI -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI import java.util.* import kotlin.concurrent.schedule diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesLoader.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesLoader.kt index 87dcdb528e..d3db8f6728 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesLoader.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/LinkedDevicesLoader.kt @@ -6,7 +6,7 @@ import org.thoughtcrime.securesms.devicelist.Device import org.thoughtcrime.securesms.loki.redesign.utilities.MnemonicUtilities import org.thoughtcrime.securesms.util.AsyncLoader import org.thoughtcrime.securesms.util.TextSecurePreferences -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities import org.whispersystems.signalservice.loki.crypto.MnemonicCodec import java.io.File diff --git a/src/org/thoughtcrime/securesms/loki/redesign/activities/SettingsActivity.kt b/src/org/thoughtcrime/securesms/loki/redesign/activities/SettingsActivity.kt index c82e4e9e3d..bcf24e26ba 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/activities/SettingsActivity.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/activities/SettingsActivity.kt @@ -42,7 +42,7 @@ import org.thoughtcrime.securesms.util.BitmapUtil import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.signalservice.api.crypto.ProfileCipher import org.whispersystems.signalservice.api.util.StreamDetails -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI import java.io.ByteArrayInputStream import java.io.File import java.security.SecureRandom diff --git a/src/org/thoughtcrime/securesms/loki/redesign/dialogs/LinkDeviceMasterModeDialog.kt b/src/org/thoughtcrime/securesms/loki/redesign/dialogs/LinkDeviceMasterModeDialog.kt index 44fc08bddf..35bab0ac35 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/dialogs/LinkDeviceMasterModeDialog.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/dialogs/LinkDeviceMasterModeDialog.kt @@ -17,9 +17,9 @@ import org.thoughtcrime.securesms.loki.redesign.utilities.QRCodeUtilities import org.thoughtcrime.securesms.loki.toPx import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.Util -import org.whispersystems.signalservice.loki.api.DeviceLink -import org.whispersystems.signalservice.loki.api.DeviceLinkingSession -import org.whispersystems.signalservice.loki.api.DeviceLinkingSessionListener +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLink +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLinkingSession +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLinkingSessionListener import org.whispersystems.signalservice.loki.crypto.MnemonicCodec class LinkDeviceMasterModeDialog : DialogFragment(), DeviceLinkingSessionListener { diff --git a/src/org/thoughtcrime/securesms/loki/redesign/dialogs/LinkDeviceSlaveModeDialog.kt b/src/org/thoughtcrime/securesms/loki/redesign/dialogs/LinkDeviceSlaveModeDialog.kt index 8a7d0acf85..d618008005 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/dialogs/LinkDeviceSlaveModeDialog.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/dialogs/LinkDeviceSlaveModeDialog.kt @@ -15,9 +15,9 @@ import network.loki.messenger.R import org.thoughtcrime.securesms.loki.redesign.utilities.MnemonicUtilities import org.thoughtcrime.securesms.util.TextSecurePreferences import org.thoughtcrime.securesms.util.Util -import org.whispersystems.signalservice.loki.api.DeviceLink -import org.whispersystems.signalservice.loki.api.DeviceLinkingSession -import org.whispersystems.signalservice.loki.api.DeviceLinkingSessionListener +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLink +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLinkingSession +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLinkingSessionListener import org.whispersystems.signalservice.loki.crypto.MnemonicCodec class LinkDeviceSlaveModeDialog : DialogFragment(), DeviceLinkingSessionListener { diff --git a/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt b/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt index 4b8fdc9037..ca0cb7fd4b 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt @@ -34,7 +34,8 @@ class BackgroundPollWorker : PersistentAlarmManagerListener() { try { val applicationContext = context.applicationContext as ApplicationContext val broadcaster = applicationContext.broadcaster - LokiAPI(userHexEncodedPublicKey, lokiAPIDatabase, broadcaster).getMessages().map { messages -> + LokiAPI.configureIfNeeded(userHexEncodedPublicKey, lokiAPIDatabase, broadcaster) + LokiAPI.shared.getMessages().map { messages -> messages.forEach { PushContentReceiveJob(context).processEnvelope(SignalServiceEnvelope(it)) } diff --git a/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiAPIDatabase.kt b/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiAPIDatabase.kt index fe70c7e934..23b401ff15 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiAPIDatabase.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiAPIDatabase.kt @@ -7,9 +7,9 @@ import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper import org.thoughtcrime.securesms.loki.redesign.utilities.* import org.thoughtcrime.securesms.util.Base64 import org.thoughtcrime.securesms.util.TextSecurePreferences -import org.whispersystems.signalservice.loki.api.DeviceLink import org.whispersystems.signalservice.loki.api.LokiAPIDatabaseProtocol import org.whispersystems.signalservice.loki.api.LokiAPITarget +import org.whispersystems.signalservice.loki.api.multidevice.DeviceLink // TODO: Clean this up a bit @@ -84,7 +84,7 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database( var string = "${target.address}-${target.port}" val keySet = target.publicKeySet if (keySet != null) { - string += "-${keySet.idKey}-${keySet.encryptionKey}" + string += "-${keySet.ed25519Key}-${keySet.x25519Key}" } string } diff --git a/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiPublicChatPoller.kt b/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiPublicChatPoller.kt index 51f2e59c51..49b64dd383 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiPublicChatPoller.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiPublicChatPoller.kt @@ -21,7 +21,11 @@ import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage import org.whispersystems.signalservice.api.messages.SignalServiceGroup import org.whispersystems.signalservice.api.messages.multidevice.SentTranscriptMessage import org.whispersystems.signalservice.api.push.SignalServiceAddress -import org.whispersystems.signalservice.loki.api.* +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChatAPI +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChatMessage import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus import org.whispersystems.signalservice.loki.utilities.successBackground import java.security.MessageDigest diff --git a/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiRSSFeedPoller.kt b/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiRSSFeedPoller.kt index c8ac9bb5fb..27c08a958b 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiRSSFeedPoller.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/messaging/LokiRSSFeedPoller.kt @@ -13,8 +13,8 @@ import org.whispersystems.signalservice.api.messages.SignalServiceContent import org.whispersystems.signalservice.api.messages.SignalServiceDataMessage import org.whispersystems.signalservice.api.messages.SignalServiceGroup import org.whispersystems.signalservice.api.push.SignalServiceAddress -import org.whispersystems.signalservice.loki.api.LokiRSSFeed -import org.whispersystems.signalservice.loki.api.LokiRSSFeedProxy +import org.whispersystems.signalservice.loki.api.rssfeeds.LokiRSSFeed +import org.whispersystems.signalservice.loki.api.rssfeeds.LokiRSSFeedProxy import org.whispersystems.signalservice.loki.utilities.successBackground import java.text.SimpleDateFormat import java.util.regex.Pattern diff --git a/src/org/thoughtcrime/securesms/loki/redesign/utilities/OpenGroupUtilities.kt b/src/org/thoughtcrime/securesms/loki/redesign/utilities/OpenGroupUtilities.kt index 87f7afdf6b..837c9bb1bd 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/utilities/OpenGroupUtilities.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/utilities/OpenGroupUtilities.kt @@ -8,7 +8,7 @@ import org.thoughtcrime.securesms.crypto.ProfileKeyUtil import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.groups.GroupManager import org.thoughtcrime.securesms.util.TextSecurePreferences -import org.whispersystems.signalservice.loki.api.LokiPublicChat +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChat object OpenGroupUtilities { diff --git a/src/org/thoughtcrime/securesms/loki/redesign/views/MentionCandidateView.kt b/src/org/thoughtcrime/securesms/loki/redesign/views/MentionCandidateView.kt index 831590d61c..0fcf572097 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/views/MentionCandidateView.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/views/MentionCandidateView.kt @@ -9,7 +9,7 @@ import android.widget.LinearLayout import kotlinx.android.synthetic.main.view_mention_candidate.view.* import network.loki.messenger.R import org.thoughtcrime.securesms.mms.GlideRequests -import org.whispersystems.signalservice.loki.api.LokiPublicChatAPI +import org.whispersystems.signalservice.loki.api.publicchats.LokiPublicChatAPI import org.whispersystems.signalservice.loki.messaging.Mention class MentionCandidateView(context: Context, attrs: AttributeSet?, defStyleAttr: Int) : LinearLayout(context, attrs, defStyleAttr) { diff --git a/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java b/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java index c976cabea1..27f7ddd87f 100644 --- a/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java +++ b/src/org/thoughtcrime/securesms/mms/PushMediaConstraints.java @@ -3,7 +3,7 @@ package org.thoughtcrime.securesms.mms; import android.content.Context; import org.thoughtcrime.securesms.util.Util; -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI; +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI; public class PushMediaConstraints extends MediaConstraints { diff --git a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java index c6e7f1b784..388746575e 100644 --- a/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java +++ b/src/org/thoughtcrime/securesms/notifications/MarkReadReceiver.java @@ -23,7 +23,7 @@ import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.loki.MultiDeviceUtilities; import org.thoughtcrime.securesms.service.ExpiringMessageManager; import org.thoughtcrime.securesms.util.Util; -import org.whispersystems.signalservice.loki.api.LokiFileServerAPI; +import org.whispersystems.signalservice.loki.api.fileserver.LokiFileServerAPI; import java.util.LinkedList; import java.util.List; diff --git a/src/org/thoughtcrime/securesms/sms/MessageSender.java b/src/org/thoughtcrime/securesms/sms/MessageSender.java index 438db55116..f11faf924a 100644 --- a/src/org/thoughtcrime/securesms/sms/MessageSender.java +++ b/src/org/thoughtcrime/securesms/sms/MessageSender.java @@ -62,7 +62,7 @@ import org.thoughtcrime.securesms.util.Util; import org.whispersystems.libsignal.util.guava.Optional; import org.whispersystems.signalservice.api.SignalServiceAccountManager; import org.whispersystems.signalservice.api.push.ContactTokenDetails; -import org.whispersystems.signalservice.loki.api.LokiDeviceLinkUtilities; +import org.whispersystems.signalservice.loki.api.multidevice.LokiDeviceLinkUtilities; import org.whispersystems.signalservice.loki.messaging.LokiThreadFriendRequestStatus; import org.whispersystems.signalservice.loki.utilities.PromiseUtil; From be688d80953295ca303ea107f797945d91b9cfd8 Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 9 Apr 2020 14:45:13 +1000 Subject: [PATCH 14/27] Update for core changes --- .../securesms/ApplicationPreferencesActivity.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java index 5325308411..86c436f345 100644 --- a/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java +++ b/src/org/thoughtcrime/securesms/ApplicationPreferencesActivity.java @@ -52,7 +52,7 @@ import org.thoughtcrime.securesms.util.DynamicLanguage; import org.thoughtcrime.securesms.util.DynamicTheme; import org.thoughtcrime.securesms.util.TextSecurePreferences; import org.whispersystems.signalservice.loki.crypto.MnemonicCodec; -import org.whispersystems.signalservice.loki.utilities.SerializationKt; +import org.whispersystems.signalservice.loki.utilities.HexEncodingKt; import java.io.File; @@ -341,7 +341,7 @@ public class ApplicationPreferencesActivity extends PassphraseRequiredActionBarA try { String hexEncodedSeed = IdentityKeyUtil.retrieve(getContext(), IdentityKeyUtil.lokiSeedKey); if (hexEncodedSeed == null) { - hexEncodedSeed = SerializationKt.getHexEncodedPrivateKey(IdentityKeyUtil.getIdentityKeyPair(getContext())); // Legacy account + hexEncodedSeed = HexEncodingKt.getHexEncodedPrivateKey(IdentityKeyUtil.getIdentityKeyPair(getContext())); // Legacy account } String seed = new MnemonicCodec(languageFileDirectory).encode(hexEncodedSeed, MnemonicCodec.Language.Configuration.Companion.getEnglish()); new AlertDialog.Builder(getContext()) From 45220bfa701af4d040bc72df2c6e6032ad91a0c5 Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 9 Apr 2020 13:23:51 +1000 Subject: [PATCH 15/27] Hide input when group is marked as not active. Fix bug where input panel gets shown when you long press a message. --- .../conversation/ConversationActivity.java | 31 ++++++++++--------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index d1b9136ddd..93819bc5f4 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -317,7 +317,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity private Button makeDefaultSmsButton; private Button registerButton; private InputAwareLayout container; - private View composePanel; protected Stub reminderView; private Stub unverifiedBannerView; private Stub groupShareProfileView; @@ -552,7 +551,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity updateTitleTextView(recipient); updateSubtitleTextView(); setActionBarColor(recipient.getColor()); - setBlockedUserState(recipient, isSecureText, isDefaultSms); + updateInputUI(recipient, isSecureText, isDefaultSms); setGroupShareProfileReminder(recipient); calculateCharactersRemaining(); @@ -645,7 +644,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity updateTitleTextView(recipient); updateSubtitleTextView(); NotificationChannels.updateContactChannelName(this, recipient); - setBlockedUserState(recipient, isSecureText, isDefaultSms); + updateInputUI(recipient, isSecureText, isDefaultSms); supportInvalidateOptionsMenu(); break; case TAKE_PHOTO: @@ -858,6 +857,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity searchViewModel.onSearchClosed(); searchNav.setVisibility(View.GONE); inputPanel.setVisibility(View.VISIBLE); + updateInputUI(recipient, isSecureText, isDefaultSms); fragment.onSearchQueryUpdated(null); invalidateOptionsMenu(); return true; @@ -1343,7 +1343,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity calculateCharactersRemaining(); supportInvalidateOptionsMenu(); - setBlockedUserState(recipient, isSecureText, isDefaultSms); + updateInputUI(recipient, isSecureText, isDefaultSms); } ///// Initializers @@ -1627,7 +1627,6 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity unblockButton = ViewUtil.findById(this, R.id.unblock_button); makeDefaultSmsButton = ViewUtil.findById(this, R.id.make_default_sms_button); registerButton = ViewUtil.findById(this, R.id.register_button); - composePanel = ViewUtil.findById(this, R.id.bottom_panel); container = ViewUtil.findById(this, R.id.layout_container); reminderView = ViewUtil.findStubById(this, R.id.reminder_stub); unverifiedBannerView = ViewUtil.findStubById(this, R.id.unverified_banner_stub); @@ -1835,7 +1834,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity updateTitleTextView(recipient); updateSubtitleTextView(); // titleView.setVerified(identityRecords.isVerified()); - setBlockedUserState(recipient, isSecureText, isDefaultSms); + updateInputUI(recipient, isSecureText, isDefaultSms); setActionBarColor(recipient.getColor()); setGroupShareProfileReminder(recipient); updateReminders(recipient.hasSeenInviteReminder()); @@ -2043,29 +2042,29 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity setStatusBarColor(getResources().getColor(R.color.action_bar_background)); } - private void setBlockedUserState(Recipient recipient, boolean isSecureText, boolean isDefaultSms) { - if (recipient.isGroupRecipient() && recipient.getAddress().isRSSFeed()) { + private void updateInputUI(Recipient recipient, boolean isSecureText, boolean isDefaultSms) { + if (recipient.isGroupRecipient() && !isActiveGroup()) { unblockButton.setVisibility(View.GONE); - composePanel.setVisibility(View.GONE); + inputPanel.setVisibility(View.GONE); makeDefaultSmsButton.setVisibility(View.GONE); registerButton.setVisibility(View.GONE); } else if (recipient.isBlocked()) { unblockButton.setVisibility(View.VISIBLE); - composePanel.setVisibility(View.GONE); + inputPanel.setVisibility(View.GONE); makeDefaultSmsButton.setVisibility(View.GONE); registerButton.setVisibility(View.GONE); } else if (!isSecureText && isPushGroupConversation()) { unblockButton.setVisibility(View.GONE); - composePanel.setVisibility(View.GONE); + inputPanel.setVisibility(View.GONE); makeDefaultSmsButton.setVisibility(View.GONE); registerButton.setVisibility(View.VISIBLE); } else if (!isSecureText && !isDefaultSms) { unblockButton.setVisibility(View.GONE); - composePanel.setVisibility(View.GONE); + inputPanel.setVisibility(View.GONE); makeDefaultSmsButton.setVisibility(View.VISIBLE); registerButton.setVisibility(View.GONE); } else { - composePanel.setVisibility(View.VISIBLE); + inputPanel.setVisibility(View.VISIBLE); unblockButton.setVisibility(View.GONE); makeDefaultSmsButton.setVisibility(View.GONE); registerButton.setVisibility(View.GONE); @@ -2125,7 +2124,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity } private boolean isActiveGroup() { - if (!isGroupConversation()) return false; + if (!isGroupConversation() || recipient.getAddress().isRSSFeed()) return false; Optional record = DatabaseFactory.getGroupDatabase(this).getGroup(getRecipient().getAddress().toGroupString()); return record.isPresent() && record.get().isActive(); @@ -2314,7 +2313,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity String hint = enabled ? "Message" : "Pending session request"; inputPanel.setHint(hint); inputPanel.setEnabled(enabled); - if (enabled) { + if (enabled && inputPanel.getVisibility() == View.VISIBLE) { inputPanel.composeText.requestFocus(); InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); inputMethodManager.showSoftInput(inputPanel.composeText, 0); @@ -2939,6 +2938,8 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity @Override public void handleReplyMessage(MessageRecord messageRecord) { + if (recipient.isGroupRecipient() && !isActiveGroup()) { return; } + Recipient author; if (messageRecord.isOutgoing()) { From 7d9eafe8fb67ac08f75d0fced6123f833be5465c Mon Sep 17 00:00:00 2001 From: Mikunj Date: Thu, 9 Apr 2020 15:30:29 +1000 Subject: [PATCH 16/27] Ignore closed group messages from users who are not members. --- .../groups/GroupMessageProcessor.java | 3 +-- .../securesms/jobs/PushDecryptJob.java | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 3 deletions(-) diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index 719a7dd7d8..29e591ffb2 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -137,8 +137,7 @@ public class GroupMessageProcessor { GroupDatabase database = DatabaseFactory.getGroupDatabase(context); String id = GroupUtil.getEncodedId(group); - String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context); - String ourHexEncodedPublicKey = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context); + String ourHexEncodedPublicKey = getMasterHexEncodedPublicKey(context, TextSecurePreferences.getLocalNumber(context)); if (group.getGroupType() == SignalServiceGroup.GroupType.SIGNAL) { // Only update group if admin sent the message diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index 29d3a12172..c421e3ba8b 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -1895,7 +1895,28 @@ public class PushDecryptJob extends BaseJob implements InjectableType { boolean isGroupActive = groupId.isPresent() && groupDatabase.isActive(groupId.get()); boolean isLeaveMessage = message.getGroupInfo().isPresent() && message.getGroupInfo().get().getType() == SignalServiceGroup.Type.QUIT; - return (isContentMessage && !isGroupActive) || (sender.isBlocked() && !isLeaveMessage); + boolean isClosedGroup = conversation.getAddress().isSignalGroup(); + boolean isGroupMember = true; + + // Only allow messages from members of a group + if (isClosedGroup) { + String senderHexEncodedPublicKey = content.getSender(); + + try { + String masterHexEncodedPublicKey = PromiseUtil.timeout(LokiDeviceLinkUtilities.INSTANCE.getMasterHexEncodedPublicKey(content.getSender()), 5000).get(); + if (masterHexEncodedPublicKey != null) { + senderHexEncodedPublicKey = masterHexEncodedPublicKey; + } + } catch (Exception e) { + e.printStackTrace(); + } + + Recipient senderMaster = Recipient.from(context, Address.fromSerialized(senderHexEncodedPublicKey), false); + + isGroupMember = groupId.isPresent() && groupDatabase.getGroupMembers(groupId.get(), true).contains(senderMaster); + } + + return (isContentMessage && !isGroupActive) || (sender.isBlocked() && !isLeaveMessage) || (isContentMessage && !isGroupMember); } else { return sender.isBlocked(); } From b72048d9a4c8ec394619ea031a6fb6463944a6f6 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 15 Apr 2020 10:24:30 +1000 Subject: [PATCH 17/27] add FCM to app for remote push notification --- AndroidManifest.xml | 9 ++ build.gradle | 4 + .../securesms/ApplicationContext.java | 25 +++++ .../loki/LokiPushNotificationManager.kt | 98 +++++++++++++++++++ .../messaging/BackgroundPollWorker.kt | 2 +- .../service/PushNotificationService.kt | 39 ++++++++ .../securesms/util/TextSecurePreferences.java | 10 ++ 7 files changed, 186 insertions(+), 1 deletion(-) create mode 100644 src/org/thoughtcrime/securesms/loki/LokiPushNotificationManager.kt create mode 100644 src/org/thoughtcrime/securesms/service/PushNotificationService.kt diff --git a/AndroidManifest.xml b/AndroidManifest.xml index bfa2c456dc..654d3bc721 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -47,6 +47,7 @@ + @@ -509,6 +510,14 @@ android:configChanges="touchscreen|keyboard|keyboardHidden|orientation|screenLayout|screenSize" android:exported="true" android:theme="@style/TextSecure.LightNoActionBar" /> + + + + + diff --git a/build.gradle b/build.gradle index 41e2ac5d37..fef89e3a44 100644 --- a/build.gradle +++ b/build.gradle @@ -16,6 +16,7 @@ buildscript { classpath "com.android.tools.build:gradle:$gradle_version" classpath files('libs/gradle-witness.jar') classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version" + classpath 'com.google.gms:google-services:4.3.3' } } @@ -24,6 +25,7 @@ apply plugin: 'kotlin-android-extensions' apply plugin: 'kotlin-android' apply plugin: 'witness' apply plugin: 'kotlin-kapt' +apply plugin: 'com.google.gms.google-services' repositories { mavenLocal() @@ -87,6 +89,8 @@ dependencies { implementation 'android.arch.lifecycle:extensions:1.1.1' implementation 'android.arch.lifecycle:common-java8:1.1.1' + implementation 'com.google.firebase:firebase-messaging:18.0.0' + implementation 'com.google.android.exoplayer:exoplayer-core:2.9.1' implementation 'com.google.android.exoplayer:exoplayer-ui:2.9.1' diff --git a/src/org/thoughtcrime/securesms/ApplicationContext.java b/src/org/thoughtcrime/securesms/ApplicationContext.java index 0687981f55..7e6215f2a7 100644 --- a/src/org/thoughtcrime/securesms/ApplicationContext.java +++ b/src/org/thoughtcrime/securesms/ApplicationContext.java @@ -30,6 +30,11 @@ import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.multidex.MultiDexApplication; +import com.google.android.gms.tasks.OnCompleteListener; +import com.google.android.gms.tasks.Task; +import com.google.firebase.iid.FirebaseInstanceId; +import com.google.firebase.iid.InstanceIdResult; + import org.conscrypt.Conscrypt; import org.jetbrains.annotations.NotNull; import org.signal.aesgcmprovider.AesGcmProvider; @@ -61,6 +66,7 @@ import org.thoughtcrime.securesms.logging.Log; import org.thoughtcrime.securesms.logging.PersistentLogger; import org.thoughtcrime.securesms.logging.UncaughtExceptionLogger; import org.thoughtcrime.securesms.loki.LokiPublicChatManager; +import org.thoughtcrime.securesms.loki.LokiPushNotificationManager; import org.thoughtcrime.securesms.loki.MultiDeviceUtilities; import org.thoughtcrime.securesms.loki.redesign.activities.HomeActivity; import org.thoughtcrime.securesms.loki.redesign.messaging.BackgroundOpenGroupPollWorker; @@ -197,6 +203,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc // Loki - Set up public chat manager lokiPublicChatManager = new LokiPublicChatManager(this); updatePublicChatProfilePictureIfNeeded(); + setUpFirebaseDeviceToken(); } @Override @@ -453,6 +460,24 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc }, this); } + public void setUpFirebaseDeviceToken() { + Context context = this; + FirebaseInstanceId.getInstance().getInstanceId() + .addOnCompleteListener(new OnCompleteListener() { + @Override + public void onComplete(@NonNull Task task) { + if (!task.isSuccessful()) { + Log.w(TAG, "getInstanceId failed", task.getException()); + return; + } + // Get new Instance ID token + String token = task.getResult().getToken(); + String userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context); + LokiPushNotificationManager.register(token, userHexEncodedPublicKey, context); + } + }); + } + @Override public void ping(@NotNull String s) { // TODO: Implement diff --git a/src/org/thoughtcrime/securesms/loki/LokiPushNotificationManager.kt b/src/org/thoughtcrime/securesms/loki/LokiPushNotificationManager.kt new file mode 100644 index 0000000000..8378519412 --- /dev/null +++ b/src/org/thoughtcrime/securesms/loki/LokiPushNotificationManager.kt @@ -0,0 +1,98 @@ +package org.thoughtcrime.securesms.loki + +import android.content.Context +import okhttp3.* +import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.whispersystems.libsignal.logging.Log +import org.whispersystems.signalservice.internal.util.JsonUtil +import java.io.IOException + +object LokiPushNotificationManager { + //const val server = "https://live.apns.getsession.org/" + const val server = "https://dev.apns.getsession.org/" + const val tokenExpirationInterval = 2 * 24 * 60 * 60 + private val connection = OkHttpClient() + + fun disableRemoteNotification(token: String, context: Context?) { + val parameters = mapOf("token" to token) + val url = "${server}register" + val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters)) + val request = Request.Builder().url(url).post(body).build() + connection.newCall(request).enqueue(object : Callback { + + override fun onResponse(call: Call, response: Response) { + when (response.code()) { + 200 -> { + val bodyAsString = response.body()!!.string() + val json = JsonUtil.fromJson(bodyAsString, Map::class.java) + val code = json?.get("code") as? Int + if (code != null && code != 0) { + TextSecurePreferences.setIsUsingRemoteNotification(context, false) + } else { + Log.d("Loki", "Couldn't disable remote notification due to error: ${json?.get("message") as? String}.") + } + } + } + } + + override fun onFailure(call: Call, exception: IOException) { + Log.d("Loki", "Couldn't disable remote notification.") + } + }) + } + + @JvmStatic + fun register(token: String, hexEncodedPublicKey: String, context: Context?) { + val parameters = mapOf("token" to token, "pubKey" to hexEncodedPublicKey) + val url = "${server}register" + val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters)) + val request = Request.Builder().url(url).post(body).build() + connection.newCall(request).enqueue(object : Callback { + + override fun onResponse(call: Call, response: Response) { + when (response.code()) { + 200 -> { + val bodyAsString = response.body()!!.string() + val json = JsonUtil.fromJson(bodyAsString, Map::class.java) + val code = json?.get("code") as? Int + if (code != null && code != 0) { + TextSecurePreferences.setIsUsingRemoteNotification(context, true) + } else { + Log.d("Loki", "Couldn't register device token due to error: ${json?.get("message") as? String}.") + } + } + } + } + + override fun onFailure(call: Call, exception: IOException) { + Log.d("Loki", "Couldn't register device token.") + } + }) + } + + fun acknowledgeDeliveryForMessageWith(hash: String, expiration: Int, hexEncodedPublicKey: String, context: Context?) { + val parameters = mapOf("hash" to hash, "pubKey" to hexEncodedPublicKey, "expiration" to expiration) + val url = "${server}acknowledge_message_delivery" + val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters)) + val request = Request.Builder().url(url).post(body).build() + connection.newCall(request).enqueue(object : Callback { + + override fun onResponse(call: Call, response: Response) { + when (response.code()) { + 200 -> { + val bodyAsString = response.body()!!.string() + val json = JsonUtil.fromJson(bodyAsString, Map::class.java) + val code = json?.get("code") as? Int + if (code == null || code == 0) { + Log.d("Loki", "Couldn't acknowledge the delivery for message due to error: ${json?.get("message") as? String}.") + } + } + } + } + + override fun onFailure(call: Call, exception: IOException) { + Log.d("Loki", "Couldn't acknowledge the delivery for message with last hash: ${hash}") + } + }) + } +} diff --git a/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt b/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt index 4b8fdc9037..19c335f41a 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt @@ -15,7 +15,7 @@ import java.util.concurrent.TimeUnit class BackgroundPollWorker : PersistentAlarmManagerListener() { companion object { - private val pollInterval = TimeUnit.MINUTES.toMillis(2) + private val pollInterval = TimeUnit.MINUTES.toMillis(20) @JvmStatic fun schedule(context: Context) { diff --git a/src/org/thoughtcrime/securesms/service/PushNotificationService.kt b/src/org/thoughtcrime/securesms/service/PushNotificationService.kt new file mode 100644 index 0000000000..c877510f59 --- /dev/null +++ b/src/org/thoughtcrime/securesms/service/PushNotificationService.kt @@ -0,0 +1,39 @@ +package org.thoughtcrime.securesms.service + +import com.google.firebase.messaging.FirebaseMessagingService +import com.google.firebase.messaging.RemoteMessage +import org.thoughtcrime.securesms.ApplicationContext +import org.thoughtcrime.securesms.jobs.PushContentReceiveJob +import org.thoughtcrime.securesms.loki.LokiPushNotificationManager +import org.thoughtcrime.securesms.util.TextSecurePreferences +import org.whispersystems.libsignal.logging.Log +import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope +import org.whispersystems.signalservice.internal.util.Base64 +import org.whispersystems.signalservice.loki.messaging.LokiMessageWrapper + +class PushNotificationService: FirebaseMessagingService() { + + override fun onNewToken(token: String) { + super.onNewToken(token) + Log.d("Loki", "new token ${token}") + val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this) + LokiPushNotificationManager.register(token, userHexEncodedPublicKey, this) + } + + override fun onMessageReceived(message: RemoteMessage) { + val base64EncodedData = message.data["ENCRYPTED_DATA"] + val data = base64EncodedData?.let { Base64.decode(it) } + if (data != null) { + try { + val envelope = LokiMessageWrapper.unwrap(data) + PushContentReceiveJob(this).processEnvelope(SignalServiceEnvelope(envelope)) + } catch (e: Exception) { + Log.d("Loki", "Failed to unwrap data for message.") + } + } else { + Log.d("Loki", "Failed to decode data for message.") + } + } + + +} \ No newline at end of file diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java index 42c204dfbb..62fc6c258e 100644 --- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java +++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java @@ -185,6 +185,16 @@ public class TextSecurePreferences { private static final String MEDIA_KEYBOARD_MODE = "pref_media_keyboard_mode"; + private static final String IS_USING_REMOTE_NOTIFICATION = "pref_is_using_remote_notification"; + + public static boolean isUsingRemoteNotification(Context context) { + return getBooleanPreference(context, IS_USING_REMOTE_NOTIFICATION, false); + } + + public static void setIsUsingRemoteNotification(Context context, boolean value) { + setBooleanPreference(context, IS_USING_REMOTE_NOTIFICATION, value); + } + public static boolean isScreenLockEnabled(@NonNull Context context) { return getBooleanPreference(context, SCREEN_LOCK, false); } From 6ed3a4c3726ead174f073930c3199067d2d9c56d Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Wed, 15 Apr 2020 15:01:02 +1000 Subject: [PATCH 18/27] Add FIXME --- .../securesms/conversation/ConversationActivity.java | 1 + .../securesms/groups/GroupMessageProcessor.java | 8 ++++---- src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java | 6 +++--- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java index 93819bc5f4..7721233336 100644 --- a/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java +++ b/src/org/thoughtcrime/securesms/conversation/ConversationActivity.java @@ -2042,6 +2042,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity setStatusBarColor(getResources().getColor(R.color.action_bar_background)); } + // FIXME: This name is confusing because we also have updateInputPanel and setInputPanelEnabled private void updateInputUI(Recipient recipient, boolean isSecureText, boolean isDefaultSms) { if (recipient.isGroupRecipient() && !isActiveGroup()) { unblockButton.setVisibility(View.GONE); diff --git a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java index 29e591ffb2..52ffa66183 100644 --- a/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java +++ b/src/org/thoughtcrime/securesms/groups/GroupMessageProcessor.java @@ -140,18 +140,18 @@ public class GroupMessageProcessor { String ourHexEncodedPublicKey = getMasterHexEncodedPublicKey(context, TextSecurePreferences.getLocalNumber(context)); if (group.getGroupType() == SignalServiceGroup.GroupType.SIGNAL) { - // Only update group if admin sent the message + // Only update group if the group admin sent the message String hexEncodedPublicKey = getMasterHexEncodedPublicKey(context, content.getSender()); if (!groupRecord.getAdmins().contains(Address.fromSerialized(hexEncodedPublicKey))) { Log.d("Loki - Group Message", "Received a group update message from a non-admin user for " + id +". Ignoring."); return null; } - // We should only process update message if we were in the group + // We should only process update messages if we're in the group Address ourAddress = Address.fromSerialized(ourHexEncodedPublicKey); if (!groupRecord.getMembers().contains(ourAddress) && !group.getMembers().or(Collections.emptyList()).contains(ourHexEncodedPublicKey)) { - Log.d("Loki - Group Message", "Received a group update message from a group we are not members in: " + id + " . Ignoring."); + Log.d("Loki - Group Message", "Received a group update message from a group we are not a member of: " + id + "; ignoring."); database.setActive(id, false); return null; } @@ -181,7 +181,7 @@ public class GroupMessageProcessor { } // We add any new or removed members to the group context - // This will allow us later to iterate over them to check if they left or were added for UI display + // This will allow us later to iterate over them to check if they left or were added for UI purposes for (Address addedMember : addedMembers) { builder.addNewMembers(addedMember.serialize()); } diff --git a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java index c421e3ba8b..96d76d818c 100644 --- a/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java +++ b/src/org/thoughtcrime/securesms/jobs/PushDecryptJob.java @@ -1898,7 +1898,7 @@ public class PushDecryptJob extends BaseJob implements InjectableType { boolean isClosedGroup = conversation.getAddress().isSignalGroup(); boolean isGroupMember = true; - // Only allow messages from members of a group + // Only allow messages from group members if (isClosedGroup) { String senderHexEncodedPublicKey = content.getSender(); @@ -1911,9 +1911,9 @@ public class PushDecryptJob extends BaseJob implements InjectableType { e.printStackTrace(); } - Recipient senderMaster = Recipient.from(context, Address.fromSerialized(senderHexEncodedPublicKey), false); + Recipient senderMasterAddress = Recipient.from(context, Address.fromSerialized(senderHexEncodedPublicKey), false); - isGroupMember = groupId.isPresent() && groupDatabase.getGroupMembers(groupId.get(), true).contains(senderMaster); + isGroupMember = groupId.isPresent() && groupDatabase.getGroupMembers(groupId.get(), true).contains(senderMasterAddress); } return (isContentMessage && !isGroupActive) || (sender.isBlocked() && !isLeaveMessage) || (isContentMessage && !isGroupMember); From 8ea2fe0294627ef196282121271cce29f58c0631 Mon Sep 17 00:00:00 2001 From: ryanzhao Date: Wed, 15 Apr 2020 15:03:57 +1000 Subject: [PATCH 19/27] add update token guard and move acknowledgement to signal service --- .../loki/LokiPushNotificationManager.kt | 32 ++++--------------- .../messaging/BackgroundPollWorker.kt | 3 +- .../securesms/util/TextSecurePreferences.java | 19 +++++++++++ 3 files changed, 28 insertions(+), 26 deletions(-) diff --git a/src/org/thoughtcrime/securesms/loki/LokiPushNotificationManager.kt b/src/org/thoughtcrime/securesms/loki/LokiPushNotificationManager.kt index 8378519412..4858e2c818 100644 --- a/src/org/thoughtcrime/securesms/loki/LokiPushNotificationManager.kt +++ b/src/org/thoughtcrime/securesms/loki/LokiPushNotificationManager.kt @@ -10,7 +10,7 @@ import java.io.IOException object LokiPushNotificationManager { //const val server = "https://live.apns.getsession.org/" const val server = "https://dev.apns.getsession.org/" - const val tokenExpirationInterval = 2 * 24 * 60 * 60 + const val tokenExpirationInterval = 2 * 24 * 60 * 60 * 1000 private val connection = OkHttpClient() fun disableRemoteNotification(token: String, context: Context?) { @@ -43,6 +43,10 @@ object LokiPushNotificationManager { @JvmStatic fun register(token: String, hexEncodedPublicKey: String, context: Context?) { + if (token == TextSecurePreferences.getTokenForRemoteNotification(context) && System.currentTimeMillis() - TextSecurePreferences.getLastTimeForTokenUploading(context) < tokenExpirationInterval) { + return + } + val parameters = mapOf("token" to token, "pubKey" to hexEncodedPublicKey) val url = "${server}register" val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters)) @@ -57,6 +61,8 @@ object LokiPushNotificationManager { val code = json?.get("code") as? Int if (code != null && code != 0) { TextSecurePreferences.setIsUsingRemoteNotification(context, true) + TextSecurePreferences.setTokenForRemoteNotification(context, token) + TextSecurePreferences.setLastTimeForTokenUploading(context, System.currentTimeMillis()) } else { Log.d("Loki", "Couldn't register device token due to error: ${json?.get("message") as? String}.") } @@ -70,29 +76,5 @@ object LokiPushNotificationManager { }) } - fun acknowledgeDeliveryForMessageWith(hash: String, expiration: Int, hexEncodedPublicKey: String, context: Context?) { - val parameters = mapOf("hash" to hash, "pubKey" to hexEncodedPublicKey, "expiration" to expiration) - val url = "${server}acknowledge_message_delivery" - val body = RequestBody.create(MediaType.get("application/json"), JsonUtil.toJson(parameters)) - val request = Request.Builder().url(url).post(body).build() - connection.newCall(request).enqueue(object : Callback { - override fun onResponse(call: Call, response: Response) { - when (response.code()) { - 200 -> { - val bodyAsString = response.body()!!.string() - val json = JsonUtil.fromJson(bodyAsString, Map::class.java) - val code = json?.get("code") as? Int - if (code == null || code == 0) { - Log.d("Loki", "Couldn't acknowledge the delivery for message due to error: ${json?.get("message") as? String}.") - } - } - } - } - - override fun onFailure(call: Call, exception: IOException) { - Log.d("Loki", "Couldn't acknowledge the delivery for message with last hash: ${hash}") - } - }) - } } diff --git a/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt b/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt index 53cd42c29e..7205e624de 100644 --- a/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt +++ b/src/org/thoughtcrime/securesms/loki/redesign/messaging/BackgroundPollWorker.kt @@ -6,6 +6,7 @@ import nl.komponents.kovenant.functional.map import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.jobs.PushContentReceiveJob +import org.thoughtcrime.securesms.loki.LokiPushNotificationManager import org.thoughtcrime.securesms.service.PersistentAlarmManagerListener import org.thoughtcrime.securesms.util.TextSecurePreferences import org.whispersystems.signalservice.api.messages.SignalServiceEnvelope @@ -15,7 +16,7 @@ import java.util.concurrent.TimeUnit class BackgroundPollWorker : PersistentAlarmManagerListener() { companion object { - private val pollInterval = TimeUnit.MINUTES.toMillis(20) + private val pollInterval = TimeUnit.MINUTES.toMillis(2) @JvmStatic fun schedule(context: Context) { diff --git a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java index 62fc6c258e..c1fbd89b25 100644 --- a/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java +++ b/src/org/thoughtcrime/securesms/util/TextSecurePreferences.java @@ -185,7 +185,10 @@ public class TextSecurePreferences { private static final String MEDIA_KEYBOARD_MODE = "pref_media_keyboard_mode"; + //Session for Push Notification private static final String IS_USING_REMOTE_NOTIFICATION = "pref_is_using_remote_notification"; + private static final String TOKEN_FOR_REMOTE_NOTIFICATION = "pref_token_for_remote_notification"; + private static final String LAST_TIME_FOR_TOKEN_UPLOADING = "pref_last_time_for_token_uploading"; public static boolean isUsingRemoteNotification(Context context) { return getBooleanPreference(context, IS_USING_REMOTE_NOTIFICATION, false); @@ -195,6 +198,22 @@ public class TextSecurePreferences { setBooleanPreference(context, IS_USING_REMOTE_NOTIFICATION, value); } + public static String getTokenForRemoteNotification(Context context) { + return getStringPreference(context, TOKEN_FOR_REMOTE_NOTIFICATION, ""); + } + + public static void setTokenForRemoteNotification(Context context, String value) { + setStringPreference(context, TOKEN_FOR_REMOTE_NOTIFICATION, value); + } + + public static long getLastTimeForTokenUploading(Context context) { + return getLongPreference(context, LAST_TIME_FOR_TOKEN_UPLOADING, 0); + } + + public static void setLastTimeForTokenUploading(Context context, long value) { + setLongPreference(context, LAST_TIME_FOR_TOKEN_UPLOADING, value); + } + public static boolean isScreenLockEnabled(@NonNull Context context) { return getBooleanPreference(context, SCREEN_LOCK, false); } From c09032900feccb40719cdd90348c942148697c7b Mon Sep 17 00:00:00 2001 From: nielsandriesse Date: Thu, 16 Apr 2020 14:49:23 +1000 Subject: [PATCH 20/27] Implement PN mode screen UI --- AndroidManifest.xml | 3 + res/drawable/pn_option_background.xml | 15 +++ ..._option_background_deselect_transition.xml | 5 + ...pn_option_background_select_transition.xml | 5 + .../pn_option_background_selected.xml | 15 +++ res/layout-sw400dp/activity_pn_mode.xml | 116 ++++++++++++++++++ res/layout/activity_pn_mode.xml | 116 ++++++++++++++++++ res/values/colors.xml | 2 + res/values/dimens.xml | 1 + res/values/strings.xml | 8 ++ .../redesign/activities/PNModeActivity.kt | 77 ++++++++++++ 11 files changed, 363 insertions(+) create mode 100644 res/drawable/pn_option_background.xml create mode 100644 res/drawable/pn_option_background_deselect_transition.xml create mode 100644 res/drawable/pn_option_background_select_transition.xml create mode 100644 res/drawable/pn_option_background_selected.xml create mode 100644 res/layout-sw400dp/activity_pn_mode.xml create mode 100644 res/layout/activity_pn_mode.xml create mode 100644 src/org/thoughtcrime/securesms/loki/redesign/activities/PNModeActivity.kt diff --git a/AndroidManifest.xml b/AndroidManifest.xml index bfa2c456dc..ea4e449167 100644 --- a/AndroidManifest.xml +++ b/AndroidManifest.xml @@ -112,6 +112,9 @@ android:name="org.thoughtcrime.securesms.loki.redesign.activities.DisplayNameActivity" android:screenOrientation="portrait" android:windowSoftInputMode="adjustResize" /> + + + + + + + + + + \ No newline at end of file diff --git a/res/drawable/pn_option_background_deselect_transition.xml b/res/drawable/pn_option_background_deselect_transition.xml new file mode 100644 index 0000000000..7fcb8e1160 --- /dev/null +++ b/res/drawable/pn_option_background_deselect_transition.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/res/drawable/pn_option_background_select_transition.xml b/res/drawable/pn_option_background_select_transition.xml new file mode 100644 index 0000000000..21c58cf71d --- /dev/null +++ b/res/drawable/pn_option_background_select_transition.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/res/drawable/pn_option_background_selected.xml b/res/drawable/pn_option_background_selected.xml new file mode 100644 index 0000000000..56d1ed983a --- /dev/null +++ b/res/drawable/pn_option_background_selected.xml @@ -0,0 +1,15 @@ + + + + + + + + + + \ No newline at end of file diff --git a/res/layout-sw400dp/activity_pn_mode.xml b/res/layout-sw400dp/activity_pn_mode.xml new file mode 100644 index 0000000000..8edc9267df --- /dev/null +++ b/res/layout-sw400dp/activity_pn_mode.xml @@ -0,0 +1,116 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +