Search in sources :

Example 1 with ProfileName

use of org.thoughtcrime.securesms.profiles.ProfileName in project Signal-Android by WhisperSystems.

the class EditSelfProfileRepository method getCurrentProfileName.

@Override
public void getCurrentProfileName(@NonNull Consumer<ProfileName> profileNameConsumer) {
    ProfileName storedProfileName = Recipient.self().getProfileName();
    if (!storedProfileName.isEmpty()) {
        profileNameConsumer.accept(storedProfileName);
    } else if (!excludeSystem) {
        SystemProfileUtil.getSystemProfileName(context).addListener(new ListenableFuture.Listener<String>() {

            @Override
            public void onSuccess(String result) {
                if (!TextUtils.isEmpty(result)) {
                    profileNameConsumer.accept(ProfileName.fromSerialized(result));
                } else {
                    profileNameConsumer.accept(storedProfileName);
                }
            }

            @Override
            public void onFailure(ExecutionException e) {
                Log.w(TAG, e);
                profileNameConsumer.accept(storedProfileName);
            }
        });
    } else {
        profileNameConsumer.accept(storedProfileName);
    }
}
Also used : ProfileName(org.thoughtcrime.securesms.profiles.ProfileName) ExecutionException(java.util.concurrent.ExecutionException)

Example 2 with ProfileName

use of org.thoughtcrime.securesms.profiles.ProfileName in project Signal-Android by WhisperSystems.

the class RetrieveProfileJob method setProfileName.

private void setProfileName(Recipient recipient, String profileName) {
    try {
        ProfileKey profileKey = ProfileKeyUtil.profileKeyOrNull(recipient.getProfileKey());
        if (profileKey == null)
            return;
        String plaintextProfileName = Util.emptyIfNull(ProfileUtil.decryptString(profileKey, profileName));
        ProfileName remoteProfileName = ProfileName.fromSerialized(plaintextProfileName);
        ProfileName localProfileName = recipient.getProfileName();
        if (!remoteProfileName.equals(localProfileName)) {
            Log.i(TAG, "Profile name updated. Writing new value.");
            SignalDatabase.recipients().setProfileName(recipient.getId(), remoteProfileName);
            String remoteDisplayName = remoteProfileName.toString();
            String localDisplayName = localProfileName.toString();
            if (!recipient.isBlocked() && !recipient.isGroup() && !recipient.isSelf() && !localDisplayName.isEmpty() && !remoteDisplayName.equals(localDisplayName)) {
                Log.i(TAG, "Writing a profile name change event for " + recipient.getId());
                SignalDatabase.sms().insertProfileNameChangeMessages(recipient, remoteDisplayName, localDisplayName);
            } else {
                Log.i(TAG, String.format(Locale.US, "Name changed, but wasn't relevant to write an event. blocked: %s, group: %s, self: %s, firstSet: %s, displayChange: %s", recipient.isBlocked(), recipient.isGroup(), recipient.isSelf(), localDisplayName.isEmpty(), !remoteDisplayName.equals(localDisplayName)));
            }
        }
        if (TextUtils.isEmpty(plaintextProfileName)) {
            Log.i(TAG, "No profile name set for " + recipient.getId());
        }
    } catch (InvalidCiphertextException e) {
        Log.w(TAG, "Bad profile key for " + recipient.getId());
    } catch (IOException e) {
        Log.w(TAG, e);
    }
}
Also used : InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) ProfileName(org.thoughtcrime.securesms.profiles.ProfileName) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 3 with ProfileName

use of org.thoughtcrime.securesms.profiles.ProfileName in project Signal-Android by WhisperSystems.

the class RefreshOwnProfileJob method setProfileName.

private void setProfileName(@Nullable String encryptedName) {
    try {
        ProfileKey profileKey = ProfileKeyUtil.getSelfProfileKey();
        String plaintextName = ProfileUtil.decryptString(profileKey, encryptedName);
        ProfileName profileName = ProfileName.fromSerialized(plaintextName);
        Log.d(TAG, "Saving " + (!Util.isEmpty(plaintextName) ? "non-" : "") + "empty name.");
        SignalDatabase.recipients().setProfileName(Recipient.self().getId(), profileName);
    } catch (InvalidCiphertextException | IOException e) {
        Log.w(TAG, e);
    }
}
Also used : InvalidCiphertextException(org.whispersystems.signalservice.api.crypto.InvalidCiphertextException) ProfileName(org.thoughtcrime.securesms.profiles.ProfileName) IOException(java.io.IOException) ProfileKey(org.signal.zkgroup.profiles.ProfileKey)

Example 4 with ProfileName

use of org.thoughtcrime.securesms.profiles.ProfileName in project Signal-Android by WhisperSystems.

the class EditProfileViewModel method submitProfile.

public void submitProfile() {
    ProfileName profileName = isGroup() ? ProfileName.EMPTY : internalProfileName.getValue();
    String displayName = isGroup() ? givenName.getValue() : "";
    String description = isGroup() ? familyName.getValue() : "";
    if (profileName == null || displayName == null) {
        return;
    }
    byte[] oldAvatar = originalAvatar.getValue();
    byte[] newAvatar = internalAvatar.getValue();
    String oldDisplayName = isGroup() ? originalDisplayName.getValue() : null;
    String oldDescription = isGroup() ? originalDescription : null;
    repository.uploadProfile(profileName, displayName, !Objects.equals(StringUtil.stripBidiProtection(oldDisplayName), displayName), description, !Objects.equals(StringUtil.stripBidiProtection(oldDescription), description), newAvatar, !Arrays.equals(oldAvatar, newAvatar), uploadResult::postValue);
}
Also used : ProfileName(org.thoughtcrime.securesms.profiles.ProfileName)

Aggregations

ProfileName (org.thoughtcrime.securesms.profiles.ProfileName)4 IOException (java.io.IOException)2 ProfileKey (org.signal.zkgroup.profiles.ProfileKey)2 InvalidCiphertextException (org.whispersystems.signalservice.api.crypto.InvalidCiphertextException)2 ExecutionException (java.util.concurrent.ExecutionException)1