Add invite friends action button and text.

This commit is contained in:
Alex Hart
2021-01-08 17:13:57 -04:00
committed by Alan Evans
parent 9fcf40fdc4
commit 4320a81846
3 changed files with 36 additions and 0 deletions

View File

@@ -233,6 +233,15 @@ public final class ConversationUpdateItem extends LinearLayout
actionButton.setVisibility(GONE);
actionButton.setOnClickListener(null);
}
} else if (conversationMessage.getMessageRecord().isSelfCreatedGroup()) {
actionButton.setText(R.string.ConversationUpdateItem_invite_friends);
actionButton.setVisibility(VISIBLE);
actionButton.setOnClickListener(v -> {
if (batchSelected.isEmpty() && eventListener != null) {
// TODO [alan]
Log.i(TAG, "TODO");
}
});
} else {
actionButton.setVisibility(GONE);
actionButton.setOnClickListener(null);

View File

@@ -32,6 +32,7 @@ import com.annimon.stream.Stream;
import org.signal.core.util.logging.Log;
import org.signal.storageservice.protos.groups.local.DecryptedGroup;
import org.signal.storageservice.protos.groups.local.DecryptedGroupChange;
import org.thoughtcrime.securesms.R;
import org.thoughtcrime.securesms.database.MmsSmsColumns;
import org.thoughtcrime.securesms.database.SmsDatabase;
@@ -56,6 +57,7 @@ import org.whispersystems.signalservice.api.util.UuidUtil;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Locale;
@@ -194,6 +196,26 @@ public abstract class MessageRecord extends DisplayRecord {
return null;
}
public boolean isSelfCreatedGroup() {
if (!isGroupUpdate() || !isGroupV2()) return false;
try {
byte[] decoded = Base64.decode(getBody());
DecryptedGroupChange change = DecryptedGroupV2Context.parseFrom(decoded)
.getChange();
return selfCreatedGroup(change);
} catch (IOException e) {
Log.w(TAG, "GV2 Message update detail could not be read", e);
return false;
}
}
private static boolean selfCreatedGroup(@NonNull DecryptedGroupChange change) {
return change.getRevision() == 0 &&
change.getEditor().equals(UuidUtil.toByteString(Recipient.self().requireUuid()));
}
public static @NonNull UpdateDescription getGv2ChangeDescription(@NonNull Context context, @NonNull String body) {
try {
ShortStringDescriptionStrategy descriptionStrategy = new ShortStringDescriptionStrategy(context);
@@ -203,6 +225,9 @@ public abstract class MessageRecord extends DisplayRecord {
if (decryptedGroupV2Context.hasChange() && (decryptedGroupV2Context.getGroupState().getRevision() != 0 || decryptedGroupV2Context.hasPreviousGroupState())) {
return UpdateDescription.concatWithNewLines(updateMessageProducer.describeChanges(decryptedGroupV2Context.getPreviousGroupState(), decryptedGroupV2Context.getChange()));
} else if (selfCreatedGroup(decryptedGroupV2Context.getChange())) {
return UpdateDescription.concatWithNewLines(Arrays.asList(updateMessageProducer.describeNewGroup(decryptedGroupV2Context.getGroupState(), decryptedGroupV2Context.getChange()),
staticUpdateDescription(context.getString(R.string.MessageRecord_invite_friends_to_this_group), 0)));
} else {
return updateMessageProducer.describeNewGroup(decryptedGroupV2Context.getGroupState(), decryptedGroupV2Context.getChange());
}

View File

@@ -1081,6 +1081,7 @@
<!-- GV2 specific -->
<string name="MessageRecord_you_created_the_group">You created the group.</string>
<string name="MessageRecord_group_updated">Group updated.</string>
<string name="MessageRecord_invite_friends_to_this_group">Invite friends to this group via a group link</string>
<!-- GV2 member additions -->
<string name="MessageRecord_you_added_s">You added %1$s.</string>
@@ -1954,6 +1955,7 @@
<string name="ConversationUpdateItem_join_call">Join call</string>
<string name="ConversationUpdateItem_return_to_call">Return to call</string>
<string name="ConversationUpdateItem_call_is_full">Call is full</string>
<string name="ConversationUpdateItem_invite_friends">Invite friends</string>
<!-- audio_view -->
<string name="audio_view__play_pause_accessibility_description">Play … Pause</string>