mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +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.clearColorFilter();
|
||||
|
||||
GroupUtil.getDescription(getContext(), messageRecord.getBody(), messageRecord.getRecipient()).addListener(this);
|
||||
GroupUtil.getDescription(getContext(), messageRecord.getBody()).addListener(this);
|
||||
body.setText(messageRecord.getDisplayBody(getContext()));
|
||||
|
||||
title.setVisibility(GONE);
|
||||
|
@ -92,7 +92,7 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
if (isGroupUpdate() && isOutgoing()) {
|
||||
return new SpannableString(context.getString(R.string.MessageRecord_you_updated_group));
|
||||
} 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()) {
|
||||
return new SpannableString(context.getString(R.string.MessageRecord_left_group));
|
||||
} else if (isGroupQuit()) {
|
||||
|
@ -7,10 +7,8 @@ import android.support.annotation.WorkerThread;
|
||||
|
||||
import com.google.protobuf.ByteString;
|
||||
|
||||
import network.loki.messenger.BuildConfig;
|
||||
import network.loki.messenger.R;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.database.Database;
|
||||
import org.thoughtcrime.securesms.database.DatabaseFactory;
|
||||
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) {
|
||||
// Make sure we always are passing a group recipient
|
||||
if (BuildConfig.DEBUG && groupRecipient != null && !groupRecipient.isGroupRecipient()) {
|
||||
throw new AssertionError();
|
||||
}
|
||||
|
||||
public static @NonNull GroupDescription getDescription(@NonNull Context context, @Nullable String encodedGroup) {
|
||||
if (encodedGroup == null) {
|
||||
return new GroupDescription(context, null, null);
|
||||
return new GroupDescription(context, null);
|
||||
}
|
||||
|
||||
try {
|
||||
GroupContext groupContext = GroupContext.parseFrom(Base64.decode(encodedGroup));
|
||||
GroupRecord groupRecord = groupRecipient != null
|
||||
? DatabaseFactory.getGroupDatabase(context).getGroup(groupRecipient.getAddress().toGroupString()).orNull()
|
||||
: null;
|
||||
return new GroupDescription(context, groupContext, groupRecord);
|
||||
return new GroupDescription(context, groupContext);
|
||||
} catch (IOException 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 boolean ourDeviceWasRemoved;
|
||||
|
||||
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) { this(context, groupContext, null); }
|
||||
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext, @Nullable GroupRecord groupRecord) {
|
||||
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.groupContext = groupContext;
|
||||
|
||||
@ -155,7 +144,7 @@ public class GroupUtil {
|
||||
|
||||
if (groupContext != null && !groupContext.getMembersList().isEmpty()) {
|
||||
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
|
||||
for (String member : memberList) {
|
||||
@ -234,5 +223,23 @@ public class GroupUtil {
|
||||
|
||||
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…
Reference in New Issue
Block a user