mirror of
https://github.com/ArcaneChat/android.git
synced 2026-07-03 14:05:24 +02:00
remove group dependecy to org.whispersystems:signal-service-android, tackles #138
This commit is contained in:
@@ -145,7 +145,6 @@ public class ConversationUpdateItem extends LinearLayout
|
||||
icon.setImageResource(R.drawable.ic_group_grey600_24dp);
|
||||
icon.clearColorFilter();
|
||||
|
||||
GroupUtil.getDescription(getContext(), messageRecord.getBody()).addListener(this);
|
||||
body.setText(messageRecord.getDisplayBody());
|
||||
|
||||
title.setVisibility(GONE);
|
||||
|
||||
@@ -29,7 +29,6 @@ import org.thoughtcrime.securesms.database.documents.IdentityKeyMismatch;
|
||||
import org.thoughtcrime.securesms.database.documents.NetworkFailure;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.util.ExpirationUtil;
|
||||
import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
@@ -90,8 +89,6 @@ public abstract class MessageRecord extends DisplayRecord {
|
||||
public SpannableString getDisplayBody() {
|
||||
if (isGroupUpdate() && isOutgoing()) {
|
||||
return new SpannableString(context.getString(R.string.MessageRecord_you_updated_group));
|
||||
} else if (isGroupUpdate()) {
|
||||
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()) {
|
||||
|
||||
@@ -1,20 +1,8 @@
|
||||
package org.thoughtcrime.securesms.util;
|
||||
|
||||
import android.content.Context;
|
||||
import android.support.annotation.NonNull;
|
||||
import android.support.annotation.Nullable;
|
||||
import android.util.Log;
|
||||
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.database.Address;
|
||||
import org.thoughtcrime.securesms.recipients.Recipient;
|
||||
import org.thoughtcrime.securesms.recipients.RecipientModifiedListener;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
import static org.whispersystems.signalservice.internal.push.SignalServiceProtos.GroupContext;
|
||||
|
||||
public class GroupUtil {
|
||||
|
||||
@@ -41,86 +29,4 @@ public class GroupUtil {
|
||||
public static boolean isMmsGroup(@NonNull String groupId) {
|
||||
return groupId.startsWith(ENCODED_MMS_GROUP_PREFIX);
|
||||
}
|
||||
|
||||
public static @NonNull GroupDescription getDescription(@NonNull Context context, @Nullable String encodedGroup) {
|
||||
if (encodedGroup == null) {
|
||||
return new GroupDescription(context, null);
|
||||
}
|
||||
|
||||
try {
|
||||
GroupContext groupContext = GroupContext.parseFrom(Base64.decode(encodedGroup));
|
||||
return new GroupDescription(context, groupContext);
|
||||
} catch (IOException e) {
|
||||
Log.w(TAG, e);
|
||||
return new GroupDescription(context, null);
|
||||
}
|
||||
}
|
||||
|
||||
public static class GroupDescription {
|
||||
|
||||
@NonNull private final Context context;
|
||||
@Nullable private final GroupContext groupContext;
|
||||
@Nullable private final List<Recipient> members;
|
||||
|
||||
public GroupDescription(@NonNull Context context, @Nullable GroupContext groupContext) {
|
||||
this.context = context.getApplicationContext();
|
||||
this.groupContext = groupContext;
|
||||
|
||||
if (groupContext == null || groupContext.getMembersList().isEmpty()) {
|
||||
this.members = null;
|
||||
} else {
|
||||
this.members = new LinkedList<>();
|
||||
|
||||
for (String member : groupContext.getMembersList()) {
|
||||
this.members.add(Recipient.from(context, Address.fromExternal(context, member), true));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public String toString(Recipient sender) {
|
||||
StringBuilder description = new StringBuilder();
|
||||
description.append(context.getString(R.string.MessageRecord_s_updated_group, sender.toShortString()));
|
||||
|
||||
if (groupContext == null) {
|
||||
return description.toString();
|
||||
}
|
||||
|
||||
String title = groupContext.getName();
|
||||
|
||||
if (members != null) {
|
||||
description.append("\n");
|
||||
description.append(context.getResources().getQuantityString(R.plurals.GroupUtil_joined_the_group,
|
||||
members.size(), toString(members)));
|
||||
}
|
||||
|
||||
if (title != null && !title.trim().isEmpty()) {
|
||||
if (members != null) description.append(" ");
|
||||
else description.append("\n");
|
||||
description.append(context.getString(R.string.GroupUtil_group_name_is_now, title));
|
||||
}
|
||||
|
||||
return description.toString();
|
||||
}
|
||||
|
||||
public void addListener(RecipientModifiedListener listener) {
|
||||
if (this.members != null) {
|
||||
for (Recipient member : this.members) {
|
||||
member.addListener(listener);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private String toString(List<Recipient> recipients) {
|
||||
String result = "";
|
||||
|
||||
for (int i=0;i<recipients.size();i++) {
|
||||
result += recipients.get(i).toShortString();
|
||||
|
||||
if (i != recipients.size() -1 )
|
||||
result += ", ";
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user