mirror of
https://github.com/oxen-io/session-android.git
synced 2025-04-23 06:31:33 +00:00
Get group record programatically instead of making user pass in the recipient.
This was the original function but i added in recipient to it. This is causing crashes and thus we just get the group record.
This commit is contained in:
parent
93a9f4c1dc
commit
6b38e5d799
@ -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(), messageRecord.getRecipient()).addListener(this);
|
GroupUtil.getDescription(getContext(), messageRecord.getBody()).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(), getRecipient()).toString(getIndividualRecipient()));
|
return new SpannableString(GroupUtil.getDescription(context, getBody()).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()) {
|
||||||
|
@ -7,10 +7,8 @@ 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.database.GroupDatabase.*;
|
||||||
@ -114,25 +112,17 @@ public class GroupUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public static @NonNull GroupDescription getDescription(@NonNull Context context, @Nullable String encodedGroup, @Nullable Recipient groupRecipient) {
|
public static @NonNull GroupDescription getDescription(@NonNull Context context, @Nullable String encodedGroup) {
|
||||||
// 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, null);
|
return new GroupDescription(context, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
GroupContext groupContext = GroupContext.parseFrom(Base64.decode(encodedGroup));
|
GroupContext groupContext = GroupContext.parseFrom(Base64.decode(encodedGroup));
|
||||||
GroupRecord groupRecord = groupRecipient != null
|
return new GroupDescription(context, groupContext);
|
||||||
? 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, null);
|
return new GroupDescription(context, null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -144,8 +134,7 @@ public class GroupUtil {
|
|||||||
private final List<Recipient> removedMembers;
|
private final List<Recipient> removedMembers;
|
||||||
private boolean ourDeviceWasRemoved;
|
private boolean ourDeviceWasRemoved;
|
||||||
|
|
||||||
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) { this(context, groupContext, null); }
|
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) {
|
||||||
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;
|
||||||
|
|
||||||
@ -155,7 +144,7 @@ public class GroupUtil {
|
|||||||
|
|
||||||
if (groupContext != null && !groupContext.getMembersList().isEmpty()) {
|
if (groupContext != null && !groupContext.getMembersList().isEmpty()) {
|
||||||
List<String> memberList = groupContext.getMembersList();
|
List<String> memberList = groupContext.getMembersList();
|
||||||
List<Address> currentMembers = groupRecord != null ? groupRecord.getMembers() : null;
|
List<Address> currentMembers = getCurrentGroupMembers();
|
||||||
|
|
||||||
// Add them to the member or removed members lists
|
// Add them to the member or removed members lists
|
||||||
for (String member : memberList) {
|
for (String member : memberList) {
|
||||||
@ -234,5 +223,23 @@ public class GroupUtil {
|
|||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private List<Address> getCurrentGroupMembers() {
|
||||||
|
if (groupContext == null) { return null; }
|
||||||
|
GroupDatabase groupDatabase = DatabaseFactory.getGroupDatabase(context);
|
||||||
|
byte[] decodedGroupId = groupContext.getId().toByteArray();
|
||||||
|
String signalGroupId = getEncodedId(decodedGroupId, false);
|
||||||
|
String publicChatId = getEncodedPublicChatId(decodedGroupId);
|
||||||
|
String rssFeedId = getEncodedRSSFeedId(decodedGroupId);
|
||||||
|
GroupRecord groupRecord = null;
|
||||||
|
if (!groupDatabase.isUnknownGroup(signalGroupId)) {
|
||||||
|
groupRecord = groupDatabase.getGroup(signalGroupId).orNull();
|
||||||
|
} else if (!groupDatabase.isUnknownGroup(publicChatId)) {
|
||||||
|
groupRecord = groupDatabase.getGroup(publicChatId).orNull();
|
||||||
|
} else if (!groupDatabase.isUnknownGroup(rssFeedId)) {
|
||||||
|
groupRecord = groupDatabase.getGroup(rssFeedId).orNull();
|
||||||
|
}
|
||||||
|
return (groupRecord != null) ? groupRecord.getMembers() : null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user