|
|
@ -8,6 +8,8 @@ import nl.komponents.kovenant.deferred
|
|
|
|
import org.thoughtcrime.securesms.ApplicationContext
|
|
|
|
import org.thoughtcrime.securesms.ApplicationContext
|
|
|
|
import org.thoughtcrime.securesms.database.Address
|
|
|
|
import org.thoughtcrime.securesms.database.Address
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
|
|
|
import org.thoughtcrime.securesms.database.DatabaseFactory
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.loki.api.ClosedGroupSubscribeJob
|
|
|
|
|
|
|
|
import org.thoughtcrime.securesms.loki.api.LokiPushNotificationManager
|
|
|
|
import org.thoughtcrime.securesms.loki.utilities.recipient
|
|
|
|
import org.thoughtcrime.securesms.loki.utilities.recipient
|
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage
|
|
|
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient
|
|
|
|
import org.thoughtcrime.securesms.recipients.Recipient
|
|
|
@ -33,7 +35,7 @@ import java.io.IOException
|
|
|
|
import java.util.*
|
|
|
|
import java.util.*
|
|
|
|
|
|
|
|
|
|
|
|
object ClosedGroupsProtocol {
|
|
|
|
object ClosedGroupsProtocol {
|
|
|
|
val isSharedSenderKeysEnabled = false
|
|
|
|
val isSharedSenderKeysEnabled = true
|
|
|
|
val groupSizeLimit = 10
|
|
|
|
val groupSizeLimit = 10
|
|
|
|
|
|
|
|
|
|
|
|
public fun createClosedGroup(context: Context, name: String, members: Collection<String>): Promise<String, Exception> {
|
|
|
|
public fun createClosedGroup(context: Context, name: String, members: Collection<String>): Promise<String, Exception> {
|
|
|
@ -70,6 +72,10 @@ object ClosedGroupsProtocol {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Add the group to the user's set of public keys to poll for
|
|
|
|
// Add the group to the user's set of public keys to poll for
|
|
|
|
DatabaseFactory.getSSKDatabase(context).setClosedGroupPrivateKey(groupPublicKey, groupKeyPair.hexEncodedPrivateKey)
|
|
|
|
DatabaseFactory.getSSKDatabase(context).setClosedGroupPrivateKey(groupPublicKey, groupKeyPair.hexEncodedPrivateKey)
|
|
|
|
|
|
|
|
// Notify PN server
|
|
|
|
|
|
|
|
val jobForPN = ClosedGroupSubscribeJob(groupPublicKey)
|
|
|
|
|
|
|
|
jobForPN.setContext(context)
|
|
|
|
|
|
|
|
jobForPN.onRun()
|
|
|
|
// Notify the user
|
|
|
|
// Notify the user
|
|
|
|
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(Recipient.from(context, Address.fromSerialized(groupID), false))
|
|
|
|
val threadID = DatabaseFactory.getThreadDatabase(context).getThreadIdFor(Recipient.from(context, Address.fromSerialized(groupID), false))
|
|
|
|
insertOutgoingInfoMessage(context, groupID, GroupContext.Type.UPDATE, name, members, admins, threadID)
|
|
|
|
insertOutgoingInfoMessage(context, groupID, GroupContext.Type.UPDATE, name, members, admins, threadID)
|
|
|
@ -137,6 +143,8 @@ object ClosedGroupsProtocol {
|
|
|
|
sskDatabase.removeClosedGroupPrivateKey(groupPublicKey)
|
|
|
|
sskDatabase.removeClosedGroupPrivateKey(groupPublicKey)
|
|
|
|
groupDB.setActive(groupID, false)
|
|
|
|
groupDB.setActive(groupID, false)
|
|
|
|
groupDB.remove(groupID, Address.fromSerialized(userPublicKey))
|
|
|
|
groupDB.remove(groupID, Address.fromSerialized(userPublicKey))
|
|
|
|
|
|
|
|
// Notify PN server
|
|
|
|
|
|
|
|
LokiPushNotificationManager.operateClosedGroup(groupPublicKey, userPublicKey, context, LokiPushNotificationManager.unsubscribe)
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
// Establish sessions if needed
|
|
|
|
// Establish sessions if needed
|
|
|
|
establishSessionsWithMembersIfNeeded(context, members)
|
|
|
|
establishSessionsWithMembersIfNeeded(context, members)
|
|
|
@ -231,6 +239,7 @@ object ClosedGroupsProtocol {
|
|
|
|
|
|
|
|
|
|
|
|
public fun handleNewClosedGroup(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|
public fun handleNewClosedGroup(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|
// Prepare
|
|
|
|
// Prepare
|
|
|
|
|
|
|
|
val userPublicKey = TextSecurePreferences.getLocalNumber(context)
|
|
|
|
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
|
|
|
val sskDatabase = DatabaseFactory.getSSKDatabase(context)
|
|
|
|
// Unwrap the message
|
|
|
|
// Unwrap the message
|
|
|
|
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
|
|
|
val groupPublicKey = closedGroupUpdate.groupPublicKey.toByteArray().toHexString()
|
|
|
@ -258,6 +267,8 @@ object ClosedGroupsProtocol {
|
|
|
|
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.UPDATE, name, members, admins)
|
|
|
|
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.UPDATE, name, members, admins)
|
|
|
|
// Establish sessions if needed
|
|
|
|
// Establish sessions if needed
|
|
|
|
establishSessionsWithMembersIfNeeded(context, members)
|
|
|
|
establishSessionsWithMembersIfNeeded(context, members)
|
|
|
|
|
|
|
|
// Notify PN server
|
|
|
|
|
|
|
|
LokiPushNotificationManager.operateClosedGroup(groupPublicKey, userPublicKey, context, LokiPushNotificationManager.subscribe)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public fun handleClosedGroupUpdate(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|
public fun handleClosedGroupUpdate(context: Context, closedGroupUpdate: SignalServiceProtos.ClosedGroupUpdate, senderPublicKey: String) {
|
|
|
|