Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
C
coopwire-hypothesis
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
孙灵跃 Leon Sun
coopwire-hypothesis
Commits
4645088e
Commit
4645088e
authored
May 17, 2023
by
Alejandro Celaya
Committed by
Alejandro Celaya
May 17, 2023
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Migrate SessionService to TS
parent
8e30765f
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
25 additions
and
19 deletions
+25
-19
session.ts
src/sidebar/services/session.ts
+25
-19
No files found.
src/sidebar/services/session.
j
s
→
src/sidebar/services/session.
t
s
View file @
4645088e
import
type
{
Profile
}
from
'../../types/api'
;
import
type
{
SidebarSettings
}
from
'../../types/config'
;
import
{
serviceConfig
}
from
'../config/service-config'
;
import
{
serviceConfig
}
from
'../config/service-config'
;
import
type
{
SidebarStore
}
from
'../store'
;
import
{
retryPromiseOperation
}
from
'../util/retry'
;
import
{
retryPromiseOperation
}
from
'../util/retry'
;
import
*
as
sentry
from
'../util/sentry'
;
import
*
as
sentry
from
'../util/sentry'
;
import
type
{
APIService
}
from
'./api'
;
import
type
{
AuthService
}
from
'./auth'
;
import
type
{
ToastMessengerService
}
from
'./toast-messenger'
;
const
CACHE_TTL
=
5
*
60
*
1000
;
// 5 minutes
const
CACHE_TTL
=
5
*
60
*
1000
;
// 5 minutes
/** @typedef {import('../../types/api').Profile} Profile */
/**
/**
* This service handles fetching the user's profile, updating profile settings
* This service handles fetching the user's profile, updating profile settings
* and logging out.
* and logging out.
...
@@ -13,25 +17,28 @@ const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
...
@@ -13,25 +17,28 @@ const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
* @inject
* @inject
*/
*/
export
class
SessionService
{
export
class
SessionService
{
/**
private
_store
:
SidebarStore
;
* @param {import('../store').SidebarStore} store
private
_api
:
APIService
;
* @param {import('./api').APIService} api
private
_auth
:
AuthService
;
* @param {import('./auth').AuthService} auth
private
_toastMessenger
:
ToastMessengerService
;
* @param {import('../../types/config').SidebarSettings} settings
private
_authority
:
string
|
null
;
* @param {import('./toast-messenger').ToastMessengerService} toastMessenger
private
_lastLoad
:
Promise
<
Profile
>
|
null
;
*/
private
_lastLoadTime
:
number
|
null
;
constructor
(
store
,
api
,
auth
,
settings
,
toastMessenger
)
{
constructor
(
store
:
SidebarStore
,
api
:
APIService
,
auth
:
AuthService
,
settings
:
SidebarSettings
,
toastMessenger
:
ToastMessengerService
)
{
this
.
_api
=
api
;
this
.
_api
=
api
;
this
.
_auth
=
auth
;
this
.
_auth
=
auth
;
this
.
_store
=
store
;
this
.
_store
=
store
;
this
.
_toastMessenger
=
toastMessenger
;
this
.
_toastMessenger
=
toastMessenger
;
this
.
_authority
=
serviceConfig
(
settings
)?.
authority
??
null
;
this
.
_authority
=
serviceConfig
(
settings
)?.
authority
??
null
;
/** @type {Promise<Profile>|null} */
this
.
_lastLoad
=
null
;
this
.
_lastLoad
=
null
;
/** @type {number|null} */
this
.
_lastLoadTime
=
null
;
this
.
_lastLoadTime
=
null
;
// Re-fetch profile when user logs in or out in another tab.
// Re-fetch profile when user logs in or out in another tab.
...
@@ -44,9 +51,9 @@ export class SessionService {
...
@@ -44,9 +51,9 @@ export class SessionService {
* If the profile has been previously fetched within `CACHE_TTL` ms, then this
* If the profile has been previously fetched within `CACHE_TTL` ms, then this
* method returns a cached profile instead of triggering another fetch.
* method returns a cached profile instead of triggering another fetch.
*
*
* @return
{Promise<Profile>}
A promise for the user's profile data.
* @return A promise for the user's profile data.
*/
*/
load
()
{
load
()
:
Promise
<
Profile
>
{
if
(
if
(
!
this
.
_lastLoad
||
!
this
.
_lastLoad
||
!
this
.
_lastLoadTime
||
!
this
.
_lastLoadTime
||
...
@@ -93,10 +100,9 @@ export class SessionService {
...
@@ -93,10 +100,9 @@ export class SessionService {
* This method can be used to update the profile data in the client when new
* This method can be used to update the profile data in the client when new
* data is pushed from the server via the real-time API.
* data is pushed from the server via the real-time API.
*
*
* @param {Profile} profile
* @return The updated profile data
* @return {Profile} The updated profile data
*/
*/
update
(
profile
)
{
update
(
profile
:
Profile
):
Profile
{
const
prevProfile
=
this
.
_store
.
profile
();
const
prevProfile
=
this
.
_store
.
profile
();
const
userChanged
=
profile
.
userid
!==
prevProfile
.
userid
;
const
userChanged
=
profile
.
userid
!==
prevProfile
.
userid
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment