Merge remote-tracking branch 'upstream/dev' into message-request-response

# Conflicts:
#	app/src/main/java/org/thoughtcrime/securesms/database/Storage.kt
#	libsession/src/main/java/org/session/libsession/messaging/sending_receiving/MessageSender.kt
This commit is contained in:
Morgan Pretty
2023-01-24 14:44:56 +11:00
534 changed files with 7258 additions and 5873 deletions

View File

@@ -16,8 +16,10 @@ interface LokiAPIDatabaseProtocol {
fun setSwarm(publicKey: String, newValue: Set<Snode>)
fun getLastMessageHashValue(snode: Snode, publicKey: String, namespace: Int): String?
fun setLastMessageHashValue(snode: Snode, publicKey: String, newValue: String, namespace: Int)
fun clearAllLastMessageHashes()
fun getReceivedMessageHashValues(publicKey: String, namespace: Int): Set<String>?
fun setReceivedMessageHashValues(publicKey: String, newValue: Set<String>, namespace: Int)
fun clearReceivedMessageHashValues()
fun getAuthToken(server: String): String?
fun setAuthToken(server: String, newValue: String?)
fun setUserCount(room: String, server: String, newValue: Int)

View File

@@ -12,6 +12,7 @@ import javax.net.ssl.SSLContext
import javax.net.ssl.X509TrustManager
object HTTP {
var isConnectedToNetwork: (() -> Boolean) = { false }
private val seedNodeConnection by lazy {
OkHttpClient().newBuilder()
@@ -64,8 +65,12 @@ object HTTP {
private const val timeout: Long = 120
class HTTPRequestFailedException(val statusCode: Int, val json: Map<*, *>?)
: kotlin.Exception("HTTP request failed with status code $statusCode.")
open class HTTPRequestFailedException(
val statusCode: Int,
val json: Map<*, *>?,
message: String = "HTTP request failed with status code $statusCode"
) : kotlin.Exception(message)
class HTTPNoNetworkException : HTTPRequestFailedException(0, null, "No network connection")
enum class Verb(val rawValue: String) {
GET("GET"), PUT("PUT"), POST("POST"), DELETE("DELETE")
@@ -120,8 +125,11 @@ object HTTP {
response = connection.newCall(request.build()).execute()
} catch (exception: Exception) {
Log.d("Loki", "${verb.rawValue} request to $url failed due to error: ${exception.localizedMessage}.")
if (!isConnectedToNetwork()) { throw HTTPNoNetworkException() }
// Override the actual error so that we can correctly catch failed requests in OnionRequestAPI
throw HTTPRequestFailedException(0, null)
throw HTTPRequestFailedException(0, null, "HTTP request failed due to: ${exception.message}")
}
return when (val statusCode = response.code()) {
200 -> {