mirror of
https://github.com/oxen-io/session-android.git
synced 2024-12-24 16:57:50 +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.database.Cursor;
|
||||
import android.graphics.Bitmap;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.annimon.stream.Stream;
|
||||
|
||||
@ -21,7 +22,7 @@ import org.thoughtcrime.securesms.util.GroupUtil;
|
||||
import org.thoughtcrime.securesms.util.Util;
|
||||
import org.whispersystems.libsignal.util.guava.Optional;
|
||||
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.IOException;
|
||||
@ -30,7 +31,7 @@ import java.util.Collections;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
|
||||
public class GroupDatabase extends Database implements LokiGroupDatabaseProtocol {
|
||||
public class GroupDatabase extends Database implements LokiOpenGroupDatabaseProtocol {
|
||||
|
||||
@SuppressWarnings("unused")
|
||||
private static final String TAG = GroupDatabase.class.getSimpleName();
|
||||
@ -242,36 +243,36 @@ public class GroupDatabase extends Database implements LokiGroupDatabaseProtocol
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateTitle(String groupId, String title) {
|
||||
public void updateTitle(String groupID, String newValue) {
|
||||
ContentValues contentValues = new ContentValues();
|
||||
contentValues.put(TITLE, title);
|
||||
contentValues.put(TITLE, newValue);
|
||||
databaseHelper.getWritableDatabase().update(TABLE_NAME, contentValues, GROUP_ID + " = ?",
|
||||
new String[] {groupId});
|
||||
new String[] {groupID});
|
||||
|
||||
Recipient recipient = Recipient.from(context, Address.fromSerialized(groupId), false);
|
||||
recipient.setName(title);
|
||||
Recipient recipient = Recipient.from(context, Address.fromSerialized(groupID), false);
|
||||
recipient.setName(newValue);
|
||||
}
|
||||
|
||||
public void updateAvatar(String groupId, Bitmap avatar) {
|
||||
updateAvatar(groupId, BitmapUtil.toByteArray(avatar));
|
||||
public void updateProfilePicture(String groupID, Bitmap newValue) {
|
||||
updateProfilePicture(groupID, BitmapUtil.toByteArray(newValue));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateAvatar(String groupId, byte[] avatar) {
|
||||
public void updateProfilePicture(String groupID, byte[] newValue) {
|
||||
long avatarId;
|
||||
|
||||
if (avatar != null) avatarId = Math.abs(new SecureRandom().nextLong());
|
||||
if (newValue != null) avatarId = Math.abs(new SecureRandom().nextLong());
|
||||
else avatarId = 0;
|
||||
|
||||
|
||||
ContentValues contentValues = new ContentValues(2);
|
||||
contentValues.put(AVATAR, avatar);
|
||||
contentValues.put(AVATAR, newValue);
|
||||
contentValues.put(AVATAR_ID, avatarId);
|
||||
|
||||
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) {
|
||||
|
@ -155,7 +155,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
db.execSQL(LokiAPIDatabase.getCreateSessionRequestSentTimestampTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateSessionRequestProcessedTimestampTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupPublicKeyTableCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupAvatarCacheCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupProfilePictureTableCommand());
|
||||
db.execSQL(LokiPreKeyBundleDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiPreKeyRecordDatabase.getCreateTableCommand());
|
||||
db.execSQL(LokiMessageDatabase.getCreateMessageIDTableCommand());
|
||||
@ -630,7 +630,7 @@ public class SQLCipherOpenHelper extends SQLiteOpenHelper {
|
||||
}
|
||||
|
||||
if (oldVersion < lokiV15) {
|
||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupAvatarCacheCommand());
|
||||
db.execSQL(LokiAPIDatabase.getCreateOpenGroupProfilePictureTableCommand());
|
||||
db.execSQL(SharedSenderKeysDatabase.getCreateOldClosedGroupRatchetTableCommand());
|
||||
}
|
||||
|
||||
|
@ -347,7 +347,7 @@ class HomeActivity : PassphraseRequiredActionBarActivity, ConversationClickListe
|
||||
val apiDB = DatabaseFactory.getLokiAPIDatabase(this@HomeActivity)
|
||||
apiDB.removeLastMessageServerID(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)
|
||||
}
|
||||
threadDB.deleteConversation(threadID)
|
||||
|
@ -14,7 +14,7 @@ import org.thoughtcrime.securesms.groups.GroupManager
|
||||
import org.thoughtcrime.securesms.util.BitmapUtil
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
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
|
||||
|
||||
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)
|
||||
var threadID = GroupManager.getOpenGroupThreadID(chat.id, context)
|
||||
var avatar: Bitmap? = null
|
||||
var profilePicture: Bitmap? = null
|
||||
// Create the group if we don't have one
|
||||
if (threadID < 0) {
|
||||
if (!info.profilePictureURL.isEmpty()) {
|
||||
val avatarBytes = ApplicationContext.getInstance(context).publicChatAPI
|
||||
?.downloadOpenGroupAvatar(server, info.profilePictureURL)
|
||||
avatar = BitmapUtil.fromByteArray(avatarBytes)
|
||||
if (info.profilePictureURL.isNotEmpty()) {
|
||||
val profilePictureAsByteArray = ApplicationContext.getInstance(context).publicChatAPI
|
||||
?.downloadOpenGroupProfilePicture(server, info.profilePictureURL)
|
||||
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
|
||||
}
|
||||
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 lokiAPIDatabase = DatabaseFactory.getLokiAPIDatabase(context)
|
||||
val lokiUserDatabase = DatabaseFactory.getLokiUserDatabase(context)
|
||||
PublicChatAPI(userHexEncodedPublicKey, userPrivateKey, lokiAPIDatabase, lokiUserDatabase)
|
||||
val openGroupDatabase = DatabaseFactory.getGroupDatabase(context)
|
||||
PublicChatAPI(userHexEncodedPublicKey, userPrivateKey, lokiAPIDatabase, lokiUserDatabase, openGroupDatabase)
|
||||
}()
|
||||
// endregion
|
||||
|
||||
|
@ -6,7 +6,6 @@ import android.util.Log
|
||||
import org.thoughtcrime.securesms.database.Database
|
||||
import org.thoughtcrime.securesms.database.helpers.SQLCipherOpenHelper
|
||||
import org.thoughtcrime.securesms.loki.utilities.*
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import org.whispersystems.signalservice.loki.api.Snode
|
||||
import org.whispersystems.signalservice.loki.database.LokiAPIDatabaseProtocol
|
||||
import org.whispersystems.signalservice.loki.protocol.shelved.multidevice.DeviceLink
|
||||
@ -71,10 +70,10 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
// 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);"
|
||||
// Open group avatar cache
|
||||
private val openGroupAvatarCacheTable = "open_group_avatar_cache"
|
||||
private val openGroupAvatar = "open_group_avatar"
|
||||
@JvmStatic val createOpenGroupAvatarCacheCommand = "CREATE TABLE $openGroupAvatarCacheTable ($publicChatID STRING PRIMARY KEY, $openGroupAvatar TEXT NULLABLE DEFAULT NULL);"
|
||||
// Open group profile picture cache
|
||||
private val openGroupProfilePictureTable = "open_group_avatar_cache"
|
||||
private val openGroupProfilePicture = "open_group_avatar"
|
||||
@JvmStatic val createOpenGroupProfilePictureTableCommand = "CREATE TABLE $openGroupProfilePictureTable ($publicChatID STRING PRIMARY KEY, $openGroupProfilePicture TEXT NULLABLE DEFAULT NULL);"
|
||||
|
||||
// region Deprecated
|
||||
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))
|
||||
}
|
||||
|
||||
override fun getOpenGroupAvatarURL(group: Long, server: String): String? {
|
||||
override fun getOpenGroupProfilePictureURL(group: Long, server: String): String? {
|
||||
val database = databaseHelper.readableDatabase
|
||||
val index = "$server.$group"
|
||||
return database.get(openGroupAvatarCacheTable, "$publicChatID = ?", wrap(index)) { cursor ->
|
||||
cursor.getString(openGroupAvatar)
|
||||
return database.get(openGroupProfilePictureTable, "$publicChatID = ?", wrap(index)) { cursor ->
|
||||
cursor.getString(openGroupProfilePicture)
|
||||
}?.toString()
|
||||
}
|
||||
|
||||
override fun setOpenGroupAvatarURL(group: Long, server: String, url: String) {
|
||||
override fun setOpenGroupProfilePictureURL(group: Long, server: String, newValue: String) {
|
||||
val database = databaseHelper.writableDatabase
|
||||
val index = "$server.$group"
|
||||
val row = wrap(mapOf(publicChatID to index, openGroupAvatar to url))
|
||||
database.insertOrUpdate(openGroupAvatarCacheTable, row, "$publicChatID = ?", wrap(index))
|
||||
val row = wrap(mapOf(publicChatID to index, openGroupProfilePicture to newValue))
|
||||
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 index = "$server.$group"
|
||||
return database.delete(openGroupAvatarCacheTable, "$publicChatID == ?", arrayOf(index)) > 0
|
||||
return database.delete(openGroupProfilePictureTable, "$publicChatID = ?", arrayOf(index)) > 0
|
||||
}
|
||||
|
||||
// region Deprecated
|
||||
|
Loading…
x
Reference in New Issue
Block a user