Skip to content

Commit

Permalink
Merge pull request #151 from loki-project/threading
Browse files Browse the repository at this point in the history
Improved Threading
  • Loading branch information
nielsandriesse authored Mar 20, 2020
2 parents 73ee3eb + 2357642 commit 81148e3
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class LinkedDevicesActivity : PassphraseRequiredActionBarActivity, LoaderManager
}

override fun onDeviceLinkRequestAuthorized(deviceLink: DeviceLink) {
LokiFileServerAPI.shared.addDeviceLink(deviceLink).bind(LokiAPI.sharedWorkContext) {
LokiFileServerAPI.shared.addDeviceLink(deviceLink).bind(LokiAPI.sharedContext) {
signAndSendDeviceLinkMessage(this, deviceLink)
}.successUi {
LoaderManager.getInstance(this).restartLoader(0, null, this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,11 +217,16 @@ class LokiPublicChatPoller(private val context: Context, private val group: Loki
val userPrivateKey = IdentityKeyUtil.getIdentityKeyPair(context).privateKey.serialize()
val database = DatabaseFactory.getLokiAPIDatabase(context)
LokiFileServerAPI.configure(false, userHexEncodedPublicKey, userPrivateKey, database)
LokiDeviceLinkUtilities.getAllLinkedDeviceHexEncodedPublicKeys(userHexEncodedPublicKey).bind { devices ->
LokiDeviceLinkUtilities.getAllLinkedDeviceHexEncodedPublicKeys(userHexEncodedPublicKey).bind(LokiPublicChatAPI.sharedContext) { devices ->
userDevices = devices
api.getMessages(group.channel, group.server)
}.bind { messages ->
}.bind(LokiPublicChatAPI.sharedContext) { messages ->
if (messages.isNotEmpty()) {
if (messages.count() == 1) {
Log.d("Loki", "Fetched 1 new message.")
} else {
Log.d("Loki", "Fetched ${messages.count()} new messages.")
}
// We need to fetch the device mapping for any devices we don't have
uniqueDevices = messages.map { it.hexEncodedPublicKey }.toSet()
val devicesToUpdate = uniqueDevices.filter { !userDevices.contains(it) && LokiFileServerAPI.shared.hasDeviceLinkCacheExpired(hexEncodedPublicKey = it) }
Expand Down

0 comments on commit 81148e3

Please sign in to comment.