mirror of
https://github.com/oxen-io/session-android.git
synced 2025-01-11 23:33:39 +00:00
Simplify & fix from_server_id
usage
This commit is contained in:
parent
716e768dac
commit
639146cc0a
@ -205,11 +205,11 @@ public class ApplicationContext extends MultiDexApplication implements Dependenc
|
|||||||
contactDB.setContact(contact);
|
contactDB.setContact(contact);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (poller != null) {
|
if (poller != null) {
|
||||||
poller.setCaughtUp(false);
|
poller.setCaughtUp(false);
|
||||||
}
|
}
|
||||||
startPollingIfNeeded();
|
startPollingIfNeeded();
|
||||||
|
|
||||||
OpenGroupManager.INSTANCE.setAllCaughtUp(false);
|
OpenGroupManager.INSTANCE.setAllCaughtUp(false);
|
||||||
OpenGroupManager.INSTANCE.startPolling();
|
OpenGroupManager.INSTANCE.startPolling();
|
||||||
}
|
}
|
||||||
|
@ -66,8 +66,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
// region Lifecycle
|
// region Lifecycle
|
||||||
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
override fun onCreate(savedInstanceState: Bundle?, isReady: Boolean) {
|
||||||
super.onCreate(savedInstanceState, isReady)
|
super.onCreate(savedInstanceState, isReady)
|
||||||
// Check when Session was last opened
|
|
||||||
setPollingLimit();
|
|
||||||
// Double check that the long poller is up
|
// Double check that the long poller is up
|
||||||
(applicationContext as ApplicationContext).startPollingIfNeeded()
|
(applicationContext as ApplicationContext).startPollingIfNeeded()
|
||||||
// Set content view
|
// Set content view
|
||||||
@ -192,15 +190,6 @@ class HomeActivity : PassphraseRequiredActionBarActivity(),
|
|||||||
super.onDestroy()
|
super.onDestroy()
|
||||||
EventBus.getDefault().unregister(this)
|
EventBus.getDefault().unregister(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setPollingLimit() {
|
|
||||||
val lastTimeSessionOpened = TextSecurePreferences.getLastTimeSessionOpened(this)
|
|
||||||
val timeSinceLastTimeOpen = System.currentTimeMillis() - lastTimeSessionOpened
|
|
||||||
|
|
||||||
// activate polling limit on open groups if the app hasn't been opened for more than the duration set in MAX_INACTIVITY_PERIOD
|
|
||||||
TextSecurePreferences.setOpenGroupPollingLimit(this, timeSinceLastTimeOpen > OpenGroupPollerV2.maxInactivityPeriod)
|
|
||||||
TextSecurePreferences.setLastTimeSessionOpened(this)
|
|
||||||
}
|
|
||||||
// endregion
|
// endregion
|
||||||
|
|
||||||
// region Updating
|
// region Updating
|
||||||
|
@ -13,6 +13,7 @@ import okhttp3.HttpUrl
|
|||||||
import okhttp3.MediaType
|
import okhttp3.MediaType
|
||||||
import okhttp3.RequestBody
|
import okhttp3.RequestBody
|
||||||
import org.session.libsession.messaging.MessagingModuleConfiguration
|
import org.session.libsession.messaging.MessagingModuleConfiguration
|
||||||
|
import org.session.libsession.messaging.sending_receiving.pollers.OpenGroupPollerV2
|
||||||
import org.session.libsession.snode.OnionRequestAPI
|
import org.session.libsession.snode.OnionRequestAPI
|
||||||
import org.session.libsession.utilities.AESGCM
|
import org.session.libsession.utilities.AESGCM
|
||||||
import org.session.libsession.utilities.TextSecurePreferences
|
import org.session.libsession.utilities.TextSecurePreferences
|
||||||
@ -31,6 +32,15 @@ object OpenGroupAPIV2 {
|
|||||||
private val moderators: HashMap<String, Set<String>> = hashMapOf() // Server URL to (channel ID to set of moderator IDs)
|
private val moderators: HashMap<String, Set<String>> = hashMapOf() // Server URL to (channel ID to set of moderator IDs)
|
||||||
private val curve = Curve25519.getInstance(Curve25519.BEST)
|
private val curve = Curve25519.getInstance(Curve25519.BEST)
|
||||||
val defaultRooms = MutableSharedFlow<List<DefaultGroup>>(replay = 1)
|
val defaultRooms = MutableSharedFlow<List<DefaultGroup>>(replay = 1)
|
||||||
|
private val hasPerformedInitialPoll = mutableMapOf<String, Boolean>()
|
||||||
|
private var hasUpdatedLastOpenDate = false
|
||||||
|
|
||||||
|
private val timeSinceLastOpen by lazy {
|
||||||
|
val context = MessagingModuleConfiguration.shared.context
|
||||||
|
val lastOpenDate = TextSecurePreferences.getLastOpenTimeDate(context)
|
||||||
|
val now = System.currentTimeMillis()
|
||||||
|
now - lastOpenDate
|
||||||
|
}
|
||||||
|
|
||||||
private const val defaultServerPublicKey = "a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238"
|
private const val defaultServerPublicKey = "a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238"
|
||||||
const val defaultServer = "http://116.203.70.33"
|
const val defaultServer = "http://116.203.70.33"
|
||||||
@ -351,6 +361,13 @@ object OpenGroupAPIV2 {
|
|||||||
val authTokenRequests = rooms.associateWith { room -> getAuthToken(room, server) }
|
val authTokenRequests = rooms.associateWith { room -> getAuthToken(room, server) }
|
||||||
val storage = MessagingModuleConfiguration.shared.storage
|
val storage = MessagingModuleConfiguration.shared.storage
|
||||||
val context = MessagingModuleConfiguration.shared.context
|
val context = MessagingModuleConfiguration.shared.context
|
||||||
|
val timeSinceLastOpen = this.timeSinceLastOpen
|
||||||
|
val useMessageLimit = (hasPerformedInitialPoll[server] != true
|
||||||
|
&& timeSinceLastOpen > OpenGroupPollerV2.maxInactivityPeriod)
|
||||||
|
hasPerformedInitialPoll[server] = true
|
||||||
|
if (!hasUpdatedLastOpenDate) {
|
||||||
|
TextSecurePreferences.setLastOpenDate(context)
|
||||||
|
}
|
||||||
val requests = rooms.mapNotNull { room ->
|
val requests = rooms.mapNotNull { room ->
|
||||||
val authToken = try {
|
val authToken = try {
|
||||||
authTokenRequests[room]?.get()
|
authTokenRequests[room]?.get()
|
||||||
@ -361,8 +378,8 @@ object OpenGroupAPIV2 {
|
|||||||
CompactPollRequest(
|
CompactPollRequest(
|
||||||
roomID = room,
|
roomID = room,
|
||||||
authToken = authToken,
|
authToken = authToken,
|
||||||
fromDeletionServerID = if (TextSecurePreferences.isOpenGroupPollingLimit(context)) null else storage.getLastDeletionServerID(room, server),
|
fromDeletionServerID = if (useMessageLimit) null else storage.getLastDeletionServerID(room, server),
|
||||||
fromMessageServerID = if (TextSecurePreferences.isOpenGroupPollingLimit(context)) null else storage.getLastMessageServerID(room, server)
|
fromMessageServerID = if (useMessageLimit) null else storage.getLastMessageServerID(room, server)
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
val request = Request(verb = POST, room = null, server = server, endpoint = "compact_poll", isAuthRequired = false, parameters = mapOf( "requests" to requests ))
|
val request = Request(verb = POST, room = null, server = server, endpoint = "compact_poll", isAuthRequired = false, parameters = mapOf( "requests" to requests ))
|
||||||
|
@ -99,21 +99,16 @@ object TextSecurePreferences {
|
|||||||
|
|
||||||
private const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
|
private const val GIF_GRID_LAYOUT = "pref_gif_grid_layout"
|
||||||
|
|
||||||
// region Limit open group polling
|
|
||||||
|
|
||||||
private const val LAST_TIME_SESSION_OPENED = "pref_last_time_session_open"
|
|
||||||
private const val OPEN_GROUP_POLLING_LIMIT = "pref_Open_group_polling_limit"
|
|
||||||
|
|
||||||
// region FCM
|
|
||||||
const val IS_USING_FCM = "pref_is_using_fcm"
|
const val IS_USING_FCM = "pref_is_using_fcm"
|
||||||
private const val FCM_TOKEN = "pref_fcm_token"
|
private const val FCM_TOKEN = "pref_fcm_token"
|
||||||
private const val LAST_FCM_TOKEN_UPLOAD_TIME = "pref_last_fcm_token_upload_time_2"
|
private const val LAST_FCM_TOKEN_UPLOAD_TIME = "pref_last_fcm_token_upload_time_2"
|
||||||
|
|
||||||
// region Multi Device
|
|
||||||
private const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time"
|
private const val LAST_CONFIGURATION_SYNC_TIME = "pref_last_configuration_sync_time"
|
||||||
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
|
const val CONFIGURATION_SYNCED = "pref_configuration_synced"
|
||||||
private const val LAST_PROFILE_UPDATE_TIME = "pref_last_profile_update_time"
|
private const val LAST_PROFILE_UPDATE_TIME = "pref_last_profile_update_time"
|
||||||
|
|
||||||
|
private const val LAST_OPEN_DATE = "pref_last_open_date"
|
||||||
|
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
fun getLastConfigurationSyncTime(context: Context): Long {
|
fun getLastConfigurationSyncTime(context: Context): Long {
|
||||||
return getLongPreference(context, LAST_CONFIGURATION_SYNC_TIME, 0)
|
return getLongPreference(context, LAST_CONFIGURATION_SYNC_TIME, 0)
|
||||||
@ -777,21 +772,11 @@ object TextSecurePreferences {
|
|||||||
setBooleanPreference(context, "has_performed_contact_migration", true)
|
setBooleanPreference(context, "has_performed_contact_migration", true)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getLastTimeSessionOpened(context: Context): Long {
|
fun getLastOpenTimeDate(context: Context): Long {
|
||||||
return getLongPreference(context!!, LAST_TIME_SESSION_OPENED, 0)
|
return getLongPreference(context, LAST_OPEN_DATE, 0)
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setLastTimeSessionOpened(context: Context) {
|
fun setLastOpenDate(context: Context) {
|
||||||
setLongPreference(context, LAST_TIME_SESSION_OPENED, System.currentTimeMillis())
|
setLongPreference(context, LAST_OPEN_DATE, System.currentTimeMillis())
|
||||||
}
|
}
|
||||||
|
|
||||||
fun isOpenGroupPollingLimit(context: Context): Boolean {
|
|
||||||
return getBooleanPreference(context, OPEN_GROUP_POLLING_LIMIT, false)
|
|
||||||
}
|
|
||||||
|
|
||||||
fun setOpenGroupPollingLimit(context: Context, limit: Boolean) {
|
|
||||||
setBooleanPreference(context, OPEN_GROUP_POLLING_LIMIT, limit)
|
|
||||||
}
|
|
||||||
|
|
||||||
// endregion
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user