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
Hide 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
type
{
SidebarStore
}
from
'../store'
;
import
{
retryPromiseOperation
}
from
'../util/retry'
;
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
/** @typedef {import('../../types/api').Profile} Profile */
/**
* This service handles fetching the user's profile, updating profile settings
* and logging out.
...
...
@@ -13,25 +17,28 @@ const CACHE_TTL = 5 * 60 * 1000; // 5 minutes
* @inject
*/
export
class
SessionService
{
/**
* @param {import('../store').SidebarStore} store
* @param {import('./api').APIService} api
* @param {import('./auth').AuthService} auth
* @param {import('../../types/config').SidebarSettings} settings
* @param {import('./toast-messenger').ToastMessengerService} toastMessenger
*/
constructor
(
store
,
api
,
auth
,
settings
,
toastMessenger
)
{
private
_store
:
SidebarStore
;
private
_api
:
APIService
;
private
_auth
:
AuthService
;
private
_toastMessenger
:
ToastMessengerService
;
private
_authority
:
string
|
null
;
private
_lastLoad
:
Promise
<
Profile
>
|
null
;
private
_lastLoadTime
:
number
|
null
;
constructor
(
store
:
SidebarStore
,
api
:
APIService
,
auth
:
AuthService
,
settings
:
SidebarSettings
,
toastMessenger
:
ToastMessengerService
)
{
this
.
_api
=
api
;
this
.
_auth
=
auth
;
this
.
_store
=
store
;
this
.
_toastMessenger
=
toastMessenger
;
this
.
_authority
=
serviceConfig
(
settings
)?.
authority
??
null
;
/** @type {Promise<Profile>|null} */
this
.
_lastLoad
=
null
;
/** @type {number|null} */
this
.
_lastLoadTime
=
null
;
// Re-fetch profile when user logs in or out in another tab.
...
...
@@ -44,9 +51,9 @@ export class SessionService {
* If the profile has been previously fetched within `CACHE_TTL` ms, then this
* 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
(
!
this
.
_lastLoad
||
!
this
.
_lastLoadTime
||
...
...
@@ -93,10 +100,9 @@ export class SessionService {
* 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.
*
* @param {Profile} profile
* @return {Profile} The updated profile data
* @return The updated profile data
*/
update
(
profile
)
{
update
(
profile
:
Profile
):
Profile
{
const
prevProfile
=
this
.
_store
.
profile
();
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