mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-12 17:23:39 +00:00
Clean
This commit is contained in:
parent
7cbeace0ce
commit
d19a69567d
@ -6,9 +6,10 @@ import android.content.ContentValues;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.database.Cursor;
|
import android.database.Cursor;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
|
import android.text.TextUtils;
|
||||||
|
|
||||||
import androidx.annotation.NonNull;
|
import androidx.annotation.NonNull;
|
||||||
import androidx.annotation.Nullable;
|
import androidx.annotation.Nullable;
|
||||||
import android.text.TextUtils;
|
|
||||||
|
|
||||||
import com.annimon.stream.Stream;
|
import com.annimon.stream.Stream;
|
||||||
|
|
||||||
@ -21,7 +22,7 @@ import org.thoughtcrime.securesms.util.GroupUtil;
|
|||||||
import org.thoughtcrime.securesms.util.Util;
|
import org.thoughtcrime.securesms.util.Util;
|
||||||
import org.whispersystems.libsignal.util.guava.Optional;
|
import org.whispersystems.libsignal.util.guava.Optional;
|
||||||
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
import org.whispersystems.signalservice.api.messages.SignalServiceAttachmentPointer;
|
||||||
import org.whispersystems.signalservice.loki.database.LokiGroupDatabaseProtocol;
|
import org.whispersystems.signalservice.loki.database.LokiOpenGroupDatabaseProtocol;
|
||||||
|
|
||||||
import java.io.Closeable;
|
import java.io.Closeable;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -30,7 +31,7 @@ import java.util.Collections;
|
|||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class GroupDatabase extends Database implements LokiGroupDatabaseProtocol {
|
public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProtocol {
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
private static final String TAG = GroupDatabase.class.getSimpleName();
|
private static final String TAG = GroupDatabase.class.getSimpleName();
|
||||||
@ -242,36 +243,36 @@ public class GroupDatabase extends Database implements LokiGroupDatabaseProtocol
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateTitle(String groupId, String title) {
|
public void updateTitle(String groupID, String newValue) {
|
||||||
ContentValues contentValues = new ContentValues();
|
ContentValues contentValues = new ContentValues();
|
||||||
contentValues.put(TITLE, title);
|
contentValues.put(TITLE, newValue);
|
||||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, GROUP_ID + " = ?",
|
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, GROUP_ID + " = ?",
|
||||||
new String[] {groupId});
|
new String[] {groupID});
|
||||||
|
|
||||||
Recipient recipient = Recipient.from(context, Address.fromSerialized(groupId), false);
|
Recipient recipient = Recipient.from(context, Address.fromSerialized(groupID), false);
|
||||||
recipient.setName(title);
|
recipient.setName(newValue);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateAvatar(String groupId, Bitmap avatar) {
|
public void updateProfilePicture(String groupID, Bitmap newValue) {
|
||||||
updateAvatar(groupId, BitmapUtil.toByteArray(avatar));
|
updateProfilePicture(groupID, BitmapUtil.toByteArray(newValue));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateAvatar(String groupId, byte[] avatar) {
|
public void updateProfilePicture(String groupID, byte[] newValue) {
|
||||||
long avatarId;
|
long avatarId;
|
||||||
|
|
||||||
if (avatar != null) avatarId = Math.abs(new SecureRandom().nextLong());
|
if (newValue != null) avatarId = Math.abs(new SecureRandom().nextLong());
|
||||||
else avatarId = 0;
|
else avatarId = 0;
|
||||||
|
|
||||||
|
|
||||||
ContentValues contentValues = new ContentValues(2);
|
ContentValues contentValues = new ContentValues(2);
|
||||||
contentValues.put(AVATAR, avatar);
|
contentValues.put(AVATAR, newValue);
|
||||||
contentValues.put(AVATAR_ID, avatarId);
|
contentValues.put(AVATAR_ID, avatarId);
|
||||||
|
|
||||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, GROUP_ID + " = ?",
|
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, GROUP_ID + " = ?",
|
||||||
new String[] {groupId});
|
new String[] {groupID});
|
||||||
|
|
||||||
Recipient.applyCached(Address.fromSerialized(groupId), recipient -> recipient.setGroupAvatarId(avatarId == 0 ? null : avatarId));
|
Recipient.applyCached(Address.fromSerialized(groupID), recipient -> recipient.setGroupAvatarId(avatarId == 0 ? null : avatarId));
|
||||||
}
|
}
|
||||||
|
|
||||||
public void updateMembers(String groupId, List<Address> members) {
|
public void updateMembers(String groupId, List<Address> members) {
|
||||||
|
@ -155,7 +155,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||||||
db.execSQL(LokiAPIDatabase.getCreateSessionRequestSentTimestampTableCommand());
|
db.execSQL(LokiAPIDatabase.getCreateSessionRequestSentTimestampTableCommand());
|
||||||
db.execSQL(LokiAPIDatabase.getCreateSessionRequestProcessedTimestampTableCommand());
|
db.execSQL(LokiAPIDatabase.getCreateSessionRequestProcessedTimestampTableCommand());
|
||||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupPublicKeyTableCommand());
|
db.execSQL(LokiAPIDatabase.getCreateOpenGroupPublicKeyTableCommand());
|
||||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupAvatarCacheCommand());
|
db.execSQL(LokiAPIDatabase.getCreateOpenGroupProfilePictureTableCommand());
|
||||||
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
|
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
|
||||||
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
||||||
db.execSQL(LokiMessageDatabase.getCreateMessageIDTableCommand());
|
db.execSQL(LokiMessageDatabase.getCreateMessageIDTableCommand());
|
||||||
@ -630,7 +630,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (oldVersion < lokiV15) {
|
if (oldVersion < lokiV15) {
|
||||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupAvatarCacheCommand());
|
db.execSQL(LokiAPIDatabase.getCreateOpenGroupProfilePictureTableCommand());
|
||||||
db.execSQL(SharedSenderKeysDatabase.getCreateOldClosedGroupRatchetTableCommand());
|
db.execSQL(SharedSenderKeysDatabase.getCreateOldClosedGroupRatchetTableCommand());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -347,7 +347,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
|||||||
val apiDB = DatabaseFactory.getLokiAPIDatabase(this@HomeActivity)
|
val apiDB = DatabaseFactory.getLokiAPIDatabase(this@HomeActivity)
|
||||||
apiDB.removeLastMessageServerID(publicChat.channel, publicChat.server)
|
apiDB.removeLastMessageServerID(publicChat.channel, publicChat.server)
|
||||||
apiDB.removeLastDeletionServerID(publicChat.channel, publicChat.server)
|
apiDB.removeLastDeletionServerID(publicChat.channel, publicChat.server)
|
||||||
apiDB.clearOpenGroupAvatarURL(publicChat.channel, publicChat.server)
|
apiDB.clearOpenGroupProfilePictureURL(publicChat.channel, publicChat.server)
|
||||||
ApplicationContext.getInstance(this@HomeActivity).publicChatAPI!!.leave(publicChat.channel, publicChat.server)
|
ApplicationContext.getInstance(this@HomeActivity).publicChatAPI!!.leave(publicChat.channel, publicChat.server)
|
||||||
}
|
}
|
||||||
threadDB.deleteConversation(threadID)
|
threadDB.deleteConversation(threadID)
|
||||||
|
@ -14,7 +14,7 @@ import org.thoughtcrime.securesms.groups.GroupManager
|
|||||||
import org.thoughtcrime.securesms.util.BitmapUtil
|
import org.thoughtcrime.securesms.util.BitmapUtil
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||||
import org.thoughtcrime.securesms.util.Util
|
import org.thoughtcrime.securesms.util.Util
|
||||||
import org.whispersystems.signalservice.loki.api.opengroups.LokiPublicChatInfo
|
import org.whispersystems.signalservice.loki.api.opengroups.PublicChatInfo
|
||||||
import org.whispersystems.signalservice.loki.api.opengroups.PublicChat
|
import org.whispersystems.signalservice.loki.api.opengroups.PublicChat
|
||||||
|
|
||||||
class PublicChatManager(private val context: Context) {
|
class PublicChatManager(private val context: Context) {
|
||||||
@ -68,18 +68,18 @@ class PublicChatManager(private val context: Context) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public fun addChat(server: String, channel: Long, info: LokiPublicChatInfo): PublicChat {
|
public fun addChat(server: String, channel: Long, info: PublicChatInfo): PublicChat {
|
||||||
val chat = PublicChat(channel, server, info.displayName, true)
|
val chat = PublicChat(channel, server, info.displayName, true)
|
||||||
var threadID = GroupManager.getOpenGroupThreadID(chat.id, context)
|
var threadID = GroupManager.getOpenGroupThreadID(chat.id, context)
|
||||||
var avatar: Bitmap? = null
|
var profilePicture: Bitmap? = null
|
||||||
// Create the group if we don't have one
|
// Create the group if we don't have one
|
||||||
if (threadID < 0) {
|
if (threadID < 0) {
|
||||||
if (!info.profilePictureURL.isEmpty()) {
|
if (info.profilePictureURL.isNotEmpty()) {
|
||||||
val avatarBytes = ApplicationContext.getInstance(context).publicChatAPI
|
val profilePictureAsByteArray = ApplicationContext.getInstance(context).publicChatAPI
|
||||||
?.downloadOpenGroupAvatar(server, info.profilePictureURL)
|
?.downloadOpenGroupProfilePicture(server, info.profilePictureURL)
|
||||||
avatar = BitmapUtil.fromByteArray(avatarBytes)
|
profilePicture = BitmapUtil.fromByteArray(profilePictureAsByteArray)
|
||||||
}
|
}
|
||||||
val result = GroupManager.createOpenGroup(chat.id, context, avatar, chat.displayName)
|
val result = GroupManager.createOpenGroup(chat.id, context, profilePicture, chat.displayName)
|
||||||
threadID = result.threadId
|
threadID = result.threadId
|
||||||
}
|
}
|
||||||
DatabaseFactory.getLokiThreadDatabase(context).setPublicChat(chat, threadID)
|
DatabaseFactory.getLokiThreadDatabase(context).setPublicChat(chat, threadID)
|
||||||
|
@ -46,7 +46,8 @@ class PublicChatPoller(private val context: Context, private val group: PublicCh
|
|||||||
val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize()
|
val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize()
|
||||||
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
val lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
||||||
val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
||||||
PublicChatAPI(userHexEncodedPublicKey, userPrivateKey, lokiAPIDatabase, lokiUserDatabase)
|
val openGroupDatabase = DatabaseFactory.getGroupDatabase(context)
|
||||||
|
PublicChatAPI(userHexEncodedPublicKey, userPrivateKey, lokiAPIDatabase, lokiUserDatabase, openGroupDatabase)
|
||||||
}()
|
}()
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
|
@ -6,7 +6,6 @@ import android.util.Log
|
|||||||
import org.thoughtcrime.securesms.database.Database
|
import org.thoughtcrime.securesms.database.Database
|
||||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||||
import org.thoughtcrime.securesms.loki.utilities.*
|
import org.thoughtcrime.securesms.loki.utilities.*
|
||||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
|
||||||
import org.whispersystems.signalservice.loki.api.Snode
|
import org.whispersystems.signalservice.loki.api.Snode
|
||||||
import org.whispersystems.signalservice.loki.database.LokiAPIDatabaseProtocol
|
import org.whispersystems.signalservice.loki.database.LokiAPIDatabaseProtocol
|
||||||
import org.whispersystems.signalservice.loki.protocol.shelved.multidevice.DeviceLink
|
import org.whispersystems.signalservice.loki.protocol.shelved.multidevice.DeviceLink
|
||||||
@ -71,10 +70,10 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
|||||||
// Open group public keys
|
// Open group public keys
|
||||||
private val openGroupPublicKeyTable = "open_group_public_keys"
|
private val openGroupPublicKeyTable = "open_group_public_keys"
|
||||||
@JvmStatic val createOpenGroupPublicKeyTableCommand = "CREATE TABLE $openGroupPublicKeyTable ($server STRING PRIMARY KEY, $publicKey INTEGER DEFAULT 0);"
|
@JvmStatic val createOpenGroupPublicKeyTableCommand = "CREATE TABLE $openGroupPublicKeyTable ($server STRING PRIMARY KEY, $publicKey INTEGER DEFAULT 0);"
|
||||||
// Open group avatar cache
|
// Open group profile picture cache
|
||||||
private val openGroupAvatarCacheTable = "open_group_avatar_cache"
|
private val openGroupProfilePictureTable = "open_group_avatar_cache"
|
||||||
private val openGroupAvatar = "open_group_avatar"
|
private val openGroupProfilePicture = "open_group_avatar"
|
||||||
@JvmStatic val createOpenGroupAvatarCacheCommand = "CREATE TABLE $openGroupAvatarCacheTable ($publicChatID STRING PRIMARY KEY, $openGroupAvatar TEXT NULLABLE DEFAULT NULL);"
|
@JvmStatic val createOpenGroupProfilePictureTableCommand = "CREATE TABLE $openGroupProfilePictureTable ($publicChatID STRING PRIMARY KEY, $openGroupProfilePicture TEXT NULLABLE DEFAULT NULL);"
|
||||||
|
|
||||||
// region Deprecated
|
// region Deprecated
|
||||||
private val deviceLinkCache = "loki_pairing_authorisation_cache"
|
private val deviceLinkCache = "loki_pairing_authorisation_cache"
|
||||||
@ -347,25 +346,25 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
|||||||
database.insertOrUpdate(openGroupPublicKeyTable, row, "${LokiAPIDatabase.server} = ?", wrap(server))
|
database.insertOrUpdate(openGroupPublicKeyTable, row, "${LokiAPIDatabase.server} = ?", wrap(server))
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun getOpenGroupAvatarURL(group: Long, server: String): String? {
|
override fun getOpenGroupProfilePictureURL(group: Long, server: String): String? {
|
||||||
val database = databaseHelper.readableDatabase
|
val database = databaseHelper.readableDatabase
|
||||||
val index = "$server.$group"
|
val index = "$server.$group"
|
||||||
return database.get(openGroupAvatarCacheTable, "$publicChatID = ?", wrap(index)) { cursor ->
|
return database.get(openGroupProfilePictureTable, "$publicChatID = ?", wrap(index)) { cursor ->
|
||||||
cursor.getString(openGroupAvatar)
|
cursor.getString(openGroupProfilePicture)
|
||||||
}?.toString()
|
}?.toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun setOpenGroupAvatarURL(group: Long, server: String, url: String) {
|
override fun setOpenGroupProfilePictureURL(group: Long, server: String, newValue: String) {
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
val index = "$server.$group"
|
val index = "$server.$group"
|
||||||
val row = wrap(mapOf(publicChatID to index, openGroupAvatar to url))
|
val row = wrap(mapOf(publicChatID to index, openGroupProfilePicture to newValue))
|
||||||
database.insertOrUpdate(openGroupAvatarCacheTable, row, "$publicChatID = ?", wrap(index))
|
database.insertOrUpdate(openGroupProfilePictureTable, row, "$publicChatID = ?", wrap(index))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun clearOpenGroupAvatarURL(group: Long, server: String): Boolean {
|
fun clearOpenGroupProfilePictureURL(group: Long, server: String): Boolean {
|
||||||
val database = databaseHelper.writableDatabase
|
val database = databaseHelper.writableDatabase
|
||||||
val index = "$server.$group"
|
val index = "$server.$group"
|
||||||
return database.delete(openGroupAvatarCacheTable, "$publicChatID == ?", arrayOf(index)) > 0
|
return database.delete(openGroupProfilePictureTable, "$publicChatID = ?", arrayOf(index)) > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
// region Deprecated
|
// region Deprecated
|
||||||
|
Loading…
x
Reference in New Issue
Block a user