mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 21:43:38 +00:00
Fix group ID handling
This commit is contained in:
parent
bbc7acfcaf
commit
2f0135a413
@ -1171,7 +1171,7 @@ public class ConversationActivity extends PassphraseRequiredActionBarActivity
|
|||||||
String groupPublicKey;
|
String groupPublicKey;
|
||||||
boolean isSSKBasedClosedGroup;
|
boolean isSSKBasedClosedGroup;
|
||||||
try {
|
try {
|
||||||
groupPublicKey = HexEncodingKt.toHexString(GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupRecipient.getAddress().toString())));
|
groupPublicKey = HexEncodingKt.toHexString(GroupUtil.getDecodedId(groupRecipient.getAddress().toString()));
|
||||||
isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey);
|
isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
groupPublicKey = null;
|
groupPublicKey = null;
|
||||||
|
@ -335,7 +335,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
|||||||
val isClosedGroup = recipient.address.isClosedGroup
|
val isClosedGroup = recipient.address.isClosedGroup
|
||||||
// Send a leave group message if this is an active closed group
|
// Send a leave group message if this is an active closed group
|
||||||
if (isClosedGroup && DatabaseFactory.getGroupDatabase(this).isActive(recipient.address.toGroupString())) {
|
if (isClosedGroup && DatabaseFactory.getGroupDatabase(this).isActive(recipient.address.toGroupString())) {
|
||||||
val groupPublicKey = GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(recipient.address.toString())).toHexString()
|
val groupPublicKey = GroupUtil.getDecodedId(recipient.address.toString()).toHexString()
|
||||||
val isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey)
|
val isSSKBasedClosedGroup = DatabaseFactory.getSSKDatabase(this).isSSKBasedClosedGroup(groupPublicKey)
|
||||||
if (isSSKBasedClosedGroup) {
|
if (isSSKBasedClosedGroup) {
|
||||||
ClosedGroupsProtocol.leave(this, groupPublicKey)
|
ClosedGroupsProtocol.leave(this, groupPublicKey)
|
||||||
|
@ -45,7 +45,7 @@ object ClosedGroupsProtocol {
|
|||||||
ClosedGroupSenderKey(Hex.fromStringCondensed(ratchet.chainKey), ratchet.keyIndex, Hex.fromStringCondensed(publicKey))
|
ClosedGroupSenderKey(Hex.fromStringCondensed(ratchet.chainKey), ratchet.keyIndex, Hex.fromStringCondensed(publicKey))
|
||||||
}
|
}
|
||||||
// Create the group
|
// Create the group
|
||||||
val groupID = GroupUtil.getEncodedId(GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false).toByteArray(), false) // Signal double encodes the group ID
|
val groupID = GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false)
|
||||||
val admins = setOf( userPublicKey )
|
val admins = setOf( userPublicKey )
|
||||||
DatabaseFactory.getGroupDatabase(context).create(groupID, name, LinkedList<Address>(members.map { Address.fromSerialized(it) }),
|
DatabaseFactory.getGroupDatabase(context).create(groupID, name, LinkedList<Address>(members.map { Address.fromSerialized(it) }),
|
||||||
null, null, LinkedList<Address>(admins.map { Address.fromSerialized(it) }))
|
null, null, LinkedList<Address>(admins.map { Address.fromSerialized(it) }))
|
||||||
@ -74,7 +74,7 @@ object ClosedGroupsProtocol {
|
|||||||
// Prepare
|
// Prepare
|
||||||
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
||||||
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
||||||
val groupID = GroupUtil.getEncodedId(GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false).toByteArray(), false) // Signal double encodes the group ID
|
val groupID = GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false)
|
||||||
val group = groupDB.getGroup(groupID).orNull()
|
val group = groupDB.getGroup(groupID).orNull()
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
Log.d("Loki", "Can't add users to nonexistent closed group.")
|
Log.d("Loki", "Can't add users to nonexistent closed group.")
|
||||||
@ -136,7 +136,7 @@ object ClosedGroupsProtocol {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
||||||
val groupID = GroupUtil.getEncodedId(GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false).toByteArray(), false) // Signal double encodes the group ID
|
val groupID = GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false)
|
||||||
val group = groupDB.getGroup(groupID).orNull()
|
val group = groupDB.getGroup(groupID).orNull()
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
Log.d("Loki", "Can't add users to nonexistent closed group.")
|
Log.d("Loki", "Can't add users to nonexistent closed group.")
|
||||||
@ -241,7 +241,7 @@ object ClosedGroupsProtocol {
|
|||||||
sskDatabase.setClosedGroupRatchet(groupPublicKey, senderKey.publicKey.toHexString(), ratchet)
|
sskDatabase.setClosedGroupRatchet(groupPublicKey, senderKey.publicKey.toHexString(), ratchet)
|
||||||
}
|
}
|
||||||
// Create the group
|
// Create the group
|
||||||
val groupID = GroupUtil.getEncodedId(GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false).toByteArray(), false) // Signal double encodes the group ID
|
val groupID = GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false)
|
||||||
DatabaseFactory.getGroupDatabase(context).create(groupID, name, LinkedList<Address>(members.map { Address.fromSerialized(it) }),
|
DatabaseFactory.getGroupDatabase(context).create(groupID, name, LinkedList<Address>(members.map { Address.fromSerialized(it) }),
|
||||||
null, null, LinkedList<Address>(admins.map { Address.fromSerialized(it) }))
|
null, null, LinkedList<Address>(admins.map { Address.fromSerialized(it) }))
|
||||||
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(Recipient.from(context, Address.fromSerialized(groupID), false), true)
|
DatabaseFactory.getRecipientDatabase(context).setProfileSharing(Recipient.from(context, Address.fromSerialized(groupID), false), true)
|
||||||
@ -267,7 +267,7 @@ object ClosedGroupsProtocol {
|
|||||||
val members = closedGroupUpdate.membersList.map { it.toByteArray().toHexString() }
|
val members = closedGroupUpdate.membersList.map { it.toByteArray().toHexString() }
|
||||||
val admins = closedGroupUpdate.adminsList.map { it.toByteArray().toHexString() }
|
val admins = closedGroupUpdate.adminsList.map { it.toByteArray().toHexString() }
|
||||||
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
||||||
val groupID = GroupUtil.getEncodedId(GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false).toByteArray(), false) // Signal double encodes the group ID
|
val groupID = GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false)
|
||||||
val group = groupDB.getGroup(groupID).orNull()
|
val group = groupDB.getGroup(groupID).orNull()
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
Log.d("Loki", "Ignoring closed group info message for nonexistent group.")
|
Log.d("Loki", "Ignoring closed group info message for nonexistent group.")
|
||||||
@ -319,7 +319,7 @@ object ClosedGroupsProtocol {
|
|||||||
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
||||||
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
||||||
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
||||||
val groupID = GroupUtil.getEncodedId(GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false).toByteArray(), false) // Signal double encodes the group ID
|
val groupID = GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false)
|
||||||
val group = groupDB.getGroup(groupID).orNull()
|
val group = groupDB.getGroup(groupID).orNull()
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
Log.d("Loki", "Ignoring closed group sender key request for nonexistent group.")
|
Log.d("Loki", "Ignoring closed group sender key request for nonexistent group.")
|
||||||
@ -344,7 +344,7 @@ object ClosedGroupsProtocol {
|
|||||||
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
||||||
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
||||||
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
val groupDB = DatabaseFactory.getGroupDatabase(context)
|
||||||
val groupID = GroupUtil.getEncodedId(GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false).toByteArray(), false) // Signal double encodes the group ID
|
val groupID = GroupUtil.getEncodedId(Hex.fromStringCondensed(groupPublicKey), false)
|
||||||
val group = groupDB.getGroup(groupID).orNull()
|
val group = groupDB.getGroup(groupID).orNull()
|
||||||
if (group == null) {
|
if (group == null) {
|
||||||
Log.d("Loki", "Ignoring closed group sender key for nonexistent group.")
|
Log.d("Loki", "Ignoring closed group sender key for nonexistent group.")
|
||||||
@ -388,7 +388,7 @@ object ClosedGroupsProtocol {
|
|||||||
if (GroupUtil.isOpenGroup(groupID)) {
|
if (GroupUtil.isOpenGroup(groupID)) {
|
||||||
return listOf( Address.fromSerialized(groupID) )
|
return listOf( Address.fromSerialized(groupID) )
|
||||||
} else {
|
} else {
|
||||||
val groupPublicKey = GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupID)).toHexString()
|
val groupPublicKey = GroupUtil.getDecodedId(groupID).toHexString()
|
||||||
if (DatabaseFactory.getSSKDatabase(context).isSSKBasedClosedGroup(groupPublicKey)) {
|
if (DatabaseFactory.getSSKDatabase(context).isSSKBasedClosedGroup(groupPublicKey)) {
|
||||||
return listOf( Address.fromSerialized(groupPublicKey) )
|
return listOf( Address.fromSerialized(groupPublicKey) )
|
||||||
} else {
|
} else {
|
||||||
@ -455,14 +455,13 @@ object ClosedGroupsProtocol {
|
|||||||
|
|
||||||
private fun insertIncomingInfoMessage(context: Context, groupID: String, type0: GroupContext.Type, type1: SignalServiceGroup.Type, name: String,
|
private fun insertIncomingInfoMessage(context: Context, groupID: String, type0: GroupContext.Type, type1: SignalServiceGroup.Type, name: String,
|
||||||
members: Collection<String>, admins: Collection<String>, threadID: Long) {
|
members: Collection<String>, admins: Collection<String>, threadID: Long) {
|
||||||
val recipient = Recipient.from(context, Address.fromSerialized(groupID), false)
|
|
||||||
val groupContextBuilder = GroupContext.newBuilder()
|
val groupContextBuilder = GroupContext.newBuilder()
|
||||||
.setId(ByteString.copyFrom(GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupID))))
|
.setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupID)))
|
||||||
.setType(type0)
|
.setType(type0)
|
||||||
.setName(name)
|
.setName(name)
|
||||||
.addAllMembers(members)
|
.addAllMembers(members)
|
||||||
.addAllAdmins(admins)
|
.addAllAdmins(admins)
|
||||||
val group = SignalServiceGroup(type1, GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupID)), GroupType.SIGNAL, name, members.toList(), null, admins.toList())
|
val group = SignalServiceGroup(type1, GroupUtil.getDecodedId(groupID), GroupType.SIGNAL, name, members.toList(), null, admins.toList())
|
||||||
val m = IncomingTextMessage(Address.fromSerialized(groupID), 1, System.currentTimeMillis(), "", Optional.of(group), 0, true)
|
val m = IncomingTextMessage(Address.fromSerialized(groupID), 1, System.currentTimeMillis(), "", Optional.of(group), 0, true)
|
||||||
val infoMessage = IncomingGroupMessage(m, groupContextBuilder.build(), "")
|
val infoMessage = IncomingGroupMessage(m, groupContextBuilder.build(), "")
|
||||||
val smsDB = DatabaseFactory.getSmsDatabase(context)
|
val smsDB = DatabaseFactory.getSmsDatabase(context)
|
||||||
@ -473,7 +472,7 @@ object ClosedGroupsProtocol {
|
|||||||
members: Collection<String>, admins: Collection<String>, threadID: Long) {
|
members: Collection<String>, admins: Collection<String>, threadID: Long) {
|
||||||
val recipient = Recipient.from(context, Address.fromSerialized(groupID), false)
|
val recipient = Recipient.from(context, Address.fromSerialized(groupID), false)
|
||||||
val groupContextBuilder = GroupContext.newBuilder()
|
val groupContextBuilder = GroupContext.newBuilder()
|
||||||
.setId(ByteString.copyFrom(GroupUtil.getDecodedId(GroupUtil.getDecodedStringId(groupID))))
|
.setId(ByteString.copyFrom(GroupUtil.getDecodedId(groupID)))
|
||||||
.setType(type)
|
.setType(type)
|
||||||
.setName(name)
|
.setName(name)
|
||||||
.addAllMembers(members)
|
.addAllMembers(members)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user