mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-05-11 17:35:01 +00:00
android: fix link preview fetch via SOCKS (#6919)
* android: fix link preview fetch via SOCKS * fix: add timeouts to link preview image fetch Match the 10s timeout already on the Jsoup HTML fetch. Without these, a slow or dead SOCKS proxy hangs the image fetch indefinitely, holding the previewMutex and blocking every subsequent preview. * timeout --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> Co-authored-by: shum <github.shum@liber.li>
This commit is contained in:
+3
-2
@@ -48,7 +48,6 @@ private val previewMutex = Mutex()
|
||||
suspend fun getLinkPreview(url: String): LinkPreview? {
|
||||
return withContext(Dispatchers.IO) {
|
||||
previewMutex.withLock {
|
||||
val previousAuthenticator = Authenticator.getDefault()
|
||||
try {
|
||||
try {
|
||||
val title: String?
|
||||
@@ -121,6 +120,8 @@ suspend fun getLinkPreview(url: String): LinkPreview? {
|
||||
imageUri = normalizeImageUri(u, imageUri)
|
||||
try {
|
||||
val conn = URL(imageUri).openConnection(proxy ?: Proxy.NO_PROXY)
|
||||
conn.connectTimeout = 20_000
|
||||
conn.readTimeout = 20_000
|
||||
val stream = conn.getInputStream()
|
||||
val image = resizeImageToStrSize(stream.use(::loadImageBitmap), maxDataSize = 14000)
|
||||
// TODO add once supported in iOS
|
||||
@@ -139,7 +140,7 @@ suspend fun getLinkPreview(url: String): LinkPreview? {
|
||||
}
|
||||
return@withLock null
|
||||
} finally {
|
||||
Authenticator.setDefault(previousAuthenticator)
|
||||
Authenticator.setDefault(null)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2646,7 +2646,7 @@
|
||||
<string name="v6_5_invite_friends">Easier to invite your friends 👋</string>
|
||||
<string name="v6_5_invite_friends_descr">We made connecting simpler for new users.</string>
|
||||
<string name="v6_5_safe_web_links">Safe web links</string>
|
||||
<string name="v6_5_safe_web_links_descr">- opt-in to send link previews.\n- prevent hyperlink phishing.\n- remove link tracking.</string>
|
||||
<string name="v6_5_safe_web_links_descr">- opt-in to send link previews.\n- use SOCKS proxy if enabled.\n- prevent hyperlink phishing.\n- remove link tracking.</string>
|
||||
<string name="v6_5_non_profit_governance">Non-profit governance</string>
|
||||
<string name="v6_5_non_profit_governance_descr">To make SimpleX Network last.</string>
|
||||
<string name="view_updated_conditions">View updated conditions</string>
|
||||
|
||||
Reference in New Issue
Block a user