Search in sources :

Example 81 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class ChatWallpaperPreviewActivity method onCreate.

@Override
protected void onCreate(Bundle savedInstanceState, boolean ready) {
    dynamicTheme.onCreate(this);
    setContentView(R.layout.chat_wallpaper_preview_activity);
    adapter = new ChatWallpaperPreviewAdapter();
    colorizerView = findViewById(R.id.colorizer);
    bubble2 = findViewById(R.id.preview_bubble_2);
    viewPager = findViewById(R.id.preview_pager);
    View submit = findViewById(R.id.preview_set_wallpaper);
    ChatWallpaperRepository repository = new ChatWallpaperRepository();
    ChatWallpaper selected = getIntent().getParcelableExtra(EXTRA_CHAT_WALLPAPER);
    boolean dim = getIntent().getBooleanExtra(EXTRA_DIM_IN_DARK_MODE, false);
    Toolbar toolbar = findViewById(R.id.toolbar);
    TextView bubble2Text = findViewById(R.id.preview_bubble_2_text);
    toolbar.setNavigationOnClickListener(unused -> {
        finish();
    });
    viewPager.setAdapter(adapter);
    adapter.submitList(Collections.singletonList(new ChatWallpaperSelectionMappingModel(selected)));
    repository.getAllWallpaper(wallpapers -> adapter.submitList(Stream.of(wallpapers).map(wallpaper -> ChatWallpaperFactory.updateWithDimming(wallpaper, dim ? ChatWallpaper.FIXED_DIM_LEVEL_FOR_DARK_THEME : 0f)).<MappingModel<?>>map(ChatWallpaperSelectionMappingModel::new).toList()));
    submit.setOnClickListener(unused -> {
        ChatWallpaperSelectionMappingModel model = (ChatWallpaperSelectionMappingModel) adapter.getCurrentList().get(viewPager.getCurrentItem());
        setResult(RESULT_OK, new Intent().putExtra(EXTRA_CHAT_WALLPAPER, model.getWallpaper()));
        finish();
    });
    RecipientId recipientId = getIntent().getParcelableExtra(EXTRA_RECIPIENT_ID);
    final ChatColors chatColors;
    if (recipientId != null && Recipient.live(recipientId).get().hasOwnChatColors()) {
        Recipient recipient = Recipient.live(recipientId).get();
        bubble2Text.setText(getString(R.string.ChatWallpaperPreviewActivity__set_wallpaper_for_s, recipient.getDisplayName(this)));
        chatColors = recipient.getChatColors();
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else if (SignalStore.chatColorsValues().hasChatColors()) {
        chatColors = Objects.requireNonNull(SignalStore.chatColorsValues().getChatColors());
        bubble2.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
            updateChatColors(chatColors);
        });
    } else {
        onPageChanged = new OnPageChanged();
        viewPager.registerOnPageChangeCallback(onPageChanged);
        bubble2.addOnLayoutChangeListener(new UpdateChatColorsOnNextLayoutChange(selected.getAutoChatColors()));
    }
    new FullscreenHelper(this).showSystemUI();
    WindowUtil.setLightStatusBarFromTheme(this);
    WindowUtil.setLightNavigationBarFromTheme(this);
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) Context(android.content.Context) Bundle(android.os.Bundle) Stream(com.annimon.stream.Stream) NonNull(androidx.annotation.NonNull) Intent(android.content.Intent) ViewPager2(androidx.viewpager2.widget.ViewPager2) ViewUtil(org.thoughtcrime.securesms.util.ViewUtil) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Drawable(android.graphics.drawable.Drawable) R(org.thoughtcrime.securesms.R) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) View(android.view.View) Recipient(org.thoughtcrime.securesms.recipients.Recipient) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) MappingModel(org.thoughtcrime.securesms.util.adapter.mapping.MappingModel) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) Objects(java.util.Objects) TextView(android.widget.TextView) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) Toolbar(androidx.appcompat.widget.Toolbar) Projection(org.thoughtcrime.securesms.util.Projection) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) ChatColors(org.thoughtcrime.securesms.conversation.colors.ChatColors) Intent(android.content.Intent) Recipient(org.thoughtcrime.securesms.recipients.Recipient) ColorizerView(org.thoughtcrime.securesms.conversation.colors.ColorizerView) View(android.view.View) TextView(android.widget.TextView) TextView(android.widget.TextView) FullscreenHelper(org.thoughtcrime.securesms.util.FullscreenHelper) Toolbar(androidx.appcompat.widget.Toolbar)

Example 82 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class MarkReadReceiverTest method givenMultipleThreadsWithMultipleMessagesEach_whenIProcess_thenIProperlyGroupByThreadAndRecipient.

@Test
public void givenMultipleThreadsWithMultipleMessagesEach_whenIProcess_thenIProperlyGroupByThreadAndRecipient() {
    // GIVEN
    List<RecipientId> recipients = Stream.range(1L, 4L).map(RecipientId::from).toList();
    List<Long> threads = Stream.range(4L, 7L).toList();
    int expected = recipients.size() * threads.size() + 1;
    List<MessageDatabase.MarkedMessageInfo> infoList = Stream.of(threads).flatMap(threadId -> Stream.of(recipients).map(recipientId -> createMarkedMessageInfo(threadId, recipientId))).toList();
    List<MessageDatabase.MarkedMessageInfo> duplicatedList = Util.concatenatedList(infoList, infoList);
    // WHEN
    MarkReadReceiver.process(mockContext, duplicatedList);
    // THEN
    assertEquals("Should have 10 total jobs, including MultiDeviceReadUpdateJob", expected, jobs.size());
    Set<Pair<Long, String>> threadRecipientPairs = new HashSet<>();
    Stream.of(jobs).forEach(job -> {
        if (job instanceof MultiDeviceReadUpdateJob) {
            return;
        }
        Data data = job.serialize();
        long threadId = data.getLong("thread");
        String recipientId = data.getString("recipient");
        long[] messageIds = data.getLongArray("message_ids");
        assertEquals("Each job should contain two messages.", 2, messageIds.length);
        assertTrue("Each thread recipient pair should only exist once.", threadRecipientPairs.add(new Pair<>(threadId, recipientId)));
    });
    assertEquals("Should have 9 total combinations.", 9, threadRecipientPairs.size());
}
Also used : Context(android.content.Context) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) PowerMockito.mockStatic(org.powermock.api.mockito.PowerMockito.mockStatic) NonNull(androidx.annotation.NonNull) Data(org.thoughtcrime.securesms.jobmanager.Data) JobManager(org.thoughtcrime.securesms.jobmanager.JobManager) RunWith(org.junit.runner.RunWith) HashSet(java.util.HashSet) Answer(org.mockito.stubbing.Answer) Pair(org.whispersystems.libsignal.util.Pair) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Recipient(org.thoughtcrime.securesms.recipients.Recipient) PowerMockRunner(org.powermock.modules.junit4.PowerMockRunner) LinkedList(java.util.LinkedList) Before(org.junit.Before) MessageId(org.thoughtcrime.securesms.database.model.MessageId) PowerMockito.when(org.powermock.api.mockito.PowerMockito.when) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Set(java.util.Set) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Matchers.any(org.mockito.Matchers.any) List(java.util.List) PowerMockito.mock(org.powermock.api.mockito.PowerMockito.mock) MultiDeviceReadUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob) PowerMockito.doAnswer(org.powermock.api.mockito.PowerMockito.doAnswer) Job(org.thoughtcrime.securesms.jobmanager.Job) MessageDatabase(org.thoughtcrime.securesms.database.MessageDatabase) Assert.assertEquals(org.junit.Assert.assertEquals) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) Data(org.thoughtcrime.securesms.jobmanager.Data) MultiDeviceReadUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceReadUpdateJob) Pair(org.whispersystems.libsignal.util.Pair) HashSet(java.util.HashSet) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 83 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class DirectoryHelper method filterForUnlistedUsers.

/**
 * Users can mark themselves as 'unlisted' in CDS, meaning that even if CDS says they're
 * unregistered, they might actually be registered. We need to double-check users who we already
 * have UUIDs for. Also, we only want to bother doing this for users we have conversations for,
 * so we will also only check for users that have a thread.
 */
private static UnlistedResult filterForUnlistedUsers(@NonNull Context context, @NonNull Set<RecipientId> inactiveIds) {
    List<Recipient> possiblyUnlisted = Stream.of(inactiveIds).map(Recipient::resolved).filter(Recipient::isRegistered).filter(Recipient::hasServiceId).filter(DirectoryHelper::hasCommunicatedWith).toList();
    ProfileService profileService = new ProfileService(ApplicationDependencies.getGroupsV2Operations().getProfileOperations(), ApplicationDependencies.getSignalServiceMessageReceiver(), ApplicationDependencies.getSignalWebSocket());
    List<Observable<Pair<Recipient, ServiceResponse<ProfileAndCredential>>>> requests = Stream.of(possiblyUnlisted).map(r -> ProfileUtil.retrieveProfile(context, r, SignalServiceProfile.RequestType.PROFILE, profileService).toObservable().timeout(5, TimeUnit.SECONDS).onErrorReturn(t -> new Pair<>(r, ServiceResponse.forUnknownError(t)))).toList();
    return Observable.mergeDelayError(requests).observeOn(Schedulers.io(), true).scan(new UnlistedResult.Builder(), (builder, pair) -> {
        Recipient recipient = pair.first();
        ProfileService.ProfileResponseProcessor processor = new ProfileService.ProfileResponseProcessor(pair.second());
        if (processor.hasResult()) {
            builder.potentiallyActiveIds.add(recipient.getId());
        } else if (processor.genericIoError() || !processor.notFound()) {
            builder.retries.add(recipient.getId());
            builder.potentiallyActiveIds.add(recipient.getId());
        }
        return builder;
    }).lastOrError().map(UnlistedResult.Builder::build).blockingGet();
}
Also used : SignalStore(org.thoughtcrime.securesms.keyvalue.SignalStore) NonNull(androidx.annotation.NonNull) R(org.thoughtcrime.securesms.R) SignalServiceAddress(org.whispersystems.signalservice.api.push.SignalServiceAddress) Manifest(android.Manifest) ProfileAndCredential(org.whispersystems.signalservice.api.profiles.ProfileAndCredential) ContactsContract(android.provider.ContactsContract) BulkOperationsHandle(org.thoughtcrime.securesms.database.RecipientDatabase.BulkOperationsHandle) RegisteredState(org.thoughtcrime.securesms.database.RecipientDatabase.RegisteredState) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) StorageSyncHelper(org.thoughtcrime.securesms.storage.StorageSyncHelper) ContentResolver(android.content.ContentResolver) Map(java.util.Map) SignalProtocolAddress(org.whispersystems.libsignal.SignalProtocolAddress) Recipient(org.thoughtcrime.securesms.recipients.Recipient) AccountManager(android.accounts.AccountManager) ACI(org.whispersystems.signalservice.api.push.ACI) Account(android.accounts.Account) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) Collection(java.util.Collection) Set(java.util.Set) SetUtil(org.thoughtcrime.securesms.util.SetUtil) Objects(java.util.Objects) Log(org.signal.core.util.logging.Log) FeatureFlags(org.thoughtcrime.securesms.util.FeatureFlags) List(java.util.List) Nullable(androidx.annotation.Nullable) StorageSyncJob(org.thoughtcrime.securesms.jobs.StorageSyncJob) ProfileService(org.whispersystems.signalservice.api.services.ProfileService) BuildConfig(org.thoughtcrime.securesms.BuildConfig) InsertResult(org.thoughtcrime.securesms.database.MessageDatabase.InsertResult) Context(android.content.Context) SignalDatabase(org.thoughtcrime.securesms.database.SignalDatabase) Stream(com.annimon.stream.Stream) Util(org.thoughtcrime.securesms.util.Util) WorkerThread(androidx.annotation.WorkerThread) RemoteException(android.os.RemoteException) RetrieveProfileJob(org.thoughtcrime.securesms.jobs.RetrieveProfileJob) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) SignalServiceProfile(org.whispersystems.signalservice.api.profiles.SignalServiceProfile) TextSecurePreferences(org.thoughtcrime.securesms.util.TextSecurePreferences) HashSet(java.util.HashSet) Schedulers(io.reactivex.rxjava3.schedulers.Schedulers) Pair(org.whispersystems.libsignal.util.Pair) NotificationChannels(org.thoughtcrime.securesms.notifications.NotificationChannels) ProfileUtil(org.thoughtcrime.securesms.util.ProfileUtil) Calendar(java.util.Calendar) Observable(io.reactivex.rxjava3.core.Observable) RegistrationUtil(org.thoughtcrime.securesms.registration.RegistrationUtil) ContactsDatabase(org.thoughtcrime.securesms.contacts.ContactsDatabase) MultiDeviceContactUpdateJob(org.thoughtcrime.securesms.jobs.MultiDeviceContactUpdateJob) Cursor(android.database.Cursor) Collectors(com.annimon.stream.Collectors) Permissions(org.thoughtcrime.securesms.permissions.Permissions) UuidUtil(org.whispersystems.signalservice.api.util.UuidUtil) TextUtils(android.text.TextUtils) IOException(java.io.IOException) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) OperationApplicationException(android.content.OperationApplicationException) Optional(org.whispersystems.libsignal.util.guava.Optional) TimeUnit(java.util.concurrent.TimeUnit) CursorUtil(org.thoughtcrime.securesms.util.CursorUtil) IncomingJoinedMessage(org.thoughtcrime.securesms.sms.IncomingJoinedMessage) ContactAccessor(org.thoughtcrime.securesms.contacts.ContactAccessor) Stopwatch(org.thoughtcrime.securesms.util.Stopwatch) PhoneNumberFormatter(org.thoughtcrime.securesms.phonenumbers.PhoneNumberFormatter) Collections(java.util.Collections) ServiceResponse(org.whispersystems.signalservice.internal.ServiceResponse) ProfileService(org.whispersystems.signalservice.api.services.ProfileService) Recipient(org.thoughtcrime.securesms.recipients.Recipient) Observable(io.reactivex.rxjava3.core.Observable)

Example 84 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class ContactSelectionListAdapter method onBindItemViewHolder.

@Override
protected void onBindItemViewHolder(ViewHolder viewHolder, @NonNull Cursor cursor, @NonNull List<Object> payloads) {
    if (!arePayloadsValid(payloads)) {
        throw new AssertionError();
    }
    String rawId = CursorUtil.requireString(cursor, ContactRepository.ID_COLUMN);
    RecipientId id = rawId != null ? RecipientId.from(rawId) : null;
    int numberType = CursorUtil.requireInt(cursor, ContactRepository.NUMBER_TYPE_COLUMN);
    String number = CursorUtil.requireString(cursor, ContactRepository.NUMBER_COLUMN);
    viewHolder.setEnabled(true);
    if (currentContacts.contains(id)) {
        viewHolder.animateChecked(true);
        viewHolder.setEnabled(false);
    } else if (numberType == ContactRepository.NEW_USERNAME_TYPE) {
        viewHolder.animateChecked(selectedContacts.contains(SelectedContact.forUsername(id, number)));
    } else {
        viewHolder.animateChecked(selectedContacts.contains(SelectedContact.forPhone(id, number)));
    }
}
Also used : RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) SpannableString(android.text.SpannableString)

Example 85 with RecipientId

use of org.thoughtcrime.securesms.recipients.RecipientId in project Signal-Android by WhisperSystems.

the class SharedContactDetailsActivity method presentActionButtons.

private void presentActionButtons(@NonNull List<RecipientId> recipients) {
    for (RecipientId recipientId : recipients) {
        activeRecipients.put(recipientId, Recipient.live(recipientId));
    }
    List<Recipient> pushUsers = new ArrayList<>(recipients.size());
    List<Recipient> systemUsers = new ArrayList<>(recipients.size());
    for (LiveRecipient recipient : activeRecipients.values()) {
        if (recipient.get().getRegistered() == RecipientDatabase.RegisteredState.REGISTERED) {
            pushUsers.add(recipient.get());
        } else if (recipient.get().isSystemContact()) {
            systemUsers.add(recipient.get());
        }
    }
    if (!pushUsers.isEmpty()) {
        engageContainerView.setVisibility(View.VISIBLE);
        inviteButtonView.setVisibility(View.GONE);
        messageButtonView.setOnClickListener(v -> {
            ContactUtil.selectRecipientThroughDialog(this, pushUsers, dynamicLanguage.getCurrentLocale(), recipient -> {
                CommunicationActions.startConversation(this, recipient, null);
            });
        });
        callButtonView.setOnClickListener(v -> {
            ContactUtil.selectRecipientThroughDialog(this, pushUsers, dynamicLanguage.getCurrentLocale(), recipient -> CommunicationActions.startVoiceCall(this, recipient));
        });
    } else if (!systemUsers.isEmpty()) {
        inviteButtonView.setVisibility(View.VISIBLE);
        engageContainerView.setVisibility(View.GONE);
        inviteButtonView.setOnClickListener(v -> {
            ContactUtil.selectRecipientThroughDialog(this, systemUsers, dynamicLanguage.getCurrentLocale(), recipient -> {
                CommunicationActions.composeSmsThroughDefaultApp(this, recipient, getString(R.string.InviteActivity_lets_switch_to_signal, getString(R.string.install_url)));
            });
        });
    } else {
        inviteButtonView.setVisibility(View.GONE);
        engageContainerView.setVisibility(View.GONE);
    }
}
Also used : Context(android.content.Context) Bundle(android.os.Bundle) NonNull(androidx.annotation.NonNull) DynamicLanguage(org.thoughtcrime.securesms.util.DynamicLanguage) Uri(android.net.Uri) ImageView(android.widget.ImageView) Intent(android.content.Intent) HashMap(java.util.HashMap) R(org.thoughtcrime.securesms.R) RecipientDatabase(org.thoughtcrime.securesms.database.RecipientDatabase) ArrayList(java.util.ArrayList) DynamicTheme(org.thoughtcrime.securesms.util.DynamicTheme) SuppressLint(android.annotation.SuppressLint) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) DiskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy) Map(java.util.Map) View(android.view.View) Recipient(org.thoughtcrime.securesms.recipients.Recipient) RecyclerView(androidx.recyclerview.widget.RecyclerView) ContextCompat(androidx.core.content.ContextCompat) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) DirectoryRefreshJob(org.thoughtcrime.securesms.jobs.DirectoryRefreshJob) AsyncTask(android.os.AsyncTask) ApplicationDependencies(org.thoughtcrime.securesms.dependencies.ApplicationDependencies) CommunicationActions(org.thoughtcrime.securesms.util.CommunicationActions) ViewGroup(android.view.ViewGroup) WindowUtil(org.thoughtcrime.securesms.util.WindowUtil) List(java.util.List) TextView(android.widget.TextView) Nullable(androidx.annotation.Nullable) PassphraseRequiredActivity(org.thoughtcrime.securesms.PassphraseRequiredActivity) DynamicNoActionBarTheme(org.thoughtcrime.securesms.util.DynamicNoActionBarTheme) DecryptableUri(org.thoughtcrime.securesms.mms.DecryptableStreamUriLoader.DecryptableUri) Toolbar(androidx.appcompat.widget.Toolbar) GlideRequests(org.thoughtcrime.securesms.mms.GlideRequests) LinearLayoutManager(androidx.recyclerview.widget.LinearLayoutManager) GlideApp(org.thoughtcrime.securesms.mms.GlideApp) Collections(java.util.Collections) RecipientId(org.thoughtcrime.securesms.recipients.RecipientId) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient) ArrayList(java.util.ArrayList) Recipient(org.thoughtcrime.securesms.recipients.Recipient) LiveRecipient(org.thoughtcrime.securesms.recipients.LiveRecipient)

Aggregations

RecipientId (org.thoughtcrime.securesms.recipients.RecipientId)154 NonNull (androidx.annotation.NonNull)70 Recipient (org.thoughtcrime.securesms.recipients.Recipient)70 List (java.util.List)34 ArrayList (java.util.ArrayList)33 Nullable (androidx.annotation.Nullable)32 Context (android.content.Context)31 Log (org.signal.core.util.logging.Log)31 IOException (java.io.IOException)30 ApplicationDependencies (org.thoughtcrime.securesms.dependencies.ApplicationDependencies)29 WorkerThread (androidx.annotation.WorkerThread)28 Stream (com.annimon.stream.Stream)27 LinkedList (java.util.LinkedList)25 ContentValues (android.content.ContentValues)24 Cursor (android.database.Cursor)24 Collections (java.util.Collections)24 SignalDatabase (org.thoughtcrime.securesms.database.SignalDatabase)24 GroupDatabase (org.thoughtcrime.securesms.database.GroupDatabase)23 Optional (org.whispersystems.libsignal.util.guava.Optional)22 HashSet (java.util.HashSet)21