fix send text message to open group

This commit is contained in:
Ryan ZHAO 2021-03-02 14:13:12 +11:00
parent d9eaedd6ae
commit 8acbb3c366
6 changed files with 11 additions and 11 deletions

View File

@ -425,6 +425,7 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
byte[] userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).getPrivateKey().serialize(); byte[] userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(this).getPrivateKey().serialize();
LokiAPIDatabaseProtocol apiDB = DatabaseFactory.getLokiAPIDatabase(this); LokiAPIDatabaseProtocol apiDB = DatabaseFactory.getLokiAPIDatabase(this);
FileServerAPI.Companion.configure(userPublicKey, userPrivateKey, apiDB); FileServerAPI.Companion.configure(userPublicKey, userPrivateKey, apiDB);
org.session.libsession.messaging.fileserver.FileServerAPI.Companion.configure(userPublicKey, userPrivateKey, apiDB);
return true; return true;
} }

View File

@ -354,15 +354,15 @@ class Storage(context: Context, helper: SQLCipherOpenHelper) : Database(context,
} }
} }
override fun setErrorMessage(messageID: Long, error: Exception) { override fun setErrorMessage(timestamp: Long, author: String, error: Exception) {
val database = DatabaseFactory.getMmsSmsDatabase(context) val database = DatabaseFactory.getMmsSmsDatabase(context)
val messageRecord = database.getMessageFor(messageID) ?: return val messageRecord = database.getMessageFor(timestamp, author) ?: return
if (messageRecord.isMms) { if (messageRecord.isMms) {
val mmsDatabase = DatabaseFactory.getMmsDatabase(context) val mmsDatabase = DatabaseFactory.getMmsDatabase(context)
mmsDatabase.markAsSentFailed(messageID) mmsDatabase.markAsSentFailed(messageRecord.getId())
} else { } else {
val smsDatabase = DatabaseFactory.getSmsDatabase(context) val smsDatabase = DatabaseFactory.getSmsDatabase(context)
smsDatabase.markAsSentFailed(messageID) smsDatabase.markAsSentFailed(messageRecord.getId())
} }
} }

View File

@ -97,7 +97,7 @@ interface StorageProtocol {
fun setOpenGroupServerMessageID(messageID: Long, serverID: Long) fun setOpenGroupServerMessageID(messageID: Long, serverID: Long)
fun markAsSent(timestamp: Long, author: String) fun markAsSent(timestamp: Long, author: String)
fun markUnidentified(timestamp: Long, author: String) fun markUnidentified(timestamp: Long, author: String)
fun setErrorMessage(messageID: Long, error: Exception) fun setErrorMessage(timestamp: Long, author: String, error: Exception)
// Closed Groups // Closed Groups
fun getGroup(groupID: String): GroupRecord? fun getGroup(groupID: String): GroupRecord?

View File

@ -19,7 +19,8 @@ sealed class Destination {
val groupPublicKey = GroupUtil.getDecodedGroupID(groupID) val groupPublicKey = GroupUtil.getDecodedGroupID(groupID)
return ClosedGroup(groupPublicKey) return ClosedGroup(groupPublicKey)
} else if (address.isOpenGroup) { } else if (address.isOpenGroup) {
val openGroup = MessagingConfiguration.shared.storage.getOpenGroup(address.contactIdentifier())!! val threadID = MessagingConfiguration.shared.storage.getThreadID(address.contactIdentifier())!!
val openGroup = MessagingConfiguration.shared.storage.getOpenGroup(threadID)!!
return OpenGroup(openGroup.channel, openGroup.server) return OpenGroup(openGroup.channel, openGroup.server)
} else { } else {
throw Exception("TODO: Handle legacy closed groups.") throw Exception("TODO: Handle legacy closed groups.")

View File

@ -209,8 +209,7 @@ object OpenGroupAPI: DotNetAPI() {
format.timeZone = TimeZone.getTimeZone("GMT") format.timeZone = TimeZone.getTimeZone("GMT")
val dateAsString = data["created_at"] as String val dateAsString = data["created_at"] as String
val timestamp = format.parse(dateAsString).time val timestamp = format.parse(dateAsString).time
@Suppress("NAME_SHADOWING") val message = OpenGroupMessage(serverID, userKeyPair.first, userDisplayName, text, timestamp, openGroupMessageType, message.quote, message.attachments, null, signedMessage.signature, timestamp) OpenGroupMessage(serverID, userKeyPair.first, userDisplayName, text, timestamp, openGroupMessageType, message.quote, message.attachments, null, signedMessage.signature, timestamp)
message
} catch (exception: Exception) { } catch (exception: Exception) {
Log.d("Loki", "Couldn't parse message for open group with ID: $channel on server: $server.") Log.d("Loki", "Couldn't parse message for open group with ID: $channel on server: $server.")
throw exception throw exception

View File

@ -68,7 +68,7 @@ object MessageSender {
attachment.caption = signalAttachment.caption attachment.caption = signalAttachment.caption
attachment.contentType = signalAttachment.contentType attachment.contentType = signalAttachment.contentType
attachment.digest = signalAttachment.digest attachment.digest = signalAttachment.digest
attachment.key = Base64.decode(signalAttachment.key) attachment.key = Base64.decode(signalAttachment.key ?: "")
attachment.sizeInBytes = signalAttachment.size.toInt() attachment.sizeInBytes = signalAttachment.size.toInt()
attachment.url = signalAttachment.url attachment.url = signalAttachment.url
attachment.size = Size(signalAttachment.width, signalAttachment.height) attachment.size = Size(signalAttachment.width, signalAttachment.height)
@ -298,8 +298,7 @@ object MessageSender {
fun handleFailedMessageSend(message: Message, error: Exception) { fun handleFailedMessageSend(message: Message, error: Exception) {
val storage = MessagingConfiguration.shared.storage val storage = MessagingConfiguration.shared.storage
val messageId = storage.getMessageIdInDatabase(message.sentTimestamp!!, message.sender!!) ?: return storage.setErrorMessage(message.sentTimestamp!!, message.sender!!, error)
storage.setErrorMessage(messageId, error)
SnodeConfiguration.shared.broadcaster.broadcast("messageFailed", message.sentTimestamp!!) SnodeConfiguration.shared.broadcaster.broadcast("messageFailed", message.sentTimestamp!!)
} }