mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 14:47:44 +00:00
Merge branch 'dev' into on
This commit is contained in:
@@ -8,9 +8,11 @@ import androidx.annotation.Nullable;
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
import org.session.libsession.utilities.Address;
|
||||
import org.session.libsignal.utilities.Log;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileInputStream;
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
@@ -22,9 +24,9 @@ public class AvatarHelper {
|
||||
private static final String AVATAR_DIRECTORY = "avatars";
|
||||
|
||||
public static InputStream getInputStreamFor(@NonNull Context context, @NonNull Address address)
|
||||
throws IOException
|
||||
throws FileNotFoundException
|
||||
{
|
||||
return new FileInputStream(getAvatarFile(context, address));
|
||||
return new FileInputStream(getAvatarFile(context, address));
|
||||
}
|
||||
|
||||
public static List<File> getAvatarFiles(@NonNull Context context) {
|
||||
|
@@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
|
||||
|
||||
import org.session.libsession.utilities.Address;
|
||||
|
||||
import java.io.FileNotFoundException;
|
||||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.security.MessageDigest;
|
||||
@@ -24,7 +25,7 @@ public class ProfileContactPhoto implements ContactPhoto {
|
||||
}
|
||||
|
||||
@Override
|
||||
public InputStream openInputStream(Context context) throws IOException {
|
||||
public InputStream openInputStream(Context context) throws FileNotFoundException {
|
||||
return AvatarHelper.getInputStreamFor(context, address);
|
||||
}
|
||||
|
||||
|
@@ -8,6 +8,7 @@ import android.graphics.drawable.LayerDrawable;
|
||||
import android.widget.ImageView;
|
||||
|
||||
import androidx.annotation.DrawableRes;
|
||||
import androidx.appcompat.content.res.AppCompatResources;
|
||||
|
||||
import com.amulyakhare.textdrawable.TextDrawable;
|
||||
import com.makeramen.roundedimageview.RoundedDrawable;
|
||||
@@ -31,7 +32,7 @@ public class ResourceContactPhoto implements FallbackContactPhoto {
|
||||
@Override
|
||||
public Drawable asDrawable(Context context, int color, boolean inverted) {
|
||||
Drawable background = TextDrawable.builder().buildRound(" ", inverted ? Color.WHITE : color);
|
||||
RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(context.getResources().getDrawable(resourceId));
|
||||
RoundedDrawable foreground = (RoundedDrawable) RoundedDrawable.fromDrawable(AppCompatResources.getDrawable(context, resourceId));
|
||||
|
||||
foreground.setScaleType(ImageView.ScaleType.CENTER_CROP);
|
||||
|
||||
@@ -39,8 +40,10 @@ public class ResourceContactPhoto implements FallbackContactPhoto {
|
||||
foreground.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
|
||||
}
|
||||
|
||||
Drawable gradient = context.getResources().getDrawable(ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark
|
||||
: R.drawable.avatar_gradient_light);
|
||||
Drawable gradient = AppCompatResources.getDrawable(
|
||||
context,
|
||||
ThemeUtil.isDarkTheme(context) ? R.drawable.avatar_gradient_dark : R.drawable.avatar_gradient_light
|
||||
);
|
||||
|
||||
return new ExpandingLayerDrawable(new Drawable[] {background, foreground, gradient});
|
||||
}
|
||||
|
@@ -77,7 +77,7 @@ class Contact(val sessionID: String) {
|
||||
companion object {
|
||||
|
||||
fun contextForRecipient(recipient: Recipient): ContactContext {
|
||||
return if (recipient.isOpenGroupRecipient) ContactContext.OPEN_GROUP else ContactContext.REGULAR
|
||||
return if (recipient.isCommunityRecipient) ContactContext.OPEN_GROUP else ContactContext.REGULAR
|
||||
}
|
||||
}
|
||||
}
|
@@ -22,7 +22,7 @@ class OpenGroupDeleteJob(private val messageServerIds: LongArray, private val th
|
||||
override suspend fun execute(dispatcherName: String) {
|
||||
val dataProvider = MessagingModuleConfiguration.shared.messageDataProvider
|
||||
val numberToDelete = messageServerIds.size
|
||||
Log.d(TAG, "Deleting $numberToDelete messages")
|
||||
Log.d(TAG, "About to attempt to delete $numberToDelete messages")
|
||||
|
||||
// FIXME: This entire process should probably run in a transaction (with the attachment deletion happening only if it succeeded)
|
||||
try {
|
||||
@@ -42,6 +42,7 @@ class OpenGroupDeleteJob(private val messageServerIds: LongArray, private val th
|
||||
delegate?.handleJobSucceeded(this, dispatcherName)
|
||||
}
|
||||
catch (e: Exception) {
|
||||
Log.w(TAG, "OpenGroupDeleteJob failed: $e")
|
||||
delegate?.handleJobFailed(this, dispatcherName, e)
|
||||
}
|
||||
}
|
||||
|
@@ -43,14 +43,14 @@ sealed class Destination {
|
||||
val groupPublicKey = GroupUtil.doubleDecodeGroupID(groupID).toHexString()
|
||||
ClosedGroup(groupPublicKey)
|
||||
}
|
||||
address.isOpenGroup -> {
|
||||
address.isCommunity -> {
|
||||
val storage = MessagingModuleConfiguration.shared.storage
|
||||
val threadID = storage.getThreadId(address)!!
|
||||
storage.getOpenGroup(threadID)?.let {
|
||||
OpenGroup(roomToken = it.room, server = it.server, fileIds = fileIds)
|
||||
} ?: throw Exception("Missing open group for thread with ID: $threadID.")
|
||||
}
|
||||
address.isOpenGroupInbox -> {
|
||||
address.isCommunityInbox -> {
|
||||
val groupInboxId = GroupUtil.getDecodedGroupID(address.serialize()).split("!")
|
||||
OpenGroupInbox(
|
||||
groupInboxId.dropLast(2).joinToString("!"),
|
||||
|
@@ -602,8 +602,7 @@ object OpenGroupApi {
|
||||
// region Message Deletion
|
||||
@JvmStatic
|
||||
fun deleteMessage(serverID: Long, room: String, server: String): Promise<Unit, Exception> {
|
||||
val request =
|
||||
Request(verb = DELETE, room = room, server = server, endpoint = Endpoint.RoomMessageIndividual(room, serverID))
|
||||
val request = Request(verb = DELETE, room = room, server = server, endpoint = Endpoint.RoomMessageIndividual(room, serverID))
|
||||
return send(request).map {
|
||||
Log.d("Loki", "Message deletion successful.")
|
||||
}
|
||||
@@ -659,7 +658,9 @@ object OpenGroupApi {
|
||||
}
|
||||
|
||||
fun banAndDeleteAll(publicKey: String, room: String, server: String): Promise<Unit, Exception> {
|
||||
|
||||
val requests = mutableListOf<BatchRequestInfo<*>>(
|
||||
// Ban request
|
||||
BatchRequestInfo(
|
||||
request = BatchRequest(
|
||||
method = POST,
|
||||
@@ -669,6 +670,7 @@ object OpenGroupApi {
|
||||
endpoint = Endpoint.UserBan(publicKey),
|
||||
responseType = object: TypeReference<Any>(){}
|
||||
),
|
||||
// Delete request
|
||||
BatchRequestInfo(
|
||||
request = BatchRequest(DELETE, "/room/$room/all/$publicKey"),
|
||||
endpoint = Endpoint.RoomDeleteMessages(room, publicKey),
|
||||
|
@@ -8,7 +8,6 @@ import androidx.annotation.VisibleForTesting
|
||||
import org.session.libsignal.utilities.IdPrefix
|
||||
import org.session.libsignal.utilities.Util
|
||||
import org.session.libsignal.utilities.guava.Optional
|
||||
import java.util.Collections
|
||||
import java.util.LinkedList
|
||||
import java.util.concurrent.atomic.AtomicReference
|
||||
import java.util.regex.Matcher
|
||||
@@ -23,17 +22,17 @@ class Address private constructor(address: String) : Parcelable, Comparable<Addr
|
||||
get() = GroupUtil.isEncodedGroup(address)
|
||||
val isClosedGroup: Boolean
|
||||
get() = GroupUtil.isClosedGroup(address)
|
||||
val isOpenGroup: Boolean
|
||||
get() = GroupUtil.isOpenGroup(address)
|
||||
val isOpenGroupInbox: Boolean
|
||||
get() = GroupUtil.isOpenGroupInbox(address)
|
||||
val isOpenGroupOutbox: Boolean
|
||||
val isCommunity: Boolean
|
||||
get() = GroupUtil.isCommunity(address)
|
||||
val isCommunityInbox: Boolean
|
||||
get() = GroupUtil.isCommunityInbox(address)
|
||||
val isCommunityOutbox: Boolean
|
||||
get() = address.startsWith(IdPrefix.BLINDED.value) || address.startsWith(IdPrefix.BLINDEDV2.value)
|
||||
val isContact: Boolean
|
||||
get() = !(isGroup || isOpenGroupInbox)
|
||||
get() = !(isGroup || isCommunityInbox)
|
||||
|
||||
fun contactIdentifier(): String {
|
||||
if (!isContact && !isOpenGroup) {
|
||||
if (!isContact && !isCommunity) {
|
||||
if (isGroup) throw AssertionError("Not e164, is group")
|
||||
throw AssertionError("Not e164, unknown")
|
||||
}
|
||||
@@ -168,8 +167,9 @@ class Address private constructor(address: String) : Parcelable, Comparable<Addr
|
||||
@JvmStatic
|
||||
fun fromSerializedList(serialized: String, delimiter: Char): List<Address> {
|
||||
val escapedAddresses = DelimiterUtil.split(serialized, delimiter)
|
||||
val set = escapedAddresses.toSet().sorted()
|
||||
val addresses: MutableList<Address> = LinkedList()
|
||||
for (escapedAddress in escapedAddresses) {
|
||||
for (escapedAddress in set) {
|
||||
addresses.add(fromSerialized(DelimiterUtil.unescape(escapedAddress, delimiter)))
|
||||
}
|
||||
return addresses
|
||||
@@ -177,9 +177,9 @@ class Address private constructor(address: String) : Parcelable, Comparable<Addr
|
||||
|
||||
@JvmStatic
|
||||
fun toSerializedList(addresses: List<Address>, delimiter: Char): String {
|
||||
Collections.sort(addresses)
|
||||
val set = addresses.toSet().sorted()
|
||||
val escapedAddresses: MutableList<String> = LinkedList()
|
||||
for (address in addresses) {
|
||||
for (address in set) {
|
||||
escapedAddresses.add(DelimiterUtil.escape(address.serialize(), delimiter))
|
||||
}
|
||||
return Util.join(escapedAddresses, delimiter.toString() + "")
|
||||
|
@@ -22,7 +22,7 @@ class GroupRecord(
|
||||
}
|
||||
|
||||
val isOpenGroup: Boolean
|
||||
get() = Address.fromSerialized(encodedId).isOpenGroup
|
||||
get() = Address.fromSerialized(encodedId).isCommunity
|
||||
val isClosedGroup: Boolean
|
||||
get() = Address.fromSerialized(encodedId).isClosedGroup
|
||||
|
||||
|
@@ -8,12 +8,12 @@ import java.io.IOException
|
||||
|
||||
object GroupUtil {
|
||||
const val CLOSED_GROUP_PREFIX = "__textsecure_group__!"
|
||||
const val OPEN_GROUP_PREFIX = "__loki_public_chat_group__!"
|
||||
const val OPEN_GROUP_INBOX_PREFIX = "__open_group_inbox__!"
|
||||
const val COMMUNITY_PREFIX = "__loki_public_chat_group__!"
|
||||
const val COMMUNITY_INBOX_PREFIX = "__open_group_inbox__!"
|
||||
|
||||
@JvmStatic
|
||||
fun getEncodedOpenGroupID(groupID: ByteArray): String {
|
||||
return OPEN_GROUP_PREFIX + Hex.toStringCondensed(groupID)
|
||||
return COMMUNITY_PREFIX + Hex.toStringCondensed(groupID)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -25,7 +25,7 @@ object GroupUtil {
|
||||
|
||||
@JvmStatic
|
||||
fun getEncodedOpenGroupInboxID(groupInboxID: ByteArray): Address {
|
||||
return Address.fromSerialized(OPEN_GROUP_INBOX_PREFIX + Hex.toStringCondensed(groupInboxID))
|
||||
return Address.fromSerialized(COMMUNITY_INBOX_PREFIX + Hex.toStringCondensed(groupInboxID))
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
@@ -69,17 +69,17 @@ object GroupUtil {
|
||||
}
|
||||
|
||||
fun isEncodedGroup(groupId: String): Boolean {
|
||||
return groupId.startsWith(CLOSED_GROUP_PREFIX) || groupId.startsWith(OPEN_GROUP_PREFIX)
|
||||
return groupId.startsWith(CLOSED_GROUP_PREFIX) || groupId.startsWith(COMMUNITY_PREFIX)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isOpenGroup(groupId: String): Boolean {
|
||||
return groupId.startsWith(OPEN_GROUP_PREFIX)
|
||||
fun isCommunity(groupId: String): Boolean {
|
||||
return groupId.startsWith(COMMUNITY_PREFIX)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun isOpenGroupInbox(groupId: String): Boolean {
|
||||
return groupId.startsWith(OPEN_GROUP_INBOX_PREFIX)
|
||||
fun isCommunityInbox(groupId: String): Boolean {
|
||||
return groupId.startsWith(COMMUNITY_INBOX_PREFIX)
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
|
@@ -459,16 +459,16 @@ public class Recipient implements RecipientModifiedListener {
|
||||
}
|
||||
public boolean is1on1() { return address.isContact() && !isLocalNumber; }
|
||||
|
||||
public boolean isOpenGroupRecipient() {
|
||||
return address.isOpenGroup();
|
||||
public boolean isCommunityRecipient() {
|
||||
return address.isCommunity();
|
||||
}
|
||||
|
||||
public boolean isOpenGroupOutboxRecipient() {
|
||||
return address.isOpenGroupOutbox();
|
||||
return address.isCommunityOutbox();
|
||||
}
|
||||
|
||||
public boolean isOpenGroupInboxRecipient() {
|
||||
return address.isOpenGroupInbox();
|
||||
return address.isCommunityInbox();
|
||||
}
|
||||
|
||||
public boolean isClosedGroupRecipient() {
|
||||
|
Reference in New Issue
Block a user