Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

Use server-provided current session status

Neeraj Gupta85372b52bd7d
diff --git a/mobile/apps/photos/lib/gateways/users/models/sessions.dart b/mobile/apps/photos/lib/gateways/users/models/sessions.dart
index d1d3cd4a2b..64ed8feaa5 100644
--- a/mobile/apps/photos/lib/gateways/users/models/sessions.dart
+++ b/mobile/apps/photos/lib/gateways/users/models/sessions.dart
@@ -15,6 +15,7 @@ class Sessions {
class Session {
final String token;
+ final bool? isCurrent;
final int creationTime;
final String ip;
final String ua;
@@ -23,6 +24,7 @@ class Session {
Session(
this.token,
+ this.isCurrent,
this.creationTime,
this.ip,
this.ua,
@@ -33,6 +35,7 @@ class Session {
factory Session.fromMap(Map<String, dynamic> map) {
return Session(
map['token'],
+ map['isCurrent'],
map['creationTime'],
map['ip'],
map['ua'],
@@ -40,4 +43,7 @@ class Session {
map['lastUsedTime'],
);
}
+
+ bool isCurrentSession(String? currentToken) =>
+ isCurrent ?? token == currentToken;
}
diff --git a/mobile/apps/photos/lib/ui/account/sessions_page.dart b/mobile/apps/photos/lib/ui/account/sessions_page.dart
index f3db87f6c8..3ec7d2e59e 100644
--- a/mobile/apps/photos/lib/ui/account/sessions_page.dart
+++ b/mobile/apps/photos/lib/ui/account/sessions_page.dart
@@ -142,8 +142,9 @@ class _SessionsPageState extends State<SessionsPage> {
void _showSessionTerminationDialog(Session session) {
final l10n = context.strings;
- final isLoggingOutFromThisDevice =
- session.token == Configuration.instance.getToken();
+ final isLoggingOutFromThisDevice = session.isCurrentSession(
+ Configuration.instance.getToken(),
+ );
final displayedUserAgent = session.ua.length > 256
? "${session.ua.substring(0, 253)}..."
: session.ua;
@@ -180,7 +181,7 @@ class _SessionsPageState extends State<SessionsPage> {
Widget _getUAWidget(Session session) {
final colors = context.componentColors;
- if (session.token == Configuration.instance.getToken()) {
+ if (session.isCurrentSession(Configuration.instance.getToken())) {
return Text(
context.strings.thisDevice,
style: TextStyles.bodyBold.copyWith(color: colors.primary),
diff --git a/mobile/packages/accounts/lib/models/sessions.dart b/mobile/packages/accounts/lib/models/sessions.dart
index d1d3cd4a2b..64ed8feaa5 100644
--- a/mobile/packages/accounts/lib/models/sessions.dart
+++ b/mobile/packages/accounts/lib/models/sessions.dart
@@ -15,6 +15,7 @@ class Sessions {
class Session {
final String token;
+ final bool? isCurrent;
final int creationTime;
final String ip;
final String ua;
@@ -23,6 +24,7 @@ class Session {
Session(
this.token,
+ this.isCurrent,
this.creationTime,
this.ip,
this.ua,
@@ -33,6 +35,7 @@ class Session {
factory Session.fromMap(Map<String, dynamic> map) {
return Session(
map['token'],
+ map['isCurrent'],
map['creationTime'],
map['ip'],
map['ua'],
@@ -40,4 +43,7 @@ class Session {
map['lastUsedTime'],
);
}
+
+ bool isCurrentSession(String? currentToken) =>
+ isCurrent ?? token == currentToken;
}
diff --git a/mobile/packages/accounts/lib/pages/sessions_page.dart b/mobile/packages/accounts/lib/pages/sessions_page.dart
index 5443f0ce26..b26d878837 100644
--- a/mobile/packages/accounts/lib/pages/sessions_page.dart
+++ b/mobile/packages/accounts/lib/pages/sessions_page.dart
@@ -146,8 +146,9 @@ class _SessionsPageState extends State<SessionsPage> {
}
void _showSessionTerminationDialog(Session session) {
- final isLoggingOutFromThisDevice =
- session.token == widget.config.getToken();
+ final isLoggingOutFromThisDevice = session.isCurrentSession(
+ widget.config.getToken(),
+ );
final textTheme = getEnteTextTheme(context);
showBaseBottomSheet(
@@ -193,7 +194,7 @@ class _SessionsPageState extends State<SessionsPage> {
}
Widget _getUAWidget(Session session) {
- if (session.token == widget.config.getToken()) {
+ if (session.isCurrentSession(widget.config.getToken())) {
return Text(
context.strings.thisDevice,
style: TextStyle(
diff --git a/web/apps/locker/src/components/LockerSessionsDrawer.tsx b/web/apps/locker/src/components/LockerSessionsDrawer.tsx
index 2234566b9e..7e6b9f1e49 100644
--- a/web/apps/locker/src/components/LockerSessionsDrawer.tsx
+++ b/web/apps/locker/src/components/LockerSessionsDrawer.tsx
@@ -12,6 +12,7 @@ import {
import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";
import {
getActiveSessions,
+ isCurrentSession,
terminateSession,
type Session,
} from "ente-accounts/services/sessions";
@@ -107,7 +108,7 @@ const SessionsContents: React.FC<SessionsContentsProps> = ({
const handleTerminateSession = useCallback(
(session: Session) => {
- const isCurrentDevice = session.token === currentToken;
+ const isCurrentDevice = isCurrentSession(session, currentToken);
showMiniDialog({
title: t("terminate_session"),
@@ -203,7 +204,10 @@ const SessionsContents: React.FC<SessionsContentsProps> = ({
<React.Fragment key={session.token}>
<SessionRow
session={session}
- isCurrentDevice={session.token === currentToken}
+ isCurrentDevice={isCurrentSession(
+ session,
+ currentToken,
+ )}
onTerminate={() => handleTerminateSession(session)}
/>
{index < sessions.length - 1 && (
diff --git a/web/apps/photos/src/components/sidebar/SessionsSettings.tsx b/web/apps/photos/src/components/sidebar/SessionsSettings.tsx
index 77fc667c7d..d9a0786dd4 100644
--- a/web/apps/photos/src/components/sidebar/SessionsSettings.tsx
+++ b/web/apps/photos/src/components/sidebar/SessionsSettings.tsx
@@ -12,6 +12,7 @@ import {
import { sessionExpiredDialogAttributes } from "ente-accounts/components/utils/dialog";
import {
getActiveSessions,
+ isCurrentSession,
terminateSession,
type Session,
} from "ente-accounts/services/sessions";
@@ -113,7 +114,7 @@ const SessionsSettingsContents: React.FC<SessionsSettingsContentsProps> = ({
const handleTerminateSession = useCallback(
(session: Session) => {
- const isCurrentDevice = session.token === currentToken;
+ const isCurrentDevice = isCurrentSession(session, currentToken);
showMiniDialog({
title: t("terminate_session"),
@@ -211,7 +212,10 @@ const SessionsSettingsContents: React.FC<SessionsSettingsContentsProps> = ({
<SessionRow
key={session.token}
session={session}
- isCurrentDevice={session.token === currentToken}
+ isCurrentDevice={isCurrentSession(
+ session,
+ currentToken,
+ )}
onTerminate={() => handleTerminateSession(session)}
showDivider={index < sessions.length - 1}
/>
diff --git a/web/packages/accounts/services/sessions.ts b/web/packages/accounts/services/sessions.ts
index f0bec949bf..3be0379292 100644
--- a/web/packages/accounts/services/sessions.ts
+++ b/web/packages/accounts/services/sessions.ts
@@ -4,6 +4,7 @@ import { z } from "zod";
const Session = z.object({
token: z.string(),
+ isCurrent: z.boolean().optional(),
creationTime: z.number(),
ip: z.string(),
ua: z.string(),
@@ -13,6 +14,11 @@ const Session = z.object({
export type Session = z.infer<typeof Session>;
+export const isCurrentSession = (
+ session: Session,
+ currentToken: string | undefined,
+) => session.isCurrent ?? session.token === currentToken;
+
const SessionsResponse = z.object({ sessions: z.array(Session) });
export const getActiveSessions = async (): Promise<Session[]> => {