diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatInfoUpdateWorker.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatInfoUpdateWorker.kt index 40955d86c5..c8f1a1f215 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatInfoUpdateWorker.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatInfoUpdateWorker.kt @@ -2,9 +2,9 @@ package org.thoughtcrime.securesms.loki.api import android.content.Context import androidx.work.* +import org.session.libsession.messaging.open_groups.OpenGroup import org.session.libsignal.utilities.logging.Log import org.thoughtcrime.securesms.loki.utilities.OpenGroupUtilities -import org.session.libsignal.service.loki.api.opengroups.PublicChat /** * Delegates the [OpenGroupUtilities.updateGroupInfo] call to the work manager. @@ -40,7 +40,7 @@ class PublicChatInfoUpdateWorker(val context: Context, params: WorkerParameters) val serverUrl = inputData.getString(DATA_KEY_SERVER_URL)!! val channel = inputData.getLong(DATA_KEY_CHANNEL, -1) - val publicChatId = PublicChat.getId(channel, serverUrl) + val publicChatId = OpenGroup.getId(channel, serverUrl) return try { Log.v(TAG, "Updating open group info for $publicChatId.") diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatManager.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatManager.kt index a7726bfee3..6586c45013 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatManager.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PublicChatManager.kt @@ -12,7 +12,6 @@ import org.session.libsession.messaging.open_groups.OpenGroupInfo import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPoller import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.Util -import org.session.libsignal.service.loki.api.opengroups.PublicChat import org.thoughtcrime.securesms.database.DatabaseContentProviders import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.groups.GroupManager @@ -75,7 +74,7 @@ class PublicChatManager(private val context: Context) { @WorkerThread public fun addChat(server: String, channel: Long, info: OpenGroupInfo): OpenGroup { - val chat = PublicChat(channel, server, info.displayName, true) + val chat = OpenGroup(channel, server, info.displayName, true) var threadID = GroupManager.getOpenGroupThreadID(chat.id, context) var profilePicture: Bitmap? = null // Create the group if we don't have one @@ -96,12 +95,12 @@ class PublicChatManager(private val context: Context) { // Start polling Util.runOnMain { startPollersIfNeeded() } - return OpenGroup.from(chat) + return chat } public fun removeChat(server: String, channel: Long) { val threadDB = DatabaseFactory.getThreadDatabase(context) - val groupId = PublicChat.getId(channel, server) + val groupId = OpenGroup.getId(channel, server) val threadId = GroupManager.getOpenGroupThreadID(groupId, context) val groupAddress = threadDB.getRecipientForThreadId(threadId)!!.address.serialize() GroupManager.deleteGroup(groupAddress, context) diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt index 0f5244ae19..5e5305103a 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/api/PushNotificationService.kt @@ -6,8 +6,8 @@ import com.google.firebase.messaging.FirebaseMessagingService import com.google.firebase.messaging.RemoteMessage import org.session.libsession.messaging.jobs.JobQueue import org.session.libsession.messaging.jobs.MessageReceiveJob +import org.session.libsession.messaging.utilities.MessageWrapper import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.service.loki.api.MessageWrapper import org.session.libsignal.utilities.Base64 import org.session.libsignal.utilities.logging.Log import org.thoughtcrime.securesms.notifications.NotificationChannels @@ -27,7 +27,7 @@ class PushNotificationService : FirebaseMessagingService() { val data = base64EncodedData?.let { Base64.decode(it) } if (data != null) { try { - JobQueue.shared.add(MessageReceiveJob(MessageWrapper.unwrap(data).toByteArray(),true)) + JobQueue.shared.add(MessageReceiveJob(MessageWrapper.unwrap(data),true)) } catch (e: Exception) { Log.d("Loki", "Failed to unwrap data for message due to error: $e.") } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiThreadDatabase.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiThreadDatabase.kt index 0c2dff9a80..3f13eef929 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiThreadDatabase.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/database/LokiThreadDatabase.kt @@ -3,6 +3,7 @@ package org.thoughtcrime.securesms.loki.database import android.content.ContentValues import android.content.Context import android.database.Cursor +import org.session.libsession.messaging.open_groups.OpenGroup import org.thoughtcrime.securesms.database.Database import org.thoughtcrime.securesms.database.DatabaseFactory @@ -12,13 +13,11 @@ import org.thoughtcrime.securesms.loki.utilities.* import org.session.libsession.messaging.threads.Address import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.service.loki.api.opengroups.PublicChat import org.session.libsignal.utilities.JsonUtil -import org.session.libsignal.service.loki.database.LokiThreadDatabaseProtocol import org.session.libsignal.service.loki.utilities.PublicKeyValidation -class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiThreadDatabaseProtocol { +class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper) { companion object { private val sessionResetTable = "loki_thread_session_reset_database" @@ -31,22 +30,22 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa @JvmStatic val createPublicChatTableCommand = "CREATE TABLE $publicChatTable ($threadID INTEGER PRIMARY KEY, $publicChat TEXT);" } - override fun getThreadID(hexEncodedPublicKey: String): Long { + fun getThreadID(hexEncodedPublicKey: String): Long { val address = Address.fromSerialized(hexEncodedPublicKey) val recipient = Recipient.from(context, address, false) return DatabaseFactory.getThreadDatabase(context).getOrCreateThreadIdFor(recipient) } - fun getAllPublicChats(): Map { + fun getAllPublicChats(): Map { val database = databaseHelper.readableDatabase var cursor: Cursor? = null - val result = mutableMapOf() + val result = mutableMapOf() try { cursor = database.rawQuery("select * from $publicChatTable", null) while (cursor != null && cursor.moveToNext()) { val threadID = cursor.getLong(threadID) val string = cursor.getString(publicChat) - val publicChat = PublicChat.fromJSON(string) + val publicChat = OpenGroup.fromJSON(string) if (publicChat != null) { result[threadID] = publicChat } } } catch (e: Exception) { @@ -61,16 +60,16 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa return getAllPublicChats().values.fold(setOf()) { set, chat -> set.plus(chat.server) } } - override fun getPublicChat(threadID: Long): PublicChat? { + fun getPublicChat(threadID: Long): OpenGroup? { if (threadID < 0) { return null } val database = databaseHelper.readableDatabase return database.get(publicChatTable, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) { cursor -> val publicChatAsJSON = cursor.getString(publicChat) - PublicChat.fromJSON(publicChatAsJSON) + OpenGroup.fromJSON(publicChatAsJSON) } } - override fun setPublicChat(publicChat: PublicChat, threadID: Long) { + fun setPublicChat(publicChat: OpenGroup, threadID: Long) { if (threadID < 0) { return } val database = databaseHelper.writableDatabase val contentValues = ContentValues(2) @@ -79,7 +78,7 @@ class LokiThreadDatabase(context: Context, helper: SQLCipherOpenHelper) : Databa database.insertOrUpdate(publicChatTable, contentValues, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) } - override fun removePublicChat(threadID: Long) { + fun removePublicChat(threadID: Long) { databaseHelper.writableDatabase.delete(publicChatTable, "${Companion.threadID} = ?", arrayOf( threadID.toString() )) } } \ No newline at end of file diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MentionManagerUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MentionManagerUtilities.kt index f59bc7b71a..7d5503c8fc 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MentionManagerUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/MentionManagerUtilities.kt @@ -1,10 +1,10 @@ package org.thoughtcrime.securesms.loki.utilities import android.content.Context +import org.session.libsession.messaging.mentions.MentionsManager import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.database.model.MessageRecord import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.service.loki.utilities.mentions.MentionsManager object MentionManagerUtilities { diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt index 9f5bad1f00..8a5f8f6bd0 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/utilities/OpenGroupUtilities.kt @@ -8,7 +8,6 @@ import org.session.libsession.messaging.open_groups.OpenGroupAPI import org.session.libsession.utilities.GroupUtil import org.session.libsession.utilities.TextSecurePreferences import org.session.libsession.utilities.preferences.ProfileKeyUtil -import org.session.libsignal.service.loki.api.opengroups.PublicChat import org.thoughtcrime.securesms.ApplicationContext import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.groups.GroupManager @@ -23,10 +22,10 @@ object OpenGroupUtilities { @Throws(Exception::class) fun addGroup(context: Context, url: String, channel: Long): OpenGroup { // Check for an existing group. - val groupID = PublicChat.getId(channel, url) + val groupID = OpenGroup.getId(channel, url) val threadID = GroupManager.getOpenGroupThreadID(groupID, context) val openGroup = DatabaseFactory.getLokiThreadDatabase(context).getPublicChat(threadID) - if (openGroup != null) { return OpenGroup.from(openGroup) } + if (openGroup != null) { return openGroup } // Add the new group. val application = ApplicationContext.getInstance(context) @@ -56,7 +55,7 @@ object OpenGroupUtilities { @Throws(Exception::class) fun updateGroupInfo(context: Context, url: String, channel: Long) { // Check if open group has a related DB record. - val groupId = GroupUtil.getEncodedOpenGroupID(PublicChat.getId(channel, url).toByteArray()) + val groupId = GroupUtil.getEncodedOpenGroupID(OpenGroup.getId(channel, url).toByteArray()) if (!DatabaseFactory.getGroupDatabase(context).hasGroup(groupId)) { throw IllegalStateException("Attempt to update open group info for non-existent DB record: $groupId") } diff --git a/app/src/main/java/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt b/app/src/main/java/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt index a092841633..c731a354d2 100644 --- a/app/src/main/java/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt +++ b/app/src/main/java/org/thoughtcrime/securesms/loki/views/ProfilePictureView.kt @@ -11,10 +11,10 @@ import com.bumptech.glide.load.engine.DiskCacheStrategy import kotlinx.android.synthetic.main.view_profile_picture.view.* import network.loki.messenger.R import org.session.libsession.messaging.avatars.ProfileContactPhoto +import org.session.libsession.messaging.mentions.MentionsManager import org.session.libsession.messaging.threads.Address import org.session.libsession.messaging.threads.recipients.Recipient import org.session.libsession.utilities.TextSecurePreferences -import org.session.libsignal.service.loki.utilities.mentions.MentionsManager import org.thoughtcrime.securesms.database.DatabaseFactory import org.thoughtcrime.securesms.loki.utilities.AvatarPlaceholderGenerator import org.thoughtcrime.securesms.mms.GlideRequests