mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-24 02:25:19 +00:00
feat: open group attachment and message processing
This commit is contained in:
parent
6272856ef9
commit
4bf0990ef9
@ -576,6 +576,13 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
|
|||||||
return if (threadID < 0) null else threadID
|
return if (threadID < 0) null else threadID
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun getThreadIdForMms(mmsId: Long): Long {
|
||||||
|
val mmsDb = DatabaseFactory.getMmsDatabase(context)
|
||||||
|
val cursor = mmsDb.getMessage(mmsId)
|
||||||
|
val reader = mmsDb.readerFor(cursor)
|
||||||
|
return reader.current.threadId
|
||||||
|
}
|
||||||
|
|
||||||
override fun getSessionRequestSentTimestamp(publicKey: String): Long? {
|
override fun getSessionRequestSentTimestamp(publicKey: String): Long? {
|
||||||
return DatabaseFactory.getLokiAPIDatabase(context).getSessionRequestSentTimestamp(publicKey)
|
return DatabaseFactory.getLokiAPIDatabase(context).getSessionRequestSentTimestamp(publicKey)
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,7 @@ class PublicChatManager(private val context: Context) {
|
|||||||
fun addChat(server: String, room: String, info: OpenGroupAPIV2.Info, publicKey: String): OpenGroupV2 {
|
fun addChat(server: String, room: String, info: OpenGroupAPIV2.Info, publicKey: String): OpenGroupV2 {
|
||||||
val chat = OpenGroupV2(server, room, info.name, publicKey)
|
val chat = OpenGroupV2(server, room, info.name, publicKey)
|
||||||
var threadID = GroupManager.getOpenGroupThreadID(chat.id, context)
|
var threadID = GroupManager.getOpenGroupThreadID(chat.id, context)
|
||||||
var profilePicture: Bitmap? = null
|
val profilePicture: Bitmap?
|
||||||
if (threadID < 0) {
|
if (threadID < 0) {
|
||||||
val profilePictureAsByteArray = try {
|
val profilePictureAsByteArray = try {
|
||||||
OpenGroupAPIV2.downloadOpenGroupProfilePicture(info.id,server).get()
|
OpenGroupAPIV2.downloadOpenGroupProfilePicture(info.id,server).get()
|
||||||
|
@ -136,6 +136,7 @@ interface StorageProtocol {
|
|||||||
fun getOrCreateThreadIdFor(address: Address): Long
|
fun getOrCreateThreadIdFor(address: Address): Long
|
||||||
fun getOrCreateThreadIdFor(publicKey: String, groupPublicKey: String?, openGroupID: String?): Long
|
fun getOrCreateThreadIdFor(publicKey: String, groupPublicKey: String?, openGroupID: String?): Long
|
||||||
fun getThreadIdFor(address: Address): Long?
|
fun getThreadIdFor(address: Address): Long?
|
||||||
|
fun getThreadIdForMms(messageId: Long): Long
|
||||||
|
|
||||||
// Session Request
|
// Session Request
|
||||||
fun getSessionRequestSentTimestamp(publicKey: String): Long?
|
fun getSessionRequestSentTimestamp(publicKey: String): Long?
|
||||||
|
@ -53,6 +53,11 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
|
|||||||
messageDataProvider.setAttachmentState(AttachmentState.STARTED, attachmentID, this.databaseMessageID)
|
messageDataProvider.setAttachmentState(AttachmentState.STARTED, attachmentID, this.databaseMessageID)
|
||||||
val tempFile = createTempFile()
|
val tempFile = createTempFile()
|
||||||
|
|
||||||
|
val threadId = MessagingConfiguration.shared.storage.getThreadIdForMms(databaseMessageID)
|
||||||
|
val openGroupV2 = MessagingConfiguration.shared.storage.getV2OpenGroup(threadId.toString())
|
||||||
|
|
||||||
|
val isOpenGroupV2 = false
|
||||||
|
if (!isOpenGroupV2) {
|
||||||
FileServerAPI.shared.downloadFile(tempFile, attachment.url, MAX_ATTACHMENT_SIZE, null)
|
FileServerAPI.shared.downloadFile(tempFile, attachment.url, MAX_ATTACHMENT_SIZE, null)
|
||||||
|
|
||||||
// DECRYPTION
|
// DECRYPTION
|
||||||
@ -62,6 +67,9 @@ class AttachmentDownloadJob(val attachmentID: Long, val databaseMessageID: Long)
|
|||||||
else AttachmentCipherInputStream.createForAttachment(tempFile, attachment.size, Base64.decode(attachment.key), attachment.digest)
|
else AttachmentCipherInputStream.createForAttachment(tempFile, attachment.size, Base64.decode(attachment.key), attachment.digest)
|
||||||
|
|
||||||
messageDataProvider.insertAttachment(databaseMessageID, attachment.attachmentId, stream)
|
messageDataProvider.insertAttachment(databaseMessageID, attachment.attachmentId, stream)
|
||||||
|
} else {
|
||||||
|
// val bytes = OpenGroupAPIV2.download()
|
||||||
|
}
|
||||||
|
|
||||||
tempFile.delete()
|
tempFile.delete()
|
||||||
handleSuccess()
|
handleSuccess()
|
||||||
|
@ -350,6 +350,10 @@ object OpenGroupAPIV2 {
|
|||||||
val storage = MessagingConfiguration.shared.storage
|
val storage = MessagingConfiguration.shared.storage
|
||||||
storage.setOpenGroupPublicKey(DEFAULT_SERVER, DEFAULT_SERVER_PUBLIC_KEY)
|
storage.setOpenGroupPublicKey(DEFAULT_SERVER, DEFAULT_SERVER_PUBLIC_KEY)
|
||||||
return getAllRooms(DEFAULT_SERVER).map { groups ->
|
return getAllRooms(DEFAULT_SERVER).map { groups ->
|
||||||
|
val earlyGroups = groups.map { group ->
|
||||||
|
DefaultGroup(group.id, group.name, null)
|
||||||
|
}
|
||||||
|
defaultRooms.tryEmit(earlyGroups) // TODO: take into account cached w/ images groups
|
||||||
val images = groups.map { group ->
|
val images = groups.map { group ->
|
||||||
group.id to downloadOpenGroupProfilePicture(group.id, DEFAULT_SERVER)
|
group.id to downloadOpenGroupProfilePicture(group.id, DEFAULT_SERVER)
|
||||||
}.toMap()
|
}.toMap()
|
||||||
|
Loading…
Reference in New Issue
Block a user