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();
LokiAPIDatabaseProtocol apiDB = DatabaseFactory.getLokiAPIDatabase(this);
FileServerAPI.Companion.configure(userPublicKey, userPrivateKey, apiDB);
org.session.libsession.messaging.fileserver.FileServerAPI.Companion.configure(userPublicKey, userPrivateKey, apiDB);
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 messageRecord = database.getMessageFor(messageID) ?: return
val messageRecord = database.getMessageFor(timestamp, author) ?: return
if (messageRecord.isMms) {
val mmsDatabase = DatabaseFactory.getMmsDatabase(context)
mmsDatabase.markAsSentFailed(messageID)
mmsDatabase.markAsSentFailed(messageRecord.getId())
} else {
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 markAsSent(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
fun getGroup(groupID: String): GroupRecord?

View File

@ -19,7 +19,8 @@ sealed class Destination {
val groupPublicKey = GroupUtil.getDecodedGroupID(groupID)
return ClosedGroup(groupPublicKey)
} 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)
} else {
throw Exception("TODO: Handle legacy closed groups.")

View File

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

View File

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