Remove unused context arguments in RecipientUtil.

This commit is contained in:
Cody Henthorne 2022-10-06 08:57:30 -04:00 committed by Greyson Parrelli
parent db0bca00ec
commit bef83e4c0c
14 changed files with 50 additions and 50 deletions

View file

@ -69,7 +69,7 @@ class BlockedUsersRepository {
void unblock(@NonNull RecipientId recipientId, @NonNull Runnable success) {
SignalExecutors.BOUNDED.execute(() -> {
RecipientUtil.unblock(context, Recipient.resolved(recipientId));
RecipientUtil.unblock(Recipient.resolved(recipientId));
success.run();
});
}

View file

@ -175,7 +175,7 @@ class ConversationSettingsRepository(
fun unblock(recipientId: RecipientId) {
SignalExecutors.BOUNDED.execute {
val recipient = Recipient.resolved(recipientId)
RecipientUtil.unblock(context, recipient)
RecipientUtil.unblock(recipient)
}
}
@ -189,7 +189,7 @@ class ConversationSettingsRepository(
fun unblock(groupId: GroupId) {
SignalExecutors.BOUNDED.execute {
val recipient = Recipient.externalGroupExact(groupId)
RecipientUtil.unblock(context, recipient)
RecipientUtil.unblock(recipient)
}
}

View file

@ -1286,7 +1286,7 @@ public class ConversationParentFragment extends Fragment
final Context context = requireContext().getApplicationContext();
BlockUnblockDialog.showUnblockFor(requireContext(), getLifecycle(), recipient.get(), () -> {
SignalExecutors.BOUNDED.execute(() -> {
RecipientUtil.unblock(context, recipient.get());
RecipientUtil.unblock(recipient.get());
});
});
}
@ -2232,7 +2232,7 @@ public class ConversationParentFragment extends Fragment
}
private void initializeLinkPreviewObserver() {
linkPreviewViewModel = new ViewModelProvider(this, new LinkPreviewViewModel.Factory(new LinkPreviewRepository())).get(LinkPreviewViewModel.class);
linkPreviewViewModel = new ViewModelProvider(this, (ViewModelProvider.Factory) new LinkPreviewViewModel.Factory(new LinkPreviewRepository())).get(LinkPreviewViewModel.class);
linkPreviewViewModel.getLinkPreviewState().observe(getViewLifecycleOwner(), previewState -> {
if (previewState == null) return;
@ -2252,7 +2252,7 @@ public class ConversationParentFragment extends Fragment
private void initializeSearchObserver() {
ConversationSearchViewModel.Factory viewModelFactory = new ConversationSearchViewModel.Factory(getString(R.string.note_to_self));
searchViewModel = new ViewModelProvider(this, viewModelFactory).get(ConversationSearchViewModel.class);
searchViewModel = new ViewModelProvider(this, (ViewModelProvider.Factory) viewModelFactory).get(ConversationSearchViewModel.class);
searchViewModel.getSearchResults().observe(getViewLifecycleOwner(), result -> {
if (result == null) return;
@ -2269,7 +2269,7 @@ public class ConversationParentFragment extends Fragment
private void initializeStickerObserver() {
StickerSearchRepository repository = new StickerSearchRepository(requireContext());
stickerViewModel = new ViewModelProvider(this, new ConversationStickerViewModel.Factory(requireActivity().getApplication(), repository))
stickerViewModel = new ViewModelProvider(this, (ViewModelProvider.Factory) new ConversationStickerViewModel.Factory(requireActivity().getApplication(), repository))
.get(ConversationStickerViewModel.class);
stickerViewModel.getStickerResults().observe(getViewLifecycleOwner(), stickers -> {
@ -2308,7 +2308,7 @@ public class ConversationParentFragment extends Fragment
}
private void initializeViewModel(@NonNull ConversationIntents.Args args) {
this.viewModel = new ViewModelProvider(this, new ConversationViewModel.Factory()).get(ConversationViewModel.class);
this.viewModel = new ViewModelProvider(this, (ViewModelProvider.Factory) new ConversationViewModel.Factory()).get(ConversationViewModel.class);
this.viewModel.setArgs(args);
this.viewModel.getEvents().observe(getViewLifecycleOwner(), this::onViewModelEvent);
@ -2316,7 +2316,7 @@ public class ConversationParentFragment extends Fragment
}
private void initializeGroupViewModel() {
groupViewModel = new ViewModelProvider(this, new ConversationGroupViewModel.Factory()).get(ConversationGroupViewModel.class);
groupViewModel = new ViewModelProvider(this, (ViewModelProvider.Factory) new ConversationGroupViewModel.Factory()).get(ConversationGroupViewModel.class);
recipient.observe(this, groupViewModel::onRecipientChange);
groupViewModel.getGroupActiveState().observe(getViewLifecycleOwner(), unused -> invalidateOptionsMenu());
groupViewModel.getReviewState().observe(getViewLifecycleOwner(), this::presentGroupReviewBanner);

View file

@ -740,7 +740,7 @@ public class ConversationListFragment extends MainFragment implements ActionMode
ConversationListViewModel.Factory viewModelFactory = new ConversationListViewModel.Factory(isArchived(),
getString(R.string.note_to_self));
viewModel = new ViewModelProvider(this, viewModelFactory).get(ConversationListViewModel.class);
viewModel = new ViewModelProvider(this, (ViewModelProvider.Factory) viewModelFactory).get(ConversationListViewModel.class);
viewModel.getSearchResult().observe(getViewLifecycleOwner(), this::onSearchResultChanged);
viewModel.getMegaphone().observe(getViewLifecycleOwner(), this::onMegaphoneChanged);

View file

@ -1535,7 +1535,7 @@ public class ThreadDatabase extends Database {
private @Nullable Extra getExtrasFor(@NonNull MessageRecord record) {
Recipient threadRecipient = record.isOutgoing() ? record.getRecipient() : getRecipientForThreadId(record.getThreadId());
boolean messageRequestAccepted = RecipientUtil.isMessageRequestAccepted(context, record.getThreadId(), threadRecipient);
boolean messageRequestAccepted = RecipientUtil.isMessageRequestAccepted(record.getThreadId(), threadRecipient);
RecipientId individualRecipientId = record.getIndividualRecipient().getId();
//noinspection ConstantConditions

View file

@ -189,7 +189,7 @@ public final class PushGroupSendJob extends PushSendJob {
log(TAG, String.valueOf(message.getSentTimeMillis()), "Sending message: " + messageId + ", Recipient: " + message.getRecipient().getId() + ", Thread: " + threadId + ", Attachments: " + buildAttachmentString(message.getAttachments()));
if (!groupRecipient.resolve().isProfileSharing() && !database.isGroupQuitMessage(messageId)) {
RecipientUtil.shareProfileIfFirstSecureMessage(context, groupRecipient);
RecipientUtil.shareProfileIfFirstSecureMessage(groupRecipient);
}
List<Recipient> target;

View file

@ -124,7 +124,7 @@ public class PushMediaSendJob extends PushSendJob {
try {
log(TAG, String.valueOf(message.getSentTimeMillis()), "Sending message: " + messageId + ", Recipient: " + message.getRecipient().getId() + ", Thread: " + threadId + ", Attachments: " + buildAttachmentString(message.getAttachments()));
RecipientUtil.shareProfileIfFirstSecureMessage(context, message.getRecipient());
RecipientUtil.shareProfileIfFirstSecureMessage(message.getRecipient());
Recipient recipient = message.getRecipient().fresh();
byte[] profileKey = recipient.getProfileKey();

View file

@ -89,7 +89,7 @@ public class PushTextSendJob extends PushSendJob {
try {
log(TAG, String.valueOf(record.getDateSent()), "Sending message: " + messageId + ", Recipient: " + record.getRecipient().getId() + ", Thread: " + record.getThreadId());
RecipientUtil.shareProfileIfFirstSecureMessage(context, record.getRecipient());
RecipientUtil.shareProfileIfFirstSecureMessage(record.getRecipient());
Recipient recipient = record.getRecipient().resolve();
byte[] profileKey = recipient.getProfileKey();

View file

@ -253,7 +253,7 @@ final class MessageRequestRepository {
executor.execute(() -> {
Recipient recipient = liveRecipient.resolve();
RecipientUtil.unblock(context, recipient);
RecipientUtil.unblock(recipient);
if (TextSecurePreferences.isMultiDevice(context)) {
ApplicationDependencies.getJobManager().add(MultiDeviceMessageRequestResponseJob.forAccept(liveRecipient.getId()));
@ -277,6 +277,6 @@ final class MessageRequestRepository {
Long threadId = SignalDatabase.threads().getThreadIdFor(recipient.getId());
return threadId != null &&
(RecipientUtil.hasSentMessageInThread(context, threadId) || RecipientUtil.isPreMessageRequestThread(context, threadId));
(RecipientUtil.hasSentMessageInThread(threadId) || RecipientUtil.isPreMessageRequestThread(threadId));
}
}

View file

@ -312,7 +312,7 @@ public final class MessageContentProcessor {
if (content.isNeedsReceipt() && messageId != null) {
handleNeedsDeliveryReceipt(content, message, messageId);
} else if (!content.isNeedsReceipt()) {
if (RecipientUtil.shouldHaveProfileKey(context, threadRecipient)) {
if (RecipientUtil.shouldHaveProfileKey(threadRecipient)) {
Log.w(TAG, "Received an unsealed sender message from " + senderRecipient.getId() + ", but they should already have our profile key. Correcting.");
if (groupId.isPresent() && groupId.get().isV2()) {

View file

@ -172,7 +172,7 @@ public class RecipientUtil {
SignalDatabase.recipients().setBlocked(recipient.getId(), true);
if (recipient.isSystemContact() || recipient.isProfileSharing() || isProfileSharedViaGroup(context, recipient)) {
if (recipient.isSystemContact() || recipient.isProfileSharing() || isProfileSharedViaGroup(recipient)) {
SignalDatabase.recipients().setProfileSharing(recipient.getId(), false);
ApplicationDependencies.getJobManager().startChain(new RefreshOwnProfileJob())
@ -185,7 +185,7 @@ public class RecipientUtil {
}
@WorkerThread
public static void unblock(@NonNull Context context, @NonNull Recipient recipient) {
public static void unblock(@NonNull Recipient recipient) {
if (!isBlockable(recipient)) {
throw new AssertionError("Recipient is not blockable!");
}
@ -221,7 +221,7 @@ public class RecipientUtil {
return true;
}
return isMessageRequestAccepted(context, threadId, threadRecipient);
return isMessageRequestAccepted(threadId, threadRecipient);
}
/**
@ -234,7 +234,7 @@ public class RecipientUtil {
}
Long threadId = SignalDatabase.threads().getThreadIdFor(threadRecipient.getId());
return isMessageRequestAccepted(context, threadId, threadRecipient);
return isMessageRequestAccepted(threadId, threadRecipient);
}
/**
@ -242,33 +242,33 @@ public class RecipientUtil {
* is more likely to return false.
*/
@WorkerThread
public static boolean isCallRequestAccepted(@NonNull Context context, @Nullable Recipient threadRecipient) {
public static boolean isCallRequestAccepted(@Nullable Recipient threadRecipient) {
if (threadRecipient == null) {
return true;
}
Long threadId = SignalDatabase.threads().getThreadIdFor(threadRecipient.getId());
return isCallRequestAccepted(context, threadId, threadRecipient);
return isCallRequestAccepted(threadId, threadRecipient);
}
/**
* @return True if a conversation existed before we enabled message requests, otherwise false.
*/
@WorkerThread
public static boolean isPreMessageRequestThread(@NonNull Context context, @Nullable Long threadId) {
public static boolean isPreMessageRequestThread(@Nullable Long threadId) {
long beforeTime = SignalStore.misc().getMessageRequestEnableTime();
return threadId != null && SignalDatabase.mmsSms().getConversationCount(threadId, beforeTime) > 0;
}
@WorkerThread
public static void shareProfileIfFirstSecureMessage(@NonNull Context context, @NonNull Recipient recipient) {
public static void shareProfileIfFirstSecureMessage(@NonNull Recipient recipient) {
if (recipient.isProfileSharing()) {
return;
}
long threadId = SignalDatabase.threads().getThreadIdIfExistsFor(recipient.getId());
if (isPreMessageRequestThread(context, threadId)) {
if (isPreMessageRequestThread(threadId)) {
return;
}
@ -290,7 +290,7 @@ public class RecipientUtil {
/**
* @return True if this recipient should already have your profile key, otherwise false.
*/
public static boolean shouldHaveProfileKey(@NonNull Context context, @NonNull Recipient recipient) {
public static boolean shouldHaveProfileKey(@NonNull Recipient recipient) {
if (recipient.isBlocked()) {
return false;
}
@ -327,33 +327,33 @@ public class RecipientUtil {
}
@WorkerThread
public static boolean isMessageRequestAccepted(@NonNull Context context, @Nullable Long threadId, @Nullable Recipient threadRecipient) {
public static boolean isMessageRequestAccepted(@Nullable Long threadId, @Nullable Recipient threadRecipient) {
return threadRecipient == null ||
threadRecipient.isSelf() ||
threadRecipient.isProfileSharing() ||
threadRecipient.isSystemContact() ||
threadRecipient.isForceSmsSelection() ||
!threadRecipient.isRegistered() ||
hasSentMessageInThread(context, threadId) ||
noSecureMessagesAndNoCallsInThread(context, threadId) ||
isPreMessageRequestThread(context, threadId);
hasSentMessageInThread(threadId) ||
noSecureMessagesAndNoCallsInThread(threadId) ||
isPreMessageRequestThread(threadId);
}
@WorkerThread
private static boolean isCallRequestAccepted(@NonNull Context context, @Nullable Long threadId, @NonNull Recipient threadRecipient) {
private static boolean isCallRequestAccepted(@Nullable Long threadId, @NonNull Recipient threadRecipient) {
return threadRecipient.isProfileSharing() ||
threadRecipient.isSystemContact() ||
hasSentMessageInThread(context, threadId) ||
isPreMessageRequestThread(context, threadId);
hasSentMessageInThread(threadId) ||
isPreMessageRequestThread(threadId);
}
@WorkerThread
public static boolean hasSentMessageInThread(@NonNull Context context, @Nullable Long threadId) {
public static boolean hasSentMessageInThread(@Nullable Long threadId) {
return threadId != null && SignalDatabase.mmsSms().getOutgoingSecureConversationCount(threadId) != 0;
}
@WorkerThread
private static boolean noSecureMessagesAndNoCallsInThread(@NonNull Context context, @Nullable Long threadId) {
private static boolean noSecureMessagesAndNoCallsInThread(@Nullable Long threadId) {
if (threadId == null) {
return true;
}
@ -363,7 +363,7 @@ public class RecipientUtil {
}
@WorkerThread
private static boolean isProfileSharedViaGroup(@NonNull Context context, @NonNull Recipient recipient) {
private static boolean isProfileSharedViaGroup(@NonNull Recipient recipient) {
return Stream.of(SignalDatabase.groups().getPushGroupsContainingMember(recipient.getId()))
.anyMatch(group -> Recipient.resolved(group.getRecipientId()).isProfileSharing());
}

View file

@ -170,7 +170,7 @@ final class RecipientDialogViewModel extends ViewModel {
}
void onUnblockClicked(@NonNull FragmentActivity activity) {
recipientDialogRepository.getRecipient(recipient -> BlockUnblockDialog.showUnblockFor(activity, activity.getLifecycle(), recipient, () -> RecipientUtil.unblock(context, recipient)));
recipientDialogRepository.getRecipient(recipient -> BlockUnblockDialog.showUnblockFor(activity, activity.getLifecycle(), recipient, () -> RecipientUtil.unblock(recipient)));
}
void onViewSafetyNumberClicked(@NonNull Activity activity, @NonNull IdentityRecord identityRecord) {

View file

@ -136,7 +136,7 @@ public abstract class WebRtcActionProcessor {
SignalServiceCallMessage callMessage = SignalServiceCallMessage.forOffer(offerMessage, true, destinationDeviceId);
Recipient callRecipient = currentState.getCallInfoState().getCallRecipient();
RecipientUtil.shareProfileIfFirstSecureMessage(context, callRecipient);
RecipientUtil.shareProfileIfFirstSecureMessage(callRecipient);
webRtcInteractor.sendCallMessage(callMetadata.getRemotePeer(), callMessage);
return currentState;
@ -179,7 +179,7 @@ public abstract class WebRtcActionProcessor {
return currentState;
}
if (!RecipientUtil.isCallRequestAccepted(context.getApplicationContext(), callMetadata.getRemotePeer().getRecipient())) {
if (!RecipientUtil.isCallRequestAccepted(callMetadata.getRemotePeer().getRecipient())) {
Log.w(tag, "Caller is untrusted.");
currentState = currentState.getActionProcessor().handleSendHangup(currentState, callMetadata, WebRtcData.HangupMetadata.fromType(HangupMessage.Type.NEED_PERMISSION), true);
webRtcInteractor.insertMissedCall(callMetadata.getRemotePeer(), receivedOfferMetadata.getServerReceivedTimestamp(), offerMetadata.getOfferType() == OfferMessage.Type.VIDEO_CALL);

View file

@ -217,7 +217,7 @@ public class RecipientUtilTest {
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(anyLong())).thenReturn(0);
// WHEN
RecipientUtil.shareProfileIfFirstSecureMessage(context, recipient);
RecipientUtil.shareProfileIfFirstSecureMessage(recipient);
// THEN
verify(mockRecipientDatabase).setProfileSharing(recipient.getId(), true);
@ -230,7 +230,7 @@ public class RecipientUtilTest {
when(mockMmsSmsDatabase.getOutgoingSecureConversationCount(anyLong())).thenReturn(5);
// WHEN
RecipientUtil.shareProfileIfFirstSecureMessage(context, recipient);
RecipientUtil.shareProfileIfFirstSecureMessage(recipient);
// THEN
verify(mockRecipientDatabase, never()).setProfileSharing(recipient.getId(), true);