Skip to content

Commit

Permalink
Squashed commit of the following:
Browse files Browse the repository at this point in the history
commit 69e6513
Author: Shaik Azad <120930148+Azad99-9@users.noreply.github.com>
Date:   Sun Feb 11 20:17:19 2024 +0530

    Created Session Management. (PalisadoesFoundation#2362)

    * feat: efficient session management

    * chore: run check ignore

    * Revert "chore: run check ignore"

    This reverts commit be7e49f.

    * chore fix: run check ignore

    * feat: added new package fake_async

    * chore: fixed codecov drop

    * Update README.md

    * Deprecate Google Maps Integration (PalisadoesFoundation#2363)

    * Post comments were invisible in Individual Post Page with Image (PalisadoesFoundation#2350)

    * Fixed Comment

    * Fixed Comment

    * Fixed Comment

    * Fixed Comment

    * Fixed Comment

    * Bump syncfusion_flutter_datepicker from 24.1.47 to 24.2.3 (PalisadoesFoundation#2365)

    Bumps [syncfusion_flutter_datepicker](https://github.com/syncfusion/flutter-widgets/tree/master/packages) from 24.1.47 to 24.2.3.
    - [Release notes](https://github.com/syncfusion/flutter-widgets/releases)
    - [Commits](https://github.com/syncfusion/flutter-widgets/commits/HEAD/packages)

    ---
    updated-dependencies:
    - dependency-name: syncfusion_flutter_datepicker
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

    * Bump syncfusion_flutter_calendar from 24.1.45 to 24.2.3 (PalisadoesFoundation#2367)

    Bumps [syncfusion_flutter_calendar](https://github.com/syncfusion/flutter-widgets/tree/master/packages) from 24.1.45 to 24.2.3.
    - [Release notes](https://github.com/syncfusion/flutter-widgets/releases)
    - [Commits](https://github.com/syncfusion/flutter-widgets/commits/HEAD/packages)

    ---
    updated-dependencies:
    - dependency-name: syncfusion_flutter_calendar
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

    * fixed requested changes

    * pulled latest upstream

    ---------

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: Peter Harrison <16875803+palisadoes@users.noreply.github.com>
    Co-authored-by: Parag Gupta <103507835+Dante291@users.noreply.github.com>
    Co-authored-by: Shivam Gupta <shivamggupta2604@gmail.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 1110aef
Author: Crystian I <60124535+Cioppolo14@users.noreply.github.com>
Date:   Tue Feb 6 21:38:27 2024 -0500

    Update pull-request-target.yml

commit 10d58db
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Feb 5 02:40:39 2024 -0800

    Bump syncfusion_flutter_calendar from 24.1.45 to 24.2.3 (PalisadoesFoundation#2367)

    Bumps [syncfusion_flutter_calendar](https://github.com/syncfusion/flutter-widgets/tree/master/packages) from 24.1.45 to 24.2.3.
    - [Release notes](https://github.com/syncfusion/flutter-widgets/releases)
    - [Commits](https://github.com/syncfusion/flutter-widgets/commits/HEAD/packages)

    ---
    updated-dependencies:
    - dependency-name: syncfusion_flutter_calendar
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 7bfbaef
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Mon Feb 5 02:04:46 2024 -0800

    Bump syncfusion_flutter_datepicker from 24.1.47 to 24.2.3 (PalisadoesFoundation#2365)

    Bumps [syncfusion_flutter_datepicker](https://github.com/syncfusion/flutter-widgets/tree/master/packages) from 24.1.47 to 24.2.3.
    - [Release notes](https://github.com/syncfusion/flutter-widgets/releases)
    - [Commits](https://github.com/syncfusion/flutter-widgets/commits/HEAD/packages)

    ---
    updated-dependencies:
    - dependency-name: syncfusion_flutter_datepicker
      dependency-type: direct:production
      update-type: version-update:semver-minor
    ...

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 38682c8
Author: Shivam Gupta <shivamggupta2604@gmail.com>
Date:   Sun Feb 4 01:16:07 2024 +0530

    Post comments were invisible in Individual Post Page with Image (PalisadoesFoundation#2350)

    * Fixed Comment

    * Fixed Comment

    * Fixed Comment

    * Fixed Comment

    * Fixed Comment
  • Loading branch information
AVtheking committed Feb 11, 2024
1 parent 89aab82 commit 204e673
Show file tree
Hide file tree
Showing 28 changed files with 485 additions and 111 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull-request-target.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ jobs:
### Reviewers
Do not assign reviewers. Our Queue Monitors will review your PR and assign them.
When your PR has been assigned reviewers contact them to get your code reviewed and approved via:
1. comments in this PR or
Expand Down
27 changes: 17 additions & 10 deletions lib/locator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import 'package:talawa/services/image_service.dart';
import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/services/org_service.dart';
import 'package:talawa/services/post_service.dart';
import 'package:talawa/services/session_manager.dart';
import 'package:talawa/services/size_config.dart';
import 'package:talawa/services/third_party_service/multi_media_pick_service.dart';
import 'package:talawa/services/user_config.dart';
Expand Down Expand Up @@ -41,37 +42,40 @@ import 'package:talawa/view_model/widgets_view_models/custom_drawer_view_model.d
import 'package:talawa/view_model/widgets_view_models/like_button_view_model.dart';
import 'package:talawa/view_model/widgets_view_models/progress_dialog_view_model.dart';

// Creating an instance of GetIt and storing it in a global variable
// Instance of GetIt and storing it in a global variable
/// Intializaing the locator.
GetIt locator = GetIt.instance;

///creating GetIt for UserConfig.
///GetIt for UserConfig.
final userConfig = locator<UserConfig>();

///creating GetIt for NavigationService.
///GetIt for NavigationService.
final navigationService = locator<NavigationService>();

///creating GetIt for DataBaseMutationFunctions.
///GetIt for DataBaseMutationFunctions.
final databaseFunctions = locator<DataBaseMutationFunctions>();

///creating GetIt for GraphqlConfig.
///GetIt for GraphqlConfig.
final graphqlConfig = locator<GraphqlConfig>();

///creating GetIt for SizeConfig.
///GetIt for SizeConfig.
final sizeConfig = locator<SizeConfig>();

///creating GetIt for Queries.
///GetIt for Queries.
final queries = locator<Queries>();

///creating GetIt for Connectivity.
///GetIt for Connectivity.
final connectivity = locator<Connectivity>();

///creating GetIt for OrganizationService.
///GetIt for OrganizationService.
final organizationService = locator<OrganizationService>();

///creating GetIt for ImageService.
///GetIt for ImageService.
final imageService = locator<ImageService>();

///GetIt for SessionManager.
final sessionManager = locator<SessionManager>();

/// This function registers the widgets/objects in "GetIt".
///
/// **params**:
Expand All @@ -91,6 +95,9 @@ void setupLocator() {
//userConfig
locator.registerSingleton(UserConfig());

//sessionManager
locator.registerSingleton(SessionManager());

//Services
locator.registerLazySingleton(() => PostService());
locator.registerLazySingleton(() => EventService());
Expand Down
2 changes: 1 addition & 1 deletion lib/plugins/fetch_plugin_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,6 @@ class FetchPluginList {
),
);
box = Hive.box('pluginBox');
box.put('plugins', result.data!["getPlugins"]);
box.put('plugins', result.data?["getPlugins"]);
}
}
3 changes: 1 addition & 2 deletions lib/services/comment_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import 'package:talawa/locator.dart';
import 'package:talawa/services/database_mutation_functions.dart';
import 'package:talawa/services/navigation_service.dart';
import 'package:talawa/utils/comment_queries.dart';
import 'package:talawa/utils/post_queries.dart';

/// CommentService class have different member functions which provides service in the context of commenting.
///
Expand Down Expand Up @@ -62,7 +61,7 @@ class CommentService {
/// * `Future<List<dynamic>>`: promise that will be fulfilled with list of comments.
///
Future<List<dynamic>> getCommentsForPost(String postId) async {
final String getCommmentQuery = PostQueries().getPostById(postId);
final String getCommmentQuery = CommentQueries().getPostsComments(postId);

final dynamic result = await _dbFunctions.gqlAuthMutation(getCommmentQuery);

Expand Down
35 changes: 24 additions & 11 deletions lib/services/database_mutation_functions.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class DataBaseMutationFunctions {
/// Query passed by fucntion calling this function.
late Queries _query;

/// initialization function.
/// Initialization function.
///
/// **params**:
/// None
Expand All @@ -39,6 +39,19 @@ class DataBaseMutationFunctions {
_query = Queries();
}

/// Initializes [clientNonAuth] function.
///
/// **params**:
/// None
///
/// **returns**:
/// None
void initClientNonAuth() {
graphqlConfig.getOrgUrl();
clientNonAuth = graphqlConfig.clientToQuery();
_query = Queries();
}

/// Graphql error for handling.
GraphQLError userNotFound = const GraphQLError(message: 'User not found');

Expand Down Expand Up @@ -86,7 +99,7 @@ class DataBaseMutationFunctions {
OperationException exception, {
bool showSnackBar = true,
}) {
// if server link is wrong.
// If server link is wrong.
if (exception.linkException != null) {
debugPrint(exception.linkException.toString());
if (showSnackBar) {
Expand All @@ -100,7 +113,7 @@ class DataBaseMutationFunctions {
return false;
}

/// looping through graphQL errors.
/// Looping through graphQL errors.
debugPrint(exception.graphqlErrors.toString());
for (int i = 0; i < exception.graphqlErrors.length; i++) {
// if the error message is "Access Token has expired. Please refresh session.: Undefined location"
Expand All @@ -116,7 +129,7 @@ class DataBaseMutationFunctions {
return true;
}

/// if the error message is "User is not authenticated"
/// If the error message is "User is not authenticated"
if (exception.graphqlErrors[i].message == userNotAuthenticated.message) {
print('client refreshed');
refreshAccessToken(userConfig.currentUser.refreshToken!).then(
Expand All @@ -127,7 +140,7 @@ class DataBaseMutationFunctions {
return true;
}

/// if the error message is "User not found"
/// If the error message is "User not found"
if (exception.graphqlErrors[i].message == userNotFound.message) {
if (showSnackBar) {
WidgetsBinding.instance.addPostFrameCallback(
Expand All @@ -140,7 +153,7 @@ class DataBaseMutationFunctions {
return false;
}

/// if the error message is "Membership Request already exists"
/// If the error message is "Membership Request already exists"
if (exception.graphqlErrors[i].message == memberRequestExist.message) {
if (showSnackBar) {
WidgetsBinding.instance.addPostFrameCallback(
Expand All @@ -153,7 +166,7 @@ class DataBaseMutationFunctions {
return false;
}

/// if the error message is "Invalid credentials"
/// If the error message is "Invalid credentials"
if (exception.graphqlErrors[i].message == wrongCredentials.message) {
if (showSnackBar) {
WidgetsBinding.instance.addPostFrameCallback(
Expand All @@ -166,7 +179,7 @@ class DataBaseMutationFunctions {
return false;
}

/// if the error message is "Organization not found"
/// If the error message is "Organization not found"
if (exception.graphqlErrors[i].message == organizationNotFound.message) {
if (showSnackBar) {
WidgetsBinding.instance.addPostFrameCallback(
Expand All @@ -179,7 +192,7 @@ class DataBaseMutationFunctions {
return false;
}

/// if the error message is "Email address already exists"
/// If the error message is "Email address already exists"
if (exception.graphqlErrors[i].message == emailAccountPresent.message) {
if (showSnackBar) {
WidgetsBinding.instance.addPostFrameCallback(
Expand All @@ -192,7 +205,7 @@ class DataBaseMutationFunctions {
return false;
}
}
// if the error is unknown
// If the error is unknown

WidgetsBinding.instance.addPostFrameCallback(
(_) => navigationService.showTalawaErrorDialog(
Expand Down Expand Up @@ -250,7 +263,7 @@ class DataBaseMutationFunctions {
variables: variables ?? <String, dynamic>{},
),
);
// if there is an error or exception in [result]
// If there is an error or exception in [result]
if (result.hasException) {
final exception = encounteredExceptionOrError(result.exception!);
if (exception!) {
Expand Down
14 changes: 0 additions & 14 deletions lib/services/event_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,10 +71,6 @@ class EventService {
/// **returns**:
/// None
Future<void> getEvents() async {
// refresh user's access token
await _dbFunctions.refreshAccessToken(userConfig.currentUser.refreshToken!);
_dbFunctions.init();

// get current organization id
final String currentOrgID = _currentOrg.id!;
// mutation to fetch the events
Expand Down Expand Up @@ -102,7 +98,6 @@ class EventService {
/// **returns**:
/// * `Future<dynamic>`: Information about event registrants.
Future<dynamic> fetchRegistrantsByEvent(String eventId) async {
await _dbFunctions.refreshAccessToken(userConfig.currentUser.refreshToken!);
final result = await _dbFunctions.gqlAuthQuery(
EventQueries().registrantsByEvent(eventId),
);
Expand All @@ -117,9 +112,6 @@ class EventService {
/// **returns**:
/// * `Future<dynamic>`: Information about the event registration.
Future<dynamic> registerForAnEvent(String eventId) async {
final tokenResult = await _dbFunctions
.refreshAccessToken(userConfig.currentUser.refreshToken!);
debugPrint(tokenResult.toString());
final Map<String, dynamic> variables = {'eventId': eventId};
final result = await _dbFunctions.gqlAuthMutation(
EventQueries().registerForEvent(),
Expand All @@ -139,9 +131,6 @@ class EventService {
navigationService.pushDialog(
const CustomProgressDialog(key: Key('DeleteEventProgress')),
);
final tokenResult = await _dbFunctions
.refreshAccessToken(userConfig.currentUser.refreshToken!);
debugPrint(tokenResult.toString());
final result = await _dbFunctions.gqlAuthMutation(
EventQueries().deleteEvent(eventId),
);
Expand All @@ -166,9 +155,6 @@ class EventService {
key: Key('EditEventProgress'),
),
);
final tokenResult = await _dbFunctions
.refreshAccessToken(userConfig.currentUser.refreshToken!);
debugPrint(tokenResult.toString());
final result = await _dbFunctions.gqlAuthMutation(
EventQueries().updateEvent(eventId: eventId),
variables: variables,
Expand Down
5 changes: 0 additions & 5 deletions lib/services/graphql_config.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// ignore_for_file: talawa_api_doc
// ignore_for_file: talawa_good_doc_comments

import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:hive/hive.dart';
import 'package:http/http.dart' as http;
Expand Down Expand Up @@ -39,8 +36,6 @@ class GraphqlConfig {
orgURI = url ?? ' ';
displayImgRoute = imgUrl ?? ' ';
httpLink = HttpLink(orgURI!);
clientToQuery();
authClient();
}

GraphQLClient clientToQuery() {
Expand Down
2 changes: 0 additions & 2 deletions lib/services/post_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,6 @@ class PostService {
/// **returns**:
/// * `Future<void>`: returns future void
Future<void> getPosts() async {
await _dbFunctions.refreshAccessToken(userConfig.currentUser.refreshToken!);
_dbFunctions.init();
// variables
final String currentOrgID = _currentOrg.id!;
final String query = PostQueries().getPostsById(currentOrgID);
Expand Down
52 changes: 52 additions & 0 deletions lib/services/session_manager.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'dart:async';

import 'package:talawa/locator.dart';

/// Manages user sessions and periodically refreshes access tokens.
class SessionManager {
SessionManager() {
initializeSessionRefresher();
}

/// returns refresh interval of Session Manager.
int get refreshInterval => _refreshInterval;

/// refresh interval in seconds.
static const int _refreshInterval = 600;

/// Initializes as session refresher.
///
/// Invokes [refreshSession] periodically at regular
/// refresh intervals.
///
/// **params**:
/// None
///
/// **returns**:
/// * `Timer`: refresh timer.
Timer initializeSessionRefresher() {
return Timer.periodic(
const Duration(seconds: _refreshInterval),
(Timer timer) async {
refreshSession();
},
);
}

/// Asynchronously refreshes the user session.
///
/// **params**:
/// None
///
/// **returns**:
/// * `Future<bool>`: indicates if session refresh was
/// successful.
Future<bool> refreshSession() async {
if (userConfig.loggedIn && userConfig.currentUser.refreshToken != null) {
final refreshed = await databaseFunctions
.refreshAccessToken(userConfig.currentUser.refreshToken!);
return refreshed;
}
return false;
}
}
Loading

0 comments on commit 204e673

Please sign in to comment.