mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +00:00
Enable note to self.
Fix note to self crashing.
This commit is contained in:
parent
bb0ac32540
commit
98cfd93b97
@ -107,8 +107,9 @@ public class AvatarImageView extends AppCompatImageView {
|
||||
if (w == 0 || h == 0 || recipient == null) { return; }
|
||||
|
||||
Drawable image;
|
||||
Context context = this.getContext();
|
||||
if (recipient.isGroupRecipient()) {
|
||||
Context context = this.getContext();
|
||||
|
||||
|
||||
String name = Optional.fromNullable(recipient.getName()).or(Optional.fromNullable(TextSecurePreferences.getProfileName(context))).or("");
|
||||
MaterialColor fallbackColor = recipient.getColor();
|
||||
@ -119,7 +120,12 @@ public class AvatarImageView extends AppCompatImageView {
|
||||
|
||||
image = new GeneratedContactPhoto(name, R.drawable.ic_profile_default).asDrawable(context, fallbackColor.toAvatarColor(context));
|
||||
} else {
|
||||
image = new JazzIdenticonDrawable(w, h, recipient.getAddress().serialize().toLowerCase());
|
||||
// Default to primary device image
|
||||
String ourPublicKey = TextSecurePreferences.getLocalNumber(context);
|
||||
String ourPrimaryDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
|
||||
String recipientAddress = recipient.getAddress().serialize();
|
||||
String profileAddress = (ourPrimaryDevice != null && ourPublicKey.equals(recipientAddress)) ? ourPrimaryDevice : recipientAddress;
|
||||
image = new JazzIdenticonDrawable(w, h, profileAddress.toLowerCase());
|
||||
}
|
||||
setImageDrawable(image);
|
||||
}
|
||||
|
@ -722,7 +722,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
if (isSingleConversation() && getRecipient().getContactUri() == null) {
|
||||
inflater.inflate(R.menu.conversation_add_to_contacts, menu);
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
if (recipient != null && recipient.isLocalNumber()) {
|
||||
if (isSecureText) menu.findItem(R.id.menu_call_secure).setVisible(false);
|
||||
@ -734,6 +734,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
||||
muteItem.setVisible(false);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
searchViewItem = menu.findItem(R.id.menu_search);
|
||||
|
||||
|
@ -305,6 +305,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
Optional<String> rawSenderDisplayName = content.senderDisplayName;
|
||||
if (rawSenderDisplayName.isPresent() && rawSenderDisplayName.get().length() > 0) {
|
||||
setDisplayName(envelope.getSource(), rawSenderDisplayName.get());
|
||||
|
||||
// If we got a name from our primary device then we also set that
|
||||
String ourPrimaryDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
|
||||
if (ourPrimaryDevice != null && envelope.getSource().equals(ourPrimaryDevice)) {
|
||||
TextSecurePreferences.setProfileName(context, rawSenderDisplayName.get());
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: Deleting the display name
|
||||
@ -1526,7 +1532,12 @@ public class PushDecryptJob extends BaseJob implements InjectableType {
|
||||
|
||||
// Get the primary device
|
||||
LokiStorageAPI.shared.getPrimaryDevicePublicKey(contentSender).success(primaryDevice -> {
|
||||
String publicKey = primaryDevice == null ? contentSender : primaryDevice;
|
||||
String publicKey = (primaryDevice != null) ? primaryDevice : contentSender;
|
||||
// If our the public key matches our primary device then we need to forward the message to ourselves (Note to self)
|
||||
String ourPrimaryDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
|
||||
if (ourPrimaryDevice != null && ourPrimaryDevice.equals(publicKey)) {
|
||||
publicKey = TextSecurePreferences.getLocalNumber(context);
|
||||
}
|
||||
device.set(publicKey);
|
||||
return Unit.INSTANCE;
|
||||
}).fail(exception -> {
|
||||
|
@ -58,9 +58,11 @@ fun shouldAutomaticallyBecomeFriendsWithDevice(publicKey: String, context: Conte
|
||||
val future = SettableFuture<Boolean>()
|
||||
storageAPI.getPrimaryDevicePublicKey(publicKey).success { primaryDevicePublicKey ->
|
||||
if (primaryDevicePublicKey == null) {
|
||||
// If the public key doesn't have any other devices then go through regular friend request logic
|
||||
future.set(false)
|
||||
return@success
|
||||
}
|
||||
// If we are the primary device and the public key is our secondary device then we should become friends
|
||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||
if (primaryDevicePublicKey == userHexEncodedPublicKey) {
|
||||
storageAPI.getSecondaryDevicePublicKeys(userHexEncodedPublicKey).success { secondaryDevices ->
|
||||
@ -70,6 +72,13 @@ fun shouldAutomaticallyBecomeFriendsWithDevice(publicKey: String, context: Conte
|
||||
}
|
||||
return@success
|
||||
}
|
||||
// If we share the same primary device then we should become friends
|
||||
val ourPrimaryDevice = TextSecurePreferences.getMasterHexEncodedPublicKey(context)
|
||||
if (ourPrimaryDevice != null && ourPrimaryDevice == primaryDevicePublicKey) {
|
||||
future.set(true)
|
||||
return@success
|
||||
}
|
||||
// If we are friends with the primary device then we should become friends
|
||||
val primaryDevice = Recipient.from(context, Address.fromSerialized(primaryDevicePublicKey), false)
|
||||
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdIfExistsFor(primaryDevice)
|
||||
if (threadID < 0) {
|
||||
|
@ -68,8 +68,9 @@ class NewConversationActivity : PassphraseRequiredActionBarActivity(), ScanListe
|
||||
fun startNewConversationIfPossible(hexEncodedPublicKey: String) {
|
||||
if (!PublicKeyValidation.isValid(hexEncodedPublicKey)) { return Toast.makeText(this, R.string.fragment_new_conversation_invalid_public_key_message, Toast.LENGTH_SHORT).show() }
|
||||
val userHexEncodedPublicKey = TextSecurePreferences.getLocalNumber(this)
|
||||
if (hexEncodedPublicKey == userHexEncodedPublicKey) { return Toast.makeText(this, R.string.fragment_new_conversation_note_to_self_not_supported_message, Toast.LENGTH_SHORT).show() }
|
||||
val contact = Recipient.from(this, Address.fromSerialized(hexEncodedPublicKey), true)
|
||||
// If we try to contact our master then redirect to note to self
|
||||
val contactPublicKey = if (TextSecurePreferences.getMasterHexEncodedPublicKey(this) == hexEncodedPublicKey) userHexEncodedPublicKey else hexEncodedPublicKey
|
||||
val contact = Recipient.from(this, Address.fromSerialized(contactPublicKey), true)
|
||||
val intent = Intent(this, ConversationActivity::class.java)
|
||||
intent.putExtra(ConversationActivity.ADDRESS_EXTRA, contact.address)
|
||||
intent.putExtra(ConversationActivity.TEXT_EXTRA, getIntent().getStringExtra(ConversationActivity.TEXT_EXTRA))
|
||||
|
Loading…
x
Reference in New Issue
Block a user