Update copy

This commit is contained in:
SessionHero01 2024-10-15 15:40:41 +11:00
parent e0ea98abdd
commit b8e98ec9ed
No known key found for this signature in database
6 changed files with 43 additions and 18 deletions

View File

@ -1059,7 +1059,7 @@ open class Storage @Inject constructor(
} }
override fun insertGroupInviteControlMessage(sentTimestamp: Long, senderPublicKey: String, closedGroup: AccountId, groupName: String): Long? { override fun insertGroupInviteControlMessage(sentTimestamp: Long, senderPublicKey: String, closedGroup: AccountId, groupName: String): Long? {
val updateData = UpdateMessageData(UpdateMessageData.Kind.GroupInvitation(senderPublicKey, groupName)) val updateData = UpdateMessageData(UpdateMessageData.Kind.GroupInvitation(closedGroup.hexString, senderPublicKey, groupName))
return insertUpdateControlMessage(updateData, sentTimestamp, senderPublicKey, closedGroup) return insertUpdateControlMessage(updateData, sentTimestamp, senderPublicKey, closedGroup)
} }

View File

@ -24,6 +24,7 @@ import android.text.style.StyleSpan;
import androidx.annotation.NonNull; import androidx.annotation.NonNull;
import org.session.libsession.messaging.MessagingModuleConfiguration;
import org.session.libsession.messaging.calls.CallMessageType; import org.session.libsession.messaging.calls.CallMessageType;
import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage; import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage;
import org.session.libsession.messaging.utilities.UpdateMessageBuilder; import org.session.libsession.messaging.utilities.UpdateMessageBuilder;
@ -118,7 +119,16 @@ public abstract class MessageRecord extends DisplayRecord {
public CharSequence getDisplayBody(@NonNull Context context) { public CharSequence getDisplayBody(@NonNull Context context) {
if (isGroupUpdateMessage()) { if (isGroupUpdateMessage()) {
UpdateMessageData updateMessageData = UpdateMessageData.Companion.fromJSON(getBody()); UpdateMessageData updateMessageData = UpdateMessageData.Companion.fromJSON(getBody());
return new SpannableString(UpdateMessageBuilder.INSTANCE.buildGroupUpdateMessage(context, updateMessageData, getIndividualRecipient().getAddress().serialize(), isOutgoing(), true)); if (updateMessageData == null) {
return "";
}
return new SpannableString(UpdateMessageBuilder.buildGroupUpdateMessage(
context,
updateMessageData,
MessagingModuleConfiguration.getShared().getConfigFactory(),
isOutgoing())
);
} else if (isExpirationTimerUpdate()) { } else if (isExpirationTimerUpdate()) {
int seconds = (int) (getExpiresIn() / 1000); int seconds = (int) (getExpiresIn() / 1000);
boolean isGroup = DatabaseComponent.get(context).threadDatabase().getRecipientForThreadId(getThreadId()).isGroupRecipient(); boolean isGroup = DatabaseComponent.get(context).threadDatabase().getRecipientForThreadId(getThreadId()).isGroupRecipient();

View File

@ -556,7 +556,6 @@ class GroupManagerV2Impl @Inject constructor(
val responseData = GroupUpdateMessage.newBuilder() val responseData = GroupUpdateMessage.newBuilder()
.setInviteResponse(inviteResponse) .setInviteResponse(inviteResponse)
val responseMessage = GroupUpdated(responseData.build()) val responseMessage = GroupUpdated(responseData.build())
storage.clearMessages(threadId)
// this will fail the first couple of times :) // this will fail the first couple of times :)
MessageSender.send( MessageSender.send(
responseMessage, responseMessage,

View File

@ -404,11 +404,12 @@ class DefaultConversationRepository @Inject constructor(
destination = Destination.from(recipient.address), destination = Destination.from(recipient.address),
isSyncMessage = recipient.isLocalNumber isSyncMessage = recipient.isLocalNumber
).await() ).await()
// add a control message for our user
storage.insertMessageRequestResponseFromYou(threadId)
} }
threadDb.setHasSent(threadId, true) threadDb.setHasSent(threadId, true)
// add a control message for our user
storage.insertMessageRequestResponseFromYou(threadId)
} }
} }

View File

@ -14,6 +14,7 @@ import org.session.libsession.messaging.sending_receiving.data_extraction.DataEx
import org.session.libsession.utilities.Address import org.session.libsession.utilities.Address
import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage.Kind.MEDIA_SAVED import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage.Kind.MEDIA_SAVED
import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage.Kind.SCREENSHOT import org.session.libsession.messaging.sending_receiving.data_extraction.DataExtractionNotificationInfoMessage.Kind.SCREENSHOT
import org.session.libsession.utilities.ConfigFactoryProtocol
import org.session.libsession.utilities.ExpirationUtil import org.session.libsession.utilities.ExpirationUtil
import org.session.libsession.utilities.getExpirationTypeDisplayValue import org.session.libsession.utilities.getExpirationTypeDisplayValue
import org.session.libsession.utilities.recipients.Recipient import org.session.libsession.utilities.recipients.Recipient
@ -25,6 +26,8 @@ import org.session.libsession.utilities.StringSubstitutionConstants.GROUP_NAME_K
import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.NAME_KEY
import org.session.libsession.utilities.StringSubstitutionConstants.OTHER_NAME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.OTHER_NAME_KEY
import org.session.libsession.utilities.StringSubstitutionConstants.TIME_KEY import org.session.libsession.utilities.StringSubstitutionConstants.TIME_KEY
import org.session.libsession.utilities.getClosedGroup
import org.session.libsignal.utilities.AccountId
object UpdateMessageBuilder { object UpdateMessageBuilder {
const val TAG = "UpdateMessageBuilder" const val TAG = "UpdateMessageBuilder"
@ -37,7 +40,12 @@ object UpdateMessageBuilder {
?: truncateIdForDisplay(senderId) ?: truncateIdForDisplay(senderId)
@JvmStatic @JvmStatic
fun buildGroupUpdateMessage(context: Context, updateMessageData: UpdateMessageData, senderId: String? = null, isOutgoing: Boolean = false, isInConversation: Boolean): CharSequence { fun buildGroupUpdateMessage(
context: Context,
updateMessageData: UpdateMessageData,
configFactory: ConfigFactoryProtocol,
isOutgoing: Boolean = false
): CharSequence {
val updateData = updateMessageData.kind ?: return "" val updateData = updateMessageData.kind ?: return ""
return when (updateData) { return when (updateData) {
@ -177,31 +185,32 @@ object UpdateMessageBuilder {
val userPublicKey = storage.getUserPublicKey()!! val userPublicKey = storage.getUserPublicKey()!!
val number = updateData.sessionIds.size val number = updateData.sessionIds.size
val containsUser = updateData.sessionIds.contains(userPublicKey) val containsUser = updateData.sessionIds.contains(userPublicKey)
val historyShared = updateData.historyShared
when (updateData.type) { when (updateData.type) {
UpdateMessageData.MemberUpdateType.ADDED -> { UpdateMessageData.MemberUpdateType.ADDED -> {
when { when {
number == 1 && containsUser -> Phrase.from(context, number == 1 && containsUser -> Phrase.from(context,
R.string.groupInviteYou) if (historyShared) R.string.groupInviteYouHistory else R.string.groupInviteYou)
.format() .format()
number == 1 -> Phrase.from(context, number == 1 -> Phrase.from(context,
R.string.groupMemberNew) if (historyShared) R.string.groupMemberNewHistory else R.string.groupMemberNew)
.put(NAME_KEY, context.youOrSender(updateData.sessionIds.first())) .put(NAME_KEY, context.youOrSender(updateData.sessionIds.first()))
.format() .format()
number == 2 && containsUser -> Phrase.from(context, number == 2 && containsUser -> Phrase.from(context,
R.string.groupInviteYouAndOtherNew) if (historyShared) R.string.groupMemberNewYouHistoryTwo else R.string.groupInviteYouAndOtherNew)
.put(OTHER_NAME_KEY, context.youOrSender(updateData.sessionIds.first { it != userPublicKey })) .put(OTHER_NAME_KEY, context.youOrSender(updateData.sessionIds.first { it != userPublicKey }))
.format() .format()
number == 2 -> Phrase.from(context, number == 2 -> Phrase.from(context,
R.string.groupMemberNewTwo) if (historyShared) R.string.groupMemberNewHistoryTwo else R.string.groupMemberNewTwo)
.put(NAME_KEY, context.youOrSender(updateData.sessionIds.first())) .put(NAME_KEY, context.youOrSender(updateData.sessionIds.first()))
.put(OTHER_NAME_KEY, context.youOrSender(updateData.sessionIds.last())) .put(OTHER_NAME_KEY, context.youOrSender(updateData.sessionIds.last()))
.format() .format()
containsUser -> Phrase.from(context, containsUser -> Phrase.from(context,
R.string.groupInviteYouAndMoreNew) if (historyShared) R.string.groupMemberNewYouHistoryMultiple else R.string.groupInviteYouAndMoreNew)
.put(COUNT_KEY, updateData.sessionIds.size - 1) .put(COUNT_KEY, updateData.sessionIds.size - 1)
.format() .format()
else -> Phrase.from(context, else -> Phrase.from(context,
R.string.groupMemberNewMultiple) if (historyShared) R.string.groupMemberNewHistoryMultiple else R.string.groupMemberNewMultiple)
.put(NAME_KEY, context.youOrSender(updateData.sessionIds.first())) .put(NAME_KEY, context.youOrSender(updateData.sessionIds.first()))
.put(COUNT_KEY, updateData.sessionIds.size - 1) .put(COUNT_KEY, updateData.sessionIds.size - 1)
.format() .format()
@ -272,7 +281,8 @@ object UpdateMessageBuilder {
} }
is UpdateMessageData.Kind.GroupInvitation -> { is UpdateMessageData.Kind.GroupInvitation -> {
val invitingAdmin = Recipient.from(context, Address.fromSerialized(updateData.invitingAdmin), false) val invitingAdmin = Recipient.from(context, Address.fromSerialized(updateData.invitingAdmin), false)
return if (invitingAdmin.name != null) { val approved = configFactory.getClosedGroup(AccountId(updateData.groupAccountId))?.invited == false
return if (invitingAdmin.name != null && !approved) {
Phrase.from(context, R.string.messageRequestGroupInvite) Phrase.from(context, R.string.messageRequestGroupInvite)
.put(NAME_KEY, invitingAdmin.name) .put(NAME_KEY, invitingAdmin.name)
.put(GROUP_NAME_KEY, updateData.groupName) .put(GROUP_NAME_KEY, updateData.groupName)

View File

@ -48,8 +48,13 @@ class UpdateMessageData () {
class GroupMemberLeft(val updatedMembers: Collection<String>, val groupName:String): Kind() { class GroupMemberLeft(val updatedMembers: Collection<String>, val groupName:String): Kind() {
constructor(): this(Collections.emptyList(), "") constructor(): this(Collections.emptyList(), "")
} }
class GroupMemberUpdated(val sessionIds: List<String>, val type: MemberUpdateType?, val groupName: String): Kind() { class GroupMemberUpdated(
constructor(): this(emptyList(), null, "") val sessionIds: List<String>,
val type: MemberUpdateType?,
val groupName: String,
val historyShared: Boolean
): Kind() {
constructor(): this(emptyList(), null, "", false)
} }
data object GroupAvatarUpdated: Kind() data object GroupAvatarUpdated: Kind()
class GroupExpirationUpdated(val updatedExpiration: Int = 0): Kind() { class GroupExpirationUpdated(val updatedExpiration: Int = 0): Kind() {
@ -60,8 +65,8 @@ class UpdateMessageData () {
} }
data object GroupLeaving: Kind() data object GroupLeaving: Kind()
data object GroupErrorQuit: Kind() data object GroupErrorQuit: Kind()
class GroupInvitation(val invitingAdmin: String, val groupName: String) : Kind() { class GroupInvitation(val groupAccountId: String, val invitingAdmin: String, val groupName: String) : Kind() {
constructor(): this("", "") constructor(): this("", "", "")
} }
class GroupKicked(val groupName: String) : Kind() { class GroupKicked(val groupName: String) : Kind() {
@ -117,7 +122,7 @@ class UpdateMessageData () {
null -> null null -> null
} }
val members = memberChange.memberSessionIdsList val members = memberChange.memberSessionIdsList
UpdateMessageData(Kind.GroupMemberUpdated(members, type, groupName)) UpdateMessageData(Kind.GroupMemberUpdated(members, type, groupName, memberChange.historyShared))
} }
inner.hasInfoChangeMessage() -> { inner.hasInfoChangeMessage() -> {
val infoChange = inner.infoChangeMessage val infoChange = inner.infoChangeMessage