mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-20 03:01:29 +00:00
Let user know when members have been removed from the group.
This commit is contained in:
parent
33788189dd
commit
23a5fa7580
@ -1073,7 +1073,12 @@
|
|||||||
<item quantity="one">%1$s joined the group.</item>
|
<item quantity="one">%1$s joined the group.</item>
|
||||||
<item quantity="other">%1$s joined the group.</item>
|
<item quantity="other">%1$s joined the group.</item>
|
||||||
</plurals>
|
</plurals>
|
||||||
|
<plurals name="GroupUtil_removed_from_the_group">
|
||||||
|
<item quantity="one">%1$s was removed from the group.</item>
|
||||||
|
<item quantity="other">%1$s were removed from the group.</item>
|
||||||
|
</plurals>
|
||||||
<string name="GroupUtil_group_name_is_now">Group name is now \'%1$s\'.</string>
|
<string name="GroupUtil_group_name_is_now">Group name is now \'%1$s\'.</string>
|
||||||
|
<string name="GroupUtil_you_were_removed_from_group">You were removed from the group.</string>
|
||||||
|
|
||||||
<!-- profile_group_share_view -->
|
<!-- profile_group_share_view -->
|
||||||
<string name="profile_group_share_view__make_your_profile_name_and_photo_visible_to_this_group">Make your profile name and photo visible to this group?</string>
|
<string name="profile_group_share_view__make_your_profile_name_and_photo_visible_to_this_group">Make your profile name and photo visible to this group?</string>
|
||||||
|
@ -175,7 +175,7 @@ public class ConversationUpdateItem extends LinearLayout
|
|||||||
icon.setImageResource(R.drawable.ic_group_grey600_24dp);
|
icon.setImageResource(R.drawable.ic_group_grey600_24dp);
|
||||||
icon.clearColorFilter();
|
icon.clearColorFilter();
|
||||||
|
|
||||||
GroupUtil.getDescription(getContext(), messageRecord.getBody()).addListener(this);
|
GroupUtil.getDescription(getContext(), messageRecord.getBody(), messageRecord.getRecipient()).addListener(this);
|
||||||
body.setText(messageRecord.getDisplayBody(getContext()));
|
body.setText(messageRecord.getDisplayBody(getContext()));
|
||||||
|
|
||||||
title.setVisibility(GONE);
|
title.setVisibility(GONE);
|
||||||
|
@ -92,7 +92,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
|||||||
if (isGroupUpdate() && isOutgoing()) {
|
if (isGroupUpdate() && isOutgoing()) {
|
||||||
return new SpannableString(context.getString(R.string.MessageRecord_you_updated_group));
|
return new SpannableString(context.getString(R.string.MessageRecord_you_updated_group));
|
||||||
} else if (isGroupUpdate()) {
|
} else if (isGroupUpdate()) {
|
||||||
return new SpannableString(GroupUtil.getDescription(context, getBody()).toString(getIndividualRecipient()));
|
return new SpannableString(GroupUtil.getDescription(context, getBody(), getRecipient()).toString(getIndividualRecipient()));
|
||||||
} else if (isGroupQuit() && isOutgoing()) {
|
} else if (isGroupQuit() && isOutgoing()) {
|
||||||
return new SpannableString(context.getString(R.string.MessageRecord_left_group));
|
return new SpannableString(context.getString(R.string.MessageRecord_left_group));
|
||||||
} else if (isGroupQuit()) {
|
} else if (isGroupQuit()) {
|
||||||
|
@ -141,7 +141,9 @@ public class GroupMessageProcessor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (missingMembers.size() > 0) {
|
if (missingMembers.size() > 0) {
|
||||||
// TODO We should tell added and missing about each-other.
|
for (Address removedMember : missingMembers) {
|
||||||
|
builder.addMembers(removedMember.serialize());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (group.getName().isPresent() || group.getAvatar().isPresent()) {
|
if (group.getName().isPresent() || group.getAvatar().isPresent()) {
|
||||||
|
@ -45,6 +45,10 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa
|
|||||||
fun getFriendRequestStatus(threadID: Long): LokiThreadFriendRequestStatus {
|
fun getFriendRequestStatus(threadID: Long): LokiThreadFriendRequestStatus {
|
||||||
if (threadID < 0) { return LokiThreadFriendRequestStatus.NONE }
|
if (threadID < 0) { return LokiThreadFriendRequestStatus.NONE }
|
||||||
|
|
||||||
|
// Loki - Friend request logic doesn't apply to group chats, always treat them as friends
|
||||||
|
val recipient = DatabaseFactory.getThreadDatabase(context).getRecipientForThreadId(threadID)
|
||||||
|
if (recipient != null && recipient.isGroupRecipient) { return LokiThreadFriendRequestStatus.FRIENDS; }
|
||||||
|
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
val result = database.get(friendRequestTableName, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) { cursor ->
|
val result = database.get(friendRequestTableName, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) { cursor ->
|
||||||
cursor.getInt(friendRequestStatus)
|
cursor.getInt(friendRequestStatus)
|
||||||
|
@ -7,10 +7,13 @@ import android.support.annotation.WorkerThread;
|
|||||||
|
|
||||||
import com.google.protobuf.ByteString;
|
import com.google.protobuf.ByteString;
|
||||||
|
|
||||||
|
import network.loki.messenger.BuildConfig;
|
||||||
import network.loki.messenger.R;
|
import network.loki.messenger.R;
|
||||||
import org.thoughtcrime.securesms.database.Address;
|
import org.thoughtcrime.securesms.database.Address;
|
||||||
|
import org.thoughtcrime.securesms.database.Database;
|
||||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||||
import org.thoughtcrime.securesms.database.GroupDatabase;
|
import org.thoughtcrime.securesms.database.GroupDatabase;
|
||||||
|
import org.thoughtcrime.securesms.database.GroupDatabase.*;
|
||||||
import org.thoughtcrime.securesms.logging.Log;
|
import org.thoughtcrime.securesms.logging.Log;
|
||||||
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
import org.thoughtcrime.securesms.mms.OutgoingGroupMediaMessage;
|
||||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||||
@ -111,17 +114,25 @@ public class GroupUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static @NonNull GroupDescription getDescription(@NonNull Context context, @Nullable String encodedGroup) {
|
public static @NonNull GroupDescription getDescription(@NonNull Context context, @Nullable String encodedGroup, @Nullable Recipient groupRecipient) {
|
||||||
|
// Make sure we always are passing a group recipient
|
||||||
|
if (BuildConfig.DEBUG && groupRecipient != null && !groupRecipient.isGroupRecipient()) {
|
||||||
|
throw new AssertionError();
|
||||||
|
}
|
||||||
|
|
||||||
if (encodedGroup == null) {
|
if (encodedGroup == null) {
|
||||||
return new GroupDescription(context, null);
|
return new GroupDescription(context, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GroupContext groupContext = GroupContext.parseFrom(Base64.decode(encodedGroup));
|
GroupContext groupContext = GroupContext.parseFrom(Base64.decode(encodedGroup));
|
||||||
return new GroupDescription(context, groupContext);
|
GroupRecord groupRecord = groupRecipient != null
|
||||||
|
? DatabaseFactory.getGroupDatabase(context).getGroup(groupRecipient.getAddress().toGroupString()).orNull()
|
||||||
|
: null;
|
||||||
|
return new GroupDescription(context, groupContext, groupRecord);
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
Log.w(TAG, e);
|
Log.w(TAG, e);
|
||||||
return new GroupDescription(context, null);
|
return new GroupDescription(context, null, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -129,24 +140,50 @@ public class GroupUtil {
|
|||||||
|
|
||||||
@NonNull private final Context context;
|
@NonNull private final Context context;
|
||||||
@Nullable private final GroupContext groupContext;
|
@Nullable private final GroupContext groupContext;
|
||||||
@Nullable private final List<Recipient> members;
|
private final List<Recipient> members;
|
||||||
|
private final List<Recipient> removedMembers;
|
||||||
|
private boolean ourDeviceWasRemoved;
|
||||||
|
|
||||||
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) {
|
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) { this(context, groupContext, null); }
|
||||||
|
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext, @Nullable GroupRecord groupRecord) {
|
||||||
this.context = context.getApplicationContext();
|
this.context = context.getApplicationContext();
|
||||||
this.groupContext = groupContext;
|
this.groupContext = groupContext;
|
||||||
|
|
||||||
if (groupContext == null || groupContext.getMembersList().isEmpty()) {
|
|
||||||
this.members = null;
|
|
||||||
} else {
|
|
||||||
this.members = new LinkedList<>();
|
this.members = new LinkedList<>();
|
||||||
|
this.removedMembers = new LinkedList<>();
|
||||||
|
this.ourDeviceWasRemoved = false;
|
||||||
|
|
||||||
for (String member : groupContext.getMembersList()) {
|
if (groupContext != null && !groupContext.getMembersList().isEmpty()) {
|
||||||
this.members.add(Recipient.from(context, Address.fromExternal(context, member), true));
|
List<String> memberList = groupContext.getMembersList();
|
||||||
|
List<Address> currentMembers = groupRecord != null ? groupRecord.getMembers() : null;
|
||||||
|
|
||||||
|
// Add them to the member or removed members lists
|
||||||
|
for (String member : memberList) {
|
||||||
|
Address address = Address.fromSerialized(member);
|
||||||
|
Recipient recipient = Recipient.from(context, address, true);
|
||||||
|
if (currentMembers == null || currentMembers.contains(address)) {
|
||||||
|
this.members.add(recipient);
|
||||||
|
} else {
|
||||||
|
this.removedMembers.add(recipient);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if our device was removed
|
||||||
|
if (!removedMembers.isEmpty()) {
|
||||||
|
String masterHexEncodedPublicKey = TextSecurePreferences.getMasterHexEncodedPublicKey(context);
|
||||||
|
String hexEncodedPublicKey = masterHexEncodedPublicKey != null ? masterHexEncodedPublicKey : TextSecurePreferences.getLocalNumber(context);
|
||||||
|
Recipient self = Recipient.from(context, Address.fromSerialized(hexEncodedPublicKey), false);
|
||||||
|
ourDeviceWasRemoved = removedMembers.contains(self);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString(Recipient sender) {
|
public String toString(Recipient sender) {
|
||||||
|
// Show the local removed message
|
||||||
|
if (ourDeviceWasRemoved) {
|
||||||
|
return context.getString(R.string.GroupUtil_you_were_removed_from_group);
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder description = new StringBuilder();
|
StringBuilder description = new StringBuilder();
|
||||||
description.append(context.getString(R.string.MessageRecord_s_updated_group, sender.toShortString()));
|
description.append(context.getString(R.string.MessageRecord_s_updated_group, sender.toShortString()));
|
||||||
|
|
||||||
@ -156,14 +193,20 @@ public class GroupUtil {
|
|||||||
|
|
||||||
String title = groupContext.getName();
|
String title = groupContext.getName();
|
||||||
|
|
||||||
if (members != null) {
|
if (!members.isEmpty()) {
|
||||||
description.append("\n");
|
description.append("\n");
|
||||||
description.append(context.getResources().getQuantityString(R.plurals.GroupUtil_joined_the_group,
|
description.append(context.getResources().getQuantityString(R.plurals.GroupUtil_joined_the_group,
|
||||||
members.size(), toString(members)));
|
members.size(), toString(members)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!removedMembers.isEmpty()) {
|
||||||
|
description.append("\n");
|
||||||
|
description.append(context.getResources().getQuantityString(R.plurals.GroupUtil_removed_from_the_group,
|
||||||
|
removedMembers.size(), toString(removedMembers)));
|
||||||
|
}
|
||||||
|
|
||||||
if (title != null && !title.trim().isEmpty()) {
|
if (title != null && !title.trim().isEmpty()) {
|
||||||
if (members != null) description.append(" ");
|
if (!members.isEmpty()) description.append(" ");
|
||||||
else description.append("\n");
|
else description.append("\n");
|
||||||
description.append(context.getString(R.string.GroupUtil_group_name_is_now, title));
|
description.append(context.getString(R.string.GroupUtil_group_name_is_now, title));
|
||||||
}
|
}
|
||||||
@ -172,7 +215,7 @@ public class GroupUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void addListener(RecipientModifiedListener listener) {
|
public void addListener(RecipientModifiedListener listener) {
|
||||||
if (this.members != null) {
|
if (!this.members.isEmpty()) {
|
||||||
for (Recipient member : this.members) {
|
for (Recipient member : this.members) {
|
||||||
member.addListener(listener);
|
member.addListener(listener);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user