@@ -10,6 +10,7 @@ import kotlinx.coroutines.GlobalScope
10
10
import kotlinx.coroutines.flow.MutableSharedFlow
11
11
import kotlinx.serialization.SerialName
12
12
import kotlinx.serialization.Serializable
13
+ import kotlinx.serialization.json.decodeFromStream
13
14
import network.loki.messenger.libsession_util.ED25519
14
15
import network.loki.messenger.libsession_util.Hash
15
16
import network.loki.messenger.libsession_util.util.BlindKeyAPI
@@ -25,7 +26,6 @@ import org.session.libsession.snode.OnionResponse
25
26
import org.session.libsession.snode.SnodeAPI
26
27
import org.session.libsession.snode.utilities.asyncPromise
27
28
import org.session.libsession.snode.utilities.await
28
- import org.session.libsession.utilities.TextSecurePreferences
29
29
import org.session.libsignal.utilities.AccountId
30
30
import org.session.libsignal.utilities.Base64.encodeBytes
31
31
import org.session.libsignal.utilities.ByteArraySlice
@@ -46,15 +46,6 @@ import kotlin.collections.set
46
46
47
47
object OpenGroupApi {
48
48
val defaultRooms = MutableSharedFlow <List <DefaultGroup >>(replay = 1 )
49
- private val hasPerformedInitialPoll = mutableMapOf<String , Boolean >()
50
- private var hasUpdatedLastOpenDate = false
51
- private val timeSinceLastOpen by lazy {
52
- val context = MessagingModuleConfiguration .shared.context
53
- val lastOpenDate = TextSecurePreferences .getLastOpenTimeDate(context)
54
- val now = System .currentTimeMillis()
55
- now - lastOpenDate
56
- }
57
-
58
49
const val defaultServerPublicKey = " a03c383cf63c3c4efe67acc52112a6dd734b3a946b9545f488aaa93da7991238"
59
50
const val legacyServerIP = " 116.203.70.33"
60
51
const val legacyDefaultServer = " http://116.203.70.33" // TODO: migrate all references to use new value
@@ -736,18 +727,6 @@ object OpenGroupApi {
736
727
}
737
728
}
738
729
739
- fun getRoomInfo (roomToken : String , server : String ): Promise <RoomInfoDetails , Exception > {
740
- val request = Request (
741
- verb = GET ,
742
- room = null ,
743
- server = server,
744
- endpoint = Endpoint .Room (roomToken)
745
- )
746
- return getResponseBody(request).map { response ->
747
- JsonUtil .fromJson(response, RoomInfoDetails ::class .java)
748
- }
749
- }
750
-
751
730
private fun getAllRooms (): Promise <List <RoomInfoDetails >, Exception> {
752
731
val request = Request (
753
732
verb = GET ,
@@ -756,10 +735,9 @@ object OpenGroupApi {
756
735
endpoint = Endpoint .Rooms
757
736
)
758
737
return getResponseBody(request, signRequest = false ).map { response ->
759
- val rawRooms = JsonUtil .fromJson(response, List ::class .java) ? : throw Error .ParsingFailed
760
- rawRooms.mapNotNull {
761
- JsonUtil .fromJson(JsonUtil .toJson(it), RoomInfoDetails ::class .java)
762
- }
738
+ MessagingModuleConfiguration .shared.json
739
+ .decodeFromStream<Array <RoomInfoDetails >>(response.inputStream())
740
+ .toList()
763
741
}
764
742
}
765
743
@@ -770,35 +748,6 @@ object OpenGroupApi {
770
748
}
771
749
}
772
750
773
- fun getCapabilitiesAndRoomInfo (
774
- room : String ,
775
- server : String
776
- ): Promise <Pair <Capabilities , RoomInfoDetails >, Exception> {
777
- val requests = mutableListOf<BatchRequestInfo <* >>(
778
- BatchRequestInfo (
779
- request = BatchRequest (
780
- method = GET ,
781
- path = " /capabilities"
782
- ),
783
- endpoint = Endpoint .Capabilities ,
784
- responseType = object : TypeReference <Capabilities >(){}
785
- ),
786
- BatchRequestInfo (
787
- request = BatchRequest (
788
- method = GET ,
789
- path = " /room/$room "
790
- ),
791
- endpoint = Endpoint .Room (room),
792
- responseType = object : TypeReference <RoomInfoDetails >(){}
793
- )
794
- )
795
- return sequentialBatch(server, requests).map {
796
- val capabilities = it.firstOrNull()?.body as ? Capabilities ? : throw Error .ParsingFailed
797
- val roomInfo = it.lastOrNull()?.body as ? RoomInfoDetails ? : throw Error .ParsingFailed
798
- capabilities to roomInfo
799
- }
800
- }
801
-
802
751
fun sendDirectMessage (message : String , blindedAccountId : String , server : String ): Promise <DirectMessage , Exception > {
803
752
val request = Request (
804
753
verb = POST ,
0 commit comments