mirror of
https://github.com/oxen-io/session-android.git
synced 2025-08-11 20:57:41 +00:00
feat: join groups logic
This commit is contained in:
@@ -6,6 +6,7 @@ import nl.komponents.kovenant.Kovenant
|
||||
import nl.komponents.kovenant.Promise
|
||||
import nl.komponents.kovenant.functional.bind
|
||||
import nl.komponents.kovenant.functional.map
|
||||
import okhttp3.Headers
|
||||
import okhttp3.HttpUrl
|
||||
import okhttp3.MediaType
|
||||
import okhttp3.RequestBody
|
||||
@@ -92,9 +93,10 @@ object OpenGroupAPIV2 {
|
||||
fun execute(token: String?): Promise<Map<*, *>, Exception> {
|
||||
val requestBuilder = okhttp3.Request.Builder()
|
||||
.url(urlBuilder.build())
|
||||
.headers(Headers.of(request.headers))
|
||||
if (request.isAuthRequired) {
|
||||
if (token.isNullOrEmpty()) throw IllegalStateException("No auth token for request")
|
||||
requestBuilder.addHeader("Authorization", token)
|
||||
requestBuilder.header("Authorization", token)
|
||||
}
|
||||
when (request.verb) {
|
||||
GET -> requestBuilder.get()
|
||||
@@ -353,7 +355,7 @@ object OpenGroupAPIV2 {
|
||||
}
|
||||
|
||||
fun getInfo(room: String, server: String): Promise<Info, Exception> {
|
||||
val request = Request(verb = GET, room = room, server = server, endpoint = "rooms/$room", isAuthRequired = false)
|
||||
val request = Request(verb = GET, room = null, server = server, endpoint = "rooms/$room", isAuthRequired = false)
|
||||
return send(request).map(sharedContext) { json ->
|
||||
val rawRoom = json["room"] as? Map<*, *> ?: throw Error.PARSING_FAILED
|
||||
val id = rawRoom["id"] as? String ?: throw Error.PARSING_FAILED
|
||||
|
@@ -8,17 +8,15 @@ data class OpenGroupV2(
|
||||
val room: String,
|
||||
val id: String,
|
||||
val name: String,
|
||||
val publicKey: String,
|
||||
val imageId: String?
|
||||
val publicKey: String
|
||||
) {
|
||||
|
||||
constructor(server: String, room: String, name: String, publicKey: String, imageId: String?) : this(
|
||||
constructor(server: String, room: String, name: String, publicKey: String) : this(
|
||||
server = server,
|
||||
room = room,
|
||||
id = "$server.$room",
|
||||
name = name,
|
||||
publicKey = publicKey,
|
||||
imageId = imageId
|
||||
)
|
||||
|
||||
companion object {
|
||||
@@ -32,9 +30,8 @@ data class OpenGroupV2(
|
||||
val server = json.get("server").asText().toLowerCase(Locale.getDefault())
|
||||
val displayName = json.get("displayName").asText()
|
||||
val publicKey = json.get("publicKey").asText()
|
||||
val imageId = json.get("imageId").asText().let { str -> if (str.isEmpty()) null else str }
|
||||
|
||||
OpenGroupV2(server, room, displayName, publicKey, imageId)
|
||||
OpenGroupV2(server, room, displayName, publicKey)
|
||||
} catch (e: Exception) {
|
||||
null
|
||||
}
|
||||
@@ -42,4 +39,11 @@ data class OpenGroupV2(
|
||||
|
||||
}
|
||||
|
||||
fun toJson(): Map<String,String> = mapOf(
|
||||
"room" to room,
|
||||
"server" to server,
|
||||
"displayName" to name,
|
||||
"publicKey" to publicKey,
|
||||
)
|
||||
|
||||
}
|
@@ -7,7 +7,6 @@ import org.session.libsession.messaging.messages.visible.VisibleMessage
|
||||
import org.session.libsession.utilities.GroupUtil
|
||||
import org.session.libsignal.service.internal.push.PushTransportDetails
|
||||
import org.session.libsignal.service.internal.push.SignalServiceProtos
|
||||
import org.session.libsignal.utilities.logging.Log
|
||||
|
||||
object MessageReceiver {
|
||||
|
||||
@@ -122,7 +121,6 @@ object MessageReceiver {
|
||||
message.recipient = userPublicKey
|
||||
message.sentTimestamp = envelope.timestamp
|
||||
message.receivedTimestamp = if (envelope.hasServerTimestamp()) envelope.serverTimestamp else System.currentTimeMillis()
|
||||
Log.d("Loki", "time: ${envelope.timestamp}, sent: ${envelope.serverTimestamp}")
|
||||
message.groupPublicKey = groupPublicKey
|
||||
message.openGroupServerMessageID = openGroupServerID
|
||||
// Validate
|
||||
|
@@ -445,7 +445,7 @@ object OnionRequestAPI {
|
||||
val urlAsString = url.toString()
|
||||
val host = url.host()
|
||||
val endpoint = when {
|
||||
server.count() < urlAsString.count() -> urlAsString.substringAfter("$server/")
|
||||
server.count() < urlAsString.count() -> urlAsString.substringAfter(server).removePrefix("/")
|
||||
else -> ""
|
||||
}
|
||||
val body = request.getBodyForOnionRequest() ?: "null"
|
||||
|
Reference in New Issue
Block a user