Skip to content

Commit

Permalink
Test
Browse files Browse the repository at this point in the history
  • Loading branch information
Peter Harrison committed Jan 20, 2024
2 parents cadc347 + 85e8432 commit 82e3356
Show file tree
Hide file tree
Showing 44 changed files with 965 additions and 299 deletions.
7 changes: 7 additions & 0 deletions lib/models/app_tour.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,10 @@ class FocusTarget {
builder: (context, controller) {
return GestureDetector(
onTap: () {
<<<<<<< HEAD
// ignore: avoid_dynamic_calls
=======
>>>>>>> upstream/develop
next?.call();

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

/// next callback that is executed on pressing this target.
<<<<<<< HEAD
Function? next;
=======
Function()? next;
>>>>>>> upstream/develop

/// next target's crossAxisAlignment.
CrossAxisAlignment nextCrossAlign;
Expand Down
12 changes: 10 additions & 2 deletions lib/models/organization/org_info.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class OrgInfo {
this.description,
this.id,
this.image,
this.isPublic,
this.userRegistrationRequired,
this.name,
});

Expand All @@ -34,7 +34,9 @@ class OrgInfo {
name: json['name'] != null ? json['name'] as String? : null,
description:
json['description'] != null ? json['description'] as String? : null,
isPublic: json['isPublic'] != null ? json['isPublic'] as bool? : null,
userRegistrationRequired: json['userRegistrationRequired'] != null
? json['userRegistrationRequired'] as bool?
: null,
creatorInfo: json['creator'] != null
? User.fromJson(
json['creator'] as Map<String, dynamic>,
Expand Down Expand Up @@ -112,9 +114,15 @@ class OrgInfo {
@HiveField(5)
String? description;

<<<<<<< HEAD
/// The org visibility.
@HiveField(6)
bool? isPublic;
=======
/// The org registration is required.
@HiveField(6)
bool? userRegistrationRequired;
>>>>>>> upstream/develop

/// The org creatorInfo.
@HiveField(7)
Expand Down
7 changes: 2 additions & 5 deletions lib/models/organization/org_info.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
2 changes: 1 addition & 1 deletion lib/router.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import 'package:talawa/views/pre_auth_screens/select_language.dart';
import 'package:talawa/views/pre_auth_screens/select_organization.dart';
import 'package:talawa/views/pre_auth_screens/set_url.dart';
import 'package:talawa/views/pre_auth_screens/signup_details.dart';
import 'package:talawa/views/pre_auth_screens/waiting_to_join_private_org.dart';
import 'package:talawa/views/pre_auth_screens/waiting_screen.dart';

/// The MaterialApp provides us with a property called generateRoute where.
///
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: 5 additions & 0 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,8 +69,12 @@ class PostService {
final result = await _dbFunctions.gqlAuthQuery(query);

//Checking if the dbFunctions return the postJSON, if not return.
<<<<<<< HEAD
// ignore:avoid_dynamic_calls
if (result == null || result.data == null) {
=======
if (result == null || (result as QueryResult).data == null) {
>>>>>>> upstream/develop
// Handle the case where the result or result.data is null
return;
}
Expand Down
Loading

0 comments on commit 82e3356

Please sign in to comment.