mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-12 04:17:42 +00:00
Start of Update messages builder class implementation & usage for Input group updates
This commit is contained in:
@@ -19,6 +19,7 @@ import org.session.libsession.messaging.sending_receiving.quotes.QuoteModel
|
||||
import org.session.libsession.messaging.threads.Address
|
||||
import org.session.libsession.messaging.threads.GroupRecord
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient
|
||||
import org.session.libsession.messaging.utilities.UpdateMessageBuilder
|
||||
import org.session.libsession.utilities.GroupUtil
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
import org.session.libsignal.libsignal.ecc.ECKeyPair
|
||||
@@ -79,6 +80,11 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
return recipient.profileKey
|
||||
}
|
||||
|
||||
override fun getDisplayNameForRecipient(recipientPublicKey: String): String? {
|
||||
val database = DatabaseFactory.getLokiUserDatabase(context)
|
||||
return database.getDisplayName(recipientPublicKey)
|
||||
}
|
||||
|
||||
override fun getOrGenerateRegistrationID(): Int {
|
||||
var registrationID = TextSecurePreferences.getLocalRegistrationId(context)
|
||||
if (registrationID == null) {
|
||||
@@ -397,7 +403,8 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
||||
.addAllAdmins(admins)
|
||||
val group = SignalServiceGroup(type1, GroupUtil.getDecodedGroupIDAsData(groupID), SignalServiceGroup.GroupType.SIGNAL, name, members.toList(), null, admins.toList())
|
||||
val m = IncomingTextMessage(Address.fromSerialized(senderPublicKey), 1, System.currentTimeMillis(), "", Optional.of(group), 0, true)
|
||||
val infoMessage = IncomingGroupMessage(m, groupContextBuilder.build(), "")
|
||||
val messageBody = UpdateMessageBuilder.buildGroupUpdateMessage(context, group, senderPublicKey)
|
||||
val infoMessage = IncomingGroupMessage(m, groupContextBuilder.build(), messageBody)
|
||||
val smsDB = DatabaseFactory.getSmsDatabase(context)
|
||||
smsDB.insertMessageInbox(infoMessage)
|
||||
}
|
||||
|
@@ -33,6 +33,7 @@ import org.session.libsignal.utilities.Hex
|
||||
import org.session.libsession.messaging.threads.Address
|
||||
import org.session.libsession.messaging.threads.GroupRecord
|
||||
import org.session.libsession.messaging.threads.recipients.Recipient
|
||||
import org.session.libsession.messaging.utilities.UpdateMessageBuilder
|
||||
import org.session.libsession.utilities.GroupUtil
|
||||
import org.session.libsession.utilities.TextSecurePreferences
|
||||
|
||||
@@ -361,7 +362,7 @@ object ClosedGroupsProtocolV2 {
|
||||
apiDB.addClosedGroupEncryptionKeyPair(encryptionKeyPair, groupPublicKey)
|
||||
// Notify the user (if we didn't make the group)
|
||||
if (userPublicKey != senderPublicKey) {
|
||||
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.UPDATE, name, members, admins, sentTimestamp)
|
||||
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.NEW_GROUP, name, members, admins, sentTimestamp)
|
||||
} else if (prevGroup == null) {
|
||||
// only notify if we created this group
|
||||
val threadID = DatabaseFactory.getLokiThreadDatabase(context).getThreadID(groupID)
|
||||
@@ -415,12 +416,12 @@ object ClosedGroupsProtocolV2 {
|
||||
}
|
||||
val (contextType, signalType) =
|
||||
if (senderLeft) GroupContext.Type.QUIT to SignalServiceGroup.Type.QUIT
|
||||
else GroupContext.Type.UPDATE to SignalServiceGroup.Type.UPDATE
|
||||
else GroupContext.Type.UPDATE to SignalServiceGroup.Type.MEMBER_REMOVED
|
||||
if (userPublicKey == senderPublicKey) {
|
||||
val threadID = DatabaseFactory.getLokiThreadDatabase(context).getThreadID(groupID)
|
||||
insertOutgoingInfoMessage(context, groupID, contextType, name, members, admins, threadID, sentTimestamp)
|
||||
} else {
|
||||
insertIncomingInfoMessage(context, senderPublicKey, groupID, contextType, signalType, name, members, admins, sentTimestamp)
|
||||
insertIncomingInfoMessage(context, senderPublicKey, groupID, contextType, signalType, name, updateMembers, admins, sentTimestamp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -450,7 +451,7 @@ object ClosedGroupsProtocolV2 {
|
||||
val threadID = DatabaseFactory.getLokiThreadDatabase(context).getThreadID(groupID)
|
||||
insertOutgoingInfoMessage(context, groupID, GroupContext.Type.UPDATE, name, members, admins, threadID, sentTimestamp)
|
||||
} else {
|
||||
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.UPDATE, name, members, admins, sentTimestamp)
|
||||
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.MEMBER_ADDED, name, updateMembers, admins, sentTimestamp)
|
||||
}
|
||||
if (userPublicKey in admins) {
|
||||
// send current encryption key to the latest added members
|
||||
@@ -489,7 +490,7 @@ object ClosedGroupsProtocolV2 {
|
||||
val threadID = DatabaseFactory.getLokiThreadDatabase(context).getThreadID(groupID)
|
||||
insertOutgoingInfoMessage(context, groupID, GroupContext.Type.UPDATE, name, members, admins, threadID, sentTimestamp)
|
||||
} else {
|
||||
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.UPDATE, name, members, admins, sentTimestamp)
|
||||
insertIncomingInfoMessage(context, senderPublicKey, groupID, GroupContext.Type.UPDATE, SignalServiceGroup.Type.NAME_CHANGE, name, members, admins, sentTimestamp)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -608,7 +609,8 @@ object ClosedGroupsProtocolV2 {
|
||||
.addAllAdmins(admins)
|
||||
val group = SignalServiceGroup(type1, GroupUtil.getDecodedGroupIDAsData(groupID), SignalServiceGroup.GroupType.SIGNAL, name, members.toList(), null, admins.toList())
|
||||
val m = IncomingTextMessage(Address.fromSerialized(senderPublicKey), 1, sentTimestamp, "", Optional.of(group), 0, true)
|
||||
val infoMessage = IncomingGroupMessage(m, groupContextBuilder.build(), "")
|
||||
val messageBody = UpdateMessageBuilder.buildGroupUpdateMessage(context, group, senderPublicKey)
|
||||
val infoMessage = IncomingGroupMessage(m, groupContextBuilder.build(), messageBody)
|
||||
val smsDB = DatabaseFactory.getSmsDatabase(context)
|
||||
smsDB.insertMessageInbox(infoMessage)
|
||||
}
|
||||
|
@@ -493,6 +493,14 @@
|
||||
<string name="MessageRecord_message_encrypted_with_a_legacy_protocol_version_that_is_no_longer_supported">Received a message encrypted using an old version of Session that is no longer supported. Please ask the sender to update to the most recent version and resend the message.</string>
|
||||
<string name="MessageRecord_left_group">You have left the group.</string>
|
||||
<string name="MessageRecord_you_updated_group">You updated the group.</string>
|
||||
<string name="MessageRecord_you_created_a_new_group">You created a new group.</string>
|
||||
<string name="MessageRecord_s_added_you_to_the_group">%1$s added you to the group.</string>
|
||||
<string name="MessageRecord_you_renamed_the_group_to_s">You renamed the group to %1$s</string>
|
||||
<string name="MessageRecord_s_renamed_the_group_to_s">%1$s renamed the group to: %2$s</string>
|
||||
<string name="MessageRecord_you_added_s_to_the_group">You added %1$s to the group.</string>
|
||||
<string name="MessageRecord_s_added_s_to_the_group">%1$s added %2$s to the group.</string>
|
||||
<string name="MessageRecord_you_removed_s_from_the_group">You removed %1$s from the group.</string>
|
||||
<string name="MessageRecord_s_removed_s_from_the_group">%1$s removed %2$s from the group.</string>
|
||||
<string name="MessageRecord_you_called">You called</string>
|
||||
<string name="MessageRecord_called_you">Contact called</string>
|
||||
<string name="MessageRecord_missed_call">Missed call</string>
|
||||
|
Reference in New Issue
Block a user