mirror of
https://github.com/oxen-io/session-android.git
synced 2024-11-27 12:05:22 +00:00
parent
3cb7d2169d
commit
48adb63fb7
@ -29,7 +29,7 @@ class ClosedGroupPoller private constructor(private val context: Context, privat
|
||||
|
||||
// region Settings
|
||||
companion object {
|
||||
private val pollInterval: Long = 2 * 1000
|
||||
private val pollInterval: Long = 4 * 1000
|
||||
|
||||
public lateinit var shared: ClosedGroupPoller
|
||||
|
||||
|
@ -9,6 +9,8 @@ import org.thoughtcrime.securesms.loki.utilities.*
|
||||
import org.session.libsignal.service.loki.api.Snode
|
||||
import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol
|
||||
import org.session.libsignal.service.loki.protocol.shelved.multidevice.DeviceLink
|
||||
import org.thoughtcrime.securesms.util.TextSecurePreferences
|
||||
import java.util.*
|
||||
|
||||
class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(context, helper), LokiAPIDatabaseProtocol {
|
||||
|
||||
@ -375,6 +377,16 @@ class LokiAPIDatabase(context: Context, helper: SQLCipherOpenHelper) : Database(
|
||||
return database.delete(openGroupProfilePictureTable, "$publicChatID = ?", arrayOf(index)) > 0
|
||||
}
|
||||
|
||||
override fun getLastSnodePoolRefreshDate(): Date? {
|
||||
val time = TextSecurePreferences.getLastSnodePoolRefreshDate(context)
|
||||
if (time <= 0) { return null }
|
||||
return Date(time)
|
||||
}
|
||||
|
||||
override fun setLastSnodePoolRefreshDate(date: Date) {
|
||||
TextSecurePreferences.setLastSnodePoolRefreshDate(context, date)
|
||||
}
|
||||
|
||||
// region Deprecated
|
||||
override fun getDeviceLinks(publicKey: String): Set<DeviceLink> {
|
||||
return setOf()
|
||||
|
@ -23,6 +23,7 @@ import java.io.IOException;
|
||||
import java.security.SecureRandom;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
import java.util.HashSet;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@ -1237,6 +1238,14 @@ public class TextSecurePreferences {
|
||||
public static void setHasSeenLightThemeIntroSheet(Context context) {
|
||||
setBooleanPreference(context, "has_seen_light_theme_intro_sheet", true);
|
||||
}
|
||||
|
||||
public static long getLastSnodePoolRefreshDate(Context context) {
|
||||
return getLongPreference(context, "last_snode_pool_refresh_date", 0);
|
||||
}
|
||||
|
||||
public static void setLastSnodePoolRefreshDate(Context context, Date date) {
|
||||
setLongPreference(context, "last_snode_pool_refresh_date", date.getTime());
|
||||
}
|
||||
// endregion
|
||||
|
||||
// region Backup related
|
||||
|
@ -11,6 +11,7 @@ import org.session.libsignal.service.loki.database.LokiAPIDatabaseProtocol
|
||||
import org.session.libsignal.service.loki.utilities.getRandomElement
|
||||
import org.session.libsignal.service.loki.utilities.prettifiedDescription
|
||||
import java.security.SecureRandom
|
||||
import java.util.*
|
||||
|
||||
class SwarmAPI private constructor(private val database: LokiAPIDatabaseProtocol) {
|
||||
internal var snodeFailureCount: MutableMap<Snode, Int> = mutableMapOf()
|
||||
@ -46,7 +47,12 @@ class SwarmAPI private constructor(private val database: LokiAPIDatabaseProtocol
|
||||
// region Swarm API
|
||||
internal fun getRandomSnode(): Promise<Snode, Exception> {
|
||||
val snodePool = this.snodePool
|
||||
if (snodePool.count() < minimumSnodePoolCount) {
|
||||
val lastRefreshDate = database.getLastSnodePoolRefreshDate()
|
||||
val now = Date()
|
||||
val needsRefresh = (snodePool.count() < minimumSnodePoolCount) || lastRefreshDate == null || (now.time - lastRefreshDate.time) > 24 * 60 * 60 * 1000
|
||||
if (needsRefresh) {
|
||||
database.setLastSnodePoolRefreshDate(now)
|
||||
|
||||
val target = seedNodePool.random()
|
||||
val url = "$target/json_rpc"
|
||||
Log.d("Loki", "Populating snode pool using: $target.")
|
||||
|
@ -2,6 +2,7 @@ package org.session.libsignal.service.loki.database
|
||||
|
||||
import org.session.libsignal.service.loki.api.Snode
|
||||
import org.session.libsignal.service.loki.protocol.shelved.multidevice.DeviceLink
|
||||
import java.util.*
|
||||
|
||||
interface LokiAPIDatabaseProtocol {
|
||||
|
||||
@ -31,6 +32,9 @@ interface LokiAPIDatabaseProtocol {
|
||||
fun setOpenGroupPublicKey(server: String, newValue: String)
|
||||
fun setOpenGroupProfilePictureURL(group: Long, server: String, newValue: String)
|
||||
fun getOpenGroupProfilePictureURL(group: Long, server: String): String?
|
||||
fun getLastSnodePoolRefreshDate(): Date?
|
||||
fun setLastSnodePoolRefreshDate(newValue: Date)
|
||||
|
||||
|
||||
// region Deprecated
|
||||
fun getDeviceLinks(publicKey: String): Set<DeviceLink>
|
||||
|
Loading…
Reference in New Issue
Block a user