Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fixed enable_avoid_dynamic_calls #2312

Merged
merged 19 commits into from
Jan 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions lib/models/app_tour.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,6 @@ class FocusTarget {
builder: (context, controller) {
return GestureDetector(
onTap: () {
// ignore: avoid_dynamic_calls
next?.call();

appTour.tutorialCoachMark.next();
Expand Down Expand Up @@ -174,7 +173,7 @@ class FocusTarget {
AppTour appTour;

/// next callback that is executed on pressing this target.
Function? next;
Function()? next;

/// next target's crossAxisAlignment.
CrossAxisAlignment nextCrossAlign;
Expand Down
6 changes: 2 additions & 4 deletions lib/models/post/post_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
// ignore_for_file: avoid_dynamic_calls

import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/user/user_info.dart';

Expand Down Expand Up @@ -40,13 +38,13 @@ class Post {
: null;
if (json['likedBy'] != null) {
likedBy = <LikedBy>[];
json['likedBy'].forEach((v) {
(json['likedBy'] as List).forEach((v) {
likedBy?.add(LikedBy.fromJson(v as Map<String, dynamic>));
});
}
if (json['comments'] != null) {
comments = <Comments>[];
json['comments'].forEach((v) {
(json['comments'] as List).forEach((v) {
comments?.add(Comments.fromJson(v as Map<String, dynamic>));
});
}
Expand Down
72 changes: 51 additions & 21 deletions lib/services/chat_service.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
// ignore_for_file: talawa_api_doc, avoid_dynamic_calls
// ignore_for_file: talawa_good_doc_comments

import 'dart:async';

import 'package:flutter/foundation.dart';
Expand All @@ -12,33 +9,47 @@ import 'package:talawa/services/database_mutation_functions.dart';
import 'package:talawa/services/user_config.dart';
import 'package:talawa/utils/chat_queries.dart';

/// ChatService class provides different services for direct chats of the user.
/// Provides different services for direct chats of the user.
///
/// Services include:
/// * `sendMessageToDirectChat` - used to send messages.
/// * `getDirectChatsByUserId` - used to get all chats by the user.
/// * `getDirectChatMessagesByChatId` - used to get all chats of a user with another user.
/// * `getDirectChatMessagesByChatId` - gets all chats of a user with
/// another user.
class ChatService {
ChatService() {
_dbFunctions = locator<DataBaseMutationFunctions>();
_chatListStream = _chatController.stream.asBroadcastStream();
_chatMessagesStream = _chatMessageController.stream.asBroadcastStream();
}

/// Database mutation functions.
late DataBaseMutationFunctions _dbFunctions;

/// Stream for chat list data.
late Stream<ChatListTileDataModel> _chatListStream;

/// Stream for chat messages.
late Stream<ChatMessage> _chatMessagesStream;

/// User configuration instance.
final _userConfig = locator<UserConfig>();

/// Stream for GraphQL query results.
late Stream<QueryResult> chatStream;

/// Controller for chat list stream.
final StreamController<ChatListTileDataModel> _chatController =
StreamController<ChatListTileDataModel>();

/// Controller for chat messages stream.
final StreamController<ChatMessage> _chatMessageController =
StreamController<ChatMessage>();

/// Getter for chat list stream.
Stream<ChatListTileDataModel> get chatListStream => _chatListStream;

/// Getter for chat messages stream.
Stream<ChatMessage> get chatMessagesStream => _chatMessagesStream;

// Stream<QueryResult> getMessagesFromDirectChat() async* {
Expand All @@ -50,11 +61,15 @@ class ChatService {
// _cha
// }

/// This function is used to send the message in the direct chats.
/// Sends a message to a direct chat.
///
/// **params**:
/// * `chatId`: The ID of the chat where the message will be sent.
/// * `messageContent`: The content of the message to be sent.
///
/// parameters required:
/// * [chatId] - id of the direct chat where message need to be send.
/// * [messageContent] - the text that need to be send.
/// **returns**:
/// * `Future<void>`: A promise that will be fulfilled
/// when the message is successfully sent.
Future<void> sendMessageToDirectChat(
String chatId,
String messageContent,
Expand All @@ -66,29 +81,37 @@ class ChatService {
);

final message = ChatMessage.fromJson(
result.data['sendMessageToDirectChat'] as Map<String, dynamic>,
(result as QueryResult).data?['sendMessageToDirectChat']
as Map<String, dynamic>,
);

_chatMessageController.add(message);

debugPrint(result.data.toString());
}

/// This function is used to get all the chats by the user.
/// Retrieves direct chats by user ID.
///
/// parameters required:
/// * [usedId] - current user id, to get all the direct chats associated with this id.
/// **params**:
/// None
///
/// **returns**:
/// * `Future<void>`: A promise that will be fulfilled
/// when the direct chats are successfully retrieved.
Future<void> getDirectChatsByUserId() async {
final userId = _userConfig.currentUser.id;

// trigger graphQL query to get all the chats of the user using [userId].
// trigger graphQL query to get all the chats
// of the user using [userId].
final String query = ChatQueries().fetchDirectChatsByUserId(userId!);

final result = await _dbFunctions.gqlAuthQuery(query);

final directMessageList = result.data['directChatsByUserID'] as List;
final directMessageList =
(result as QueryResult).data?['directChatsByUserID'] as List;

// loop through the result [directMessageList] and append the element to the directChat.
// loop through the result [directMessageList]
// and append the element to the directChat.
directMessageList.forEach((chat) {
final directChat =
ChatListTileDataModel.fromJson(chat as Map<String, dynamic>);
Expand All @@ -99,18 +122,25 @@ class ChatService {
});
}

/// This function is used to get all the chat messages of a particular chat by the user.
/// This function retrieves direct chat messages by chat ID.
///
/// **params**:
/// * `chatId`: The ID of the chat for which messages
/// are to be retrieved.
///
/// parameters required:
/// * [chatId] - id of the direct chat.
/// **returns**:
/// * `Future<void>`: A promise that will be fulfilled
/// when the chat messages are successfully retrieved.
Future<void> getDirectChatMessagesByChatId(chatId) async {
// trigger graphQL query to get all the chat messages of a particular chat using [chatId].
// trigger graphQL query to get all the chat messages
// of a particular chat using [chatId].
final String query =
ChatQueries().fetchDirectChatMessagesByChatId(chatId as String);

final result = await _dbFunctions.gqlAuthQuery(query);

final messages = result.data['directChatsMessagesByChatID'] as List;
final messages =
(result as QueryResult).data?['directChatsMessagesByChatID'] as List;

messages.forEach((message) {
final chatMessage = ChatMessage.fromJson(message as Map<String, dynamic>);
Expand Down
6 changes: 3 additions & 3 deletions lib/services/event_service.dart
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
// ignore_for_file: avoid_dynamic_calls

import 'dart:async';

import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/constants/routing_constants.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/events/event_model.dart';
Expand Down Expand Up @@ -83,7 +82,8 @@ class EventService {
final result = await _dbFunctions.gqlAuthMutation(mutation);

if (result == null) return;
final List eventsJson = result.data!["eventsByOrganization"] as List;
final List eventsJson =
(result as QueryResult).data!["eventsByOrganization"] as List;
eventsJson.forEach((eventJsonData) {
final Event event = Event.fromJson(eventJsonData as Map<String, dynamic>);
event.isRegistered = event.registrants?.any(
Expand Down
20 changes: 12 additions & 8 deletions lib/services/org_service.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
// ignore_for_file: talawa_api_doc, avoid_dynamic_calls
// ignore_for_file: talawa_good_doc_comments

import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/user/user_info.dart';
import 'package:talawa/services/database_mutation_functions.dart';
import 'package:talawa/utils/queries.dart';

/// OrganizationService class provides the in the context of organizations.
/// Provides the Services in the context of organizations.
///
/// Services include:
/// * `getOrgMembersList` : to get all organizations members
Expand All @@ -17,16 +15,22 @@ class OrganizationService {
}
late DataBaseMutationFunctions _dbFunctions;

/// This function fetch and returns the list of organization members.
/// Retrieves a list of organization members.
///
/// **params**:
/// * `orgId`: The ID of the organization to fetch members from.
///
/// params:
/// * [orgId] : id of the organization for which members list need be fetched.
/// **returns**:
/// * `Future<List<User>>`: A promise that will be fulfilled
/// with the list of organization members.
Future<List<User>> getOrgMembersList(String orgId) async {
final String query = Queries().fetchOrgDetailsById(orgId);
// fetching from database using graphQL mutations.
final result = await _dbFunctions.gqlAuthMutation(query);
final organizations =
(result as QueryResult).data?['organizations'] as List;
final List orgMembersResult =
result.data['organizations'][0]['members'] as List;
(organizations[0] as Map<String, dynamic>)['members'] as List;
final List<User> orgMembersList = [];
orgMembersResult.forEach((jsonElement) {
final User member =
Expand Down
5 changes: 2 additions & 3 deletions lib/services/post_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:async';

import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/organization/org_info.dart';
import 'package:talawa/models/post/post_model.dart';
Expand Down Expand Up @@ -68,13 +69,11 @@ class PostService {
final result = await _dbFunctions.gqlAuthQuery(query);

//Checking if the dbFunctions return the postJSON, if not return.
// ignore:avoid_dynamic_calls
if (result == null || result.data == null) {
if (result == null || (result as QueryResult).data == null) {
// Handle the case where the result or result.data is null
return;
}

// ignore:avoid_dynamic_calls
final List postsJson = result.data!['postsByOrganization'] as List;

postsJson.forEach((postJson) {
Expand Down
Loading
Loading