Skip to content

Commit

Permalink
feat (#19): Get current user session
Browse files Browse the repository at this point in the history
  • Loading branch information
y9slavabogu authored Jul 13, 2023
1 parent 5dbff90 commit 626a52a
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -368,6 +368,11 @@ public class GrpcTimeMatesRequestsEngine(
headers = authorizedMetadata(request.accessHash),
).let { SdkEmpty }

is GetUserCurrentSessionRequest -> timerSessionsService.getUserCurrentSession(
request = Empty.getDefaultInstance(),
headers = authorizedMetadata(request.accessHash),
).let { timersMapper.grpcTimerToSdkTimer(it) }

else -> unsupported(request::class)
} as T
}.mapException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ import "io/timemates/api/timers/sessions/requests/StopTimerSessionRequest.proto"
import "io/timemates/api/timers/sessions/requests/JoinTimerSessionRequest.proto";
import "io/timemates/api/timers/sessions/requests/ConfirmTimerSessionRequest.proto";
import "io/timemates/api/timers/sessions/requests/GetTimerStateRequest.proto";
import "io/timemates/api/timers/sessions/requests/GetUserCurrentSessionRequest.proto";
import "io/timemates/api/timers/sessions/types/TimerState.proto";
import "io/timemates/api/timers/types/Timer.proto";
import "google/protobuf/empty.proto";

option java_package = "io.timemates.api.timers";
Expand Down Expand Up @@ -61,4 +63,9 @@ service TimerSessionsService {
* The state is returned as a stream of TimerState messages.
*/
rpc getState(GetTimerStateRequest) returns (stream TimerState);

/**
* Gets current timer session
*/
rpc getUserCurrentSession(google.protobuf.Empty) returns (Timer);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
syntax = "proto3";

import "io/timemates/api/timers/types/Timer.proto";

option java_package = "io.timemates.api.timers.sessions.requests";

message GetUserCurrentSessionRequest {
message Response {
optional Timer timer = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import io.timemates.sdk.common.providers.AccessHashProvider
import io.timemates.sdk.common.providers.getAsResult
import io.timemates.sdk.common.types.Empty
import io.timemates.sdk.timers.sessions.requests.*
import io.timemates.sdk.timers.types.Timer
import io.timemates.sdk.timers.types.value.TimerId

/**
Expand Down Expand Up @@ -82,4 +83,14 @@ public class TimersSessionsApi(
return tokenProvider.getAsResult()
.flatMap { token -> engine.execute(ConfirmTimerRoundRequest(token)) }
}

/**
* Returns current user session.
*
* @return A [Result] indicating the success or failure of the operation.
*/
public suspend fun getUserCurrentSession(): Result<Timer> {
return tokenProvider.getAsResult()
.flatMap { token -> engine.execute(GetUserCurrentSessionRequest(token)) }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package io.timemates.sdk.timers.sessions.requests

import io.timemates.sdk.authorization.types.value.AccessHash
import io.timemates.sdk.common.types.TimeMatesRequest
import io.timemates.sdk.timers.types.Timer

/**
* Gets current timer session.
*/
public data class GetUserCurrentSessionRequest(
val accessHash: AccessHash,
) : TimeMatesRequest<Timer>()

0 comments on commit 626a52a

Please sign in to comment.