kopia lustrzana https://github.com/ryukoposting/Signal-Android
Display membership count in link preview description field.
rodzic
dda98a474d
commit
4ace075ddf
|
@ -14,6 +14,7 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy;
|
||||||
import org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo;
|
import org.signal.storageservice.protos.groups.local.DecryptedGroupJoinInfo;
|
||||||
import org.signal.zkgroup.VerificationFailedException;
|
import org.signal.zkgroup.VerificationFailedException;
|
||||||
import org.signal.zkgroup.groups.GroupMasterKey;
|
import org.signal.zkgroup.groups.GroupMasterKey;
|
||||||
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.attachments.Attachment;
|
import org.thoughtcrime.securesms.attachments.Attachment;
|
||||||
import org.thoughtcrime.securesms.attachments.UriAttachment;
|
import org.thoughtcrime.securesms.attachments.UriAttachment;
|
||||||
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
import org.thoughtcrime.securesms.database.AttachmentDatabase;
|
||||||
|
@ -260,6 +261,8 @@ public class LinkPreviewRepository {
|
||||||
|
|
||||||
GroupDatabase.GroupRecord groupRecord = group.get();
|
GroupDatabase.GroupRecord groupRecord = group.get();
|
||||||
String title = groupRecord.getTitle();
|
String title = groupRecord.getTitle();
|
||||||
|
int memberCount = groupRecord.getMembers().size();
|
||||||
|
String description = getMemberCountDescription(context, memberCount);
|
||||||
Optional<Attachment> thumbnail = Optional.absent();
|
Optional<Attachment> thumbnail = Optional.absent();
|
||||||
|
|
||||||
if (AvatarHelper.hasAvatar(context, groupRecord.getRecipientId())) {
|
if (AvatarHelper.hasAvatar(context, groupRecord.getRecipientId())) {
|
||||||
|
@ -269,11 +272,12 @@ public class LinkPreviewRepository {
|
||||||
thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.WEBP, MediaUtil.IMAGE_WEBP);
|
thumbnail = bitmapToAttachment(bitmap, Bitmap.CompressFormat.WEBP, MediaUtil.IMAGE_WEBP);
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onSuccess(new LinkPreview(groupUrl, title, "", thumbnail));
|
callback.onSuccess(new LinkPreview(groupUrl, title, description, thumbnail));
|
||||||
} else {
|
} else {
|
||||||
Log.i(TAG, "Group is not locally available for preview generation, fetching from server");
|
Log.i(TAG, "Group is not locally available for preview generation, fetching from server");
|
||||||
|
|
||||||
DecryptedGroupJoinInfo joinInfo = GroupManager.getGroupJoinInfoFromServer(context, groupMasterKey, groupInviteLinkUrl.getPassword());
|
DecryptedGroupJoinInfo joinInfo = GroupManager.getGroupJoinInfoFromServer(context, groupMasterKey, groupInviteLinkUrl.getPassword());
|
||||||
|
String description = getMemberCountDescription(context, joinInfo.getMemberCount());
|
||||||
Optional<Attachment> thumbnail = Optional.absent();
|
Optional<Attachment> thumbnail = Optional.absent();
|
||||||
byte[] avatarBytes = AvatarGroupsV2DownloadJob.downloadGroupAvatarBytes(context, groupMasterKey, joinInfo.getAvatar());
|
byte[] avatarBytes = AvatarGroupsV2DownloadJob.downloadGroupAvatarBytes(context, groupMasterKey, joinInfo.getAvatar());
|
||||||
|
|
||||||
|
@ -285,7 +289,7 @@ public class LinkPreviewRepository {
|
||||||
if (bitmap != null) bitmap.recycle();
|
if (bitmap != null) bitmap.recycle();
|
||||||
}
|
}
|
||||||
|
|
||||||
callback.onSuccess(new LinkPreview(groupUrl, joinInfo.getTitle(), "", thumbnail));
|
callback.onSuccess(new LinkPreview(groupUrl, joinInfo.getTitle(), description, thumbnail));
|
||||||
}
|
}
|
||||||
} catch (ExecutionException | InterruptedException | IOException | VerificationFailedException e) {
|
} catch (ExecutionException | InterruptedException | IOException | VerificationFailedException e) {
|
||||||
Log.w(TAG, "Failed to fetch group link preview.", e);
|
Log.w(TAG, "Failed to fetch group link preview.", e);
|
||||||
|
@ -302,6 +306,13 @@ public class LinkPreviewRepository {
|
||||||
return () -> Log.i(TAG, "Cancelled group link preview fetch -- no effect.");
|
return () -> Log.i(TAG, "Cancelled group link preview fetch -- no effect.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static @NonNull String getMemberCountDescription(@NonNull Context context, int memberCount) {
|
||||||
|
return context.getResources()
|
||||||
|
.getQuantityString(R.plurals.LinkPreviewRepository_d_members,
|
||||||
|
memberCount,
|
||||||
|
memberCount);
|
||||||
|
}
|
||||||
|
|
||||||
private static Optional<Attachment> bitmapToAttachment(@Nullable Bitmap bitmap,
|
private static Optional<Attachment> bitmapToAttachment(@Nullable Bitmap bitmap,
|
||||||
@NonNull Bitmap.CompressFormat format,
|
@NonNull Bitmap.CompressFormat format,
|
||||||
@NonNull String contentType)
|
@NonNull String contentType)
|
||||||
|
|
|
@ -495,6 +495,12 @@
|
||||||
<string name="LinkPreviewView_no_link_preview_available">No link preview available</string>
|
<string name="LinkPreviewView_no_link_preview_available">No link preview available</string>
|
||||||
<string name="LinkPreviewView_this_group_link_is_not_active">This group link is not active</string>
|
<string name="LinkPreviewView_this_group_link_is_not_active">This group link is not active</string>
|
||||||
|
|
||||||
|
<!-- LinkPreviewRepository -->
|
||||||
|
<plurals name="LinkPreviewRepository_d_members">
|
||||||
|
<item quantity="one">%1$d member</item>
|
||||||
|
<item quantity="other">%1$d members</item>
|
||||||
|
</plurals>
|
||||||
|
|
||||||
<!-- PendingMembersActivity -->
|
<!-- PendingMembersActivity -->
|
||||||
<string name="PendingMemberInvitesActivity_pending_group_invites">Pending group invites</string>
|
<string name="PendingMemberInvitesActivity_pending_group_invites">Pending group invites</string>
|
||||||
<string name="PendingMembersActivity_people_you_invited">People you invited</string>
|
<string name="PendingMembersActivity_people_you_invited">People you invited</string>
|
||||||
|
|
Ładowanie…
Reference in New Issue