Skip to content

Commit

Permalink
Merge branch 'editp' of https://github.com/Dante291/talawa into editp
Browse files Browse the repository at this point in the history
  • Loading branch information
Dante291 committed Dec 24, 2023
2 parents c392182 + b91f1e7 commit bd979c0
Show file tree
Hide file tree
Showing 17 changed files with 785 additions and 179 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ jobs:
uses: VeryGoodOpenSource/very_good_coverage@v2
with:
path: './coverage/lcov.info'
min_coverage: 87.0
min_coverage: 88.0

Android-Build:
name: Testing build for android
Expand Down
9 changes: 9 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -244,3 +244,12 @@ test/fixtures/core
# Ignoring file that are generated during talawa testing and firebase initialization
genhtml.perl
test_img.png


# Ignoring Node files that are generated if user uses any node command which is not required for the project
node_modules/
package.json
package-lock.json
yarn.lock
npm-debug.log
yarn-error.log
47 changes: 29 additions & 18 deletions lib/services/comment_service.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
// 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/services/database_mutation_functions.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 All @@ -18,11 +17,14 @@ class CommentService {

/// This function is used to add comment on the post.
///
/// parameters:
/// * [postId] - Post id where comment need to be added.
/// * [text] - content of the comment.
/// To verify things are working, check out the native platform logs.
/// **params**:
/// * `postId`: The post id on which comment is to be added.
/// * `text`: The comment text.
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled message background activities are successful.
Future<void> createComments(String postId, String text) async {
print("comment service called");
final String createCommentQuery = CommentQueries().createComment();
final result = await _dbFunctions.gqlAuthMutation(
createCommentQuery,
Expand All @@ -31,21 +33,30 @@ class CommentService {
'text': text,
},
);
print("comment added");
print(result);
return result;
}

/// This function is used to fetch all comments on the post.
/// This function is used to get all comments on the post.
///
/// To verify things are working, check out the native platform logs.
/// **params**:
/// * `postId`: The post id for which comments are to be fetched.
///
/// **returns**:
/// * `Future<List<dynamic>>`: promise that will be fulfilled with list of comments.
///
/// parameters:
/// * [postId] - Post id for which comments need to be fetched.
Future getCommentsForPost(String postId) async {
final String getCommmentQuery = CommentQueries().getPostsComments(postId);
final result = await _dbFunctions.gqlAuthMutation(getCommmentQuery);
if (result.data != null) {
return result.data["commentsByPost"] as List;
Future<List<dynamic>> getCommentsForPost(String postId) async {
final String getCommmentQuery = PostQueries().getPostById(postId);

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

if (result == null) {
return [];
}
return [];
final resultData = (result as QueryResult<Object?>).data;

final resultDataPostComments = (resultData?['post']
as Map<String, dynamic>)['comments'] as List<dynamic>;
return resultDataPostComments;
}
}
2 changes: 2 additions & 0 deletions lib/services/user_config.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ class UserConfig {
_currentOrgInfoController.add(_currentOrg!);

_currentUser = boxUser.get('user');

// if there is not currentUser then returns false.
if (_currentUser == null) {
_currentUser = User(id: 'null', authToken: 'null');
Expand All @@ -108,6 +109,7 @@ class UserConfig {
_currentOrgInfoController.add(_currentOrg!);

saveUserInHive();

return true;
} on Exception catch (e) {
print(e);
Expand Down
46 changes: 46 additions & 0 deletions lib/utils/post_queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,52 @@ class PostQueries {
""";
}

/// Getting Post by Post Id.
///
/// **params**:
/// * `postId`: The post id
///
/// **returns**:
/// * `String`: The query related to gettingPostsbyId
String getPostById(String postId) {
return """
query {
post(id: "$postId")
{
_id
text
createdAt
imageUrl
videoUrl
title
commentCount
likeCount
creator{
_id
firstName
lastName
image
}
organization{
_id
}
likedBy{
_id
}
comments{
_id,
text,
createdAt
creator{
firstName
lastName
}
}
}
}
""";
}

/// Add Like to a post.
///
/// **params**:
Expand Down
2 changes: 0 additions & 2 deletions lib/view_model/access_request_view_model.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// ignore_for_file: talawa_api_doc
import 'package:flutter/cupertino.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/constants/routing_constants.dart';
Expand All @@ -23,7 +22,6 @@ class AccessScreenViewModel extends BaseModel {

/// initialization function.
///
///
/// **params**:
/// * `org`: Org to send request to.
///
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

// ignore_for_file: avoid_dynamic_calls

import 'dart:convert';
import 'dart:io';

import 'package:flutter/material.dart';
import 'package:graphql_flutter/graphql_flutter.dart';
import 'package:talawa/enums/enums.dart';
Expand Down Expand Up @@ -72,6 +72,7 @@ class EditProfilePageViewModel extends BaseModel {
}
}


/// modal sheet to choose image.
///
/// more_info_if_required
Expand Down
66 changes: 47 additions & 19 deletions lib/view_model/widgets_view_models/comments_view_model.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:talawa/enums/enums.dart';
import 'package:talawa/locator.dart';
import 'package:talawa/models/comment/comment_model.dart';
Expand All @@ -9,25 +6,41 @@ import 'package:talawa/services/post_service.dart';
import 'package:talawa/services/user_config.dart';
import 'package:talawa/view_model/base_view_model.dart';

/// CommentsViewModel class helps to serve the data from model
/// and to react to user's input for Comment Widget.
/// CommentsViewModel class helps to serve the data from model and to react to user's input for Comment Widget.
///
/// Methods include:
/// * `getComments` : to get all comments on the post.
/// * `createComment` : to add comment on the post.
class CommentsViewModel extends BaseModel {
/// Constructor
late CommentService _commentService;

/// PostService instance.
late PostService _postService;

/// Post id on which comments are to be fetched.
late String _postID;

/// List of comments on the post.
late List<Comment> _commentlist;

/// UserConfig instance.
late UserConfig _userConfig;

// Getters
List<Comment> get commentList => _commentlist;
String get postId => _postID;

// initialiser.
Future initialise(String postID) async {
/// This function is used to initialise the CommentViewModel.
///
/// To verify things are working, check out the native platform logs.
/// **params**:
/// * `postID`: The post id for which comments are to be fetched.
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled message background activities are successful.
///
Future<void> initialise(String postID) async {
_commentlist = [];
_postID = postID;
_commentService = locator<CommentService>();
Expand All @@ -37,31 +50,46 @@ class CommentsViewModel extends BaseModel {
await getComments();
}

/// This methods fetch all comments on the post.
/// The function uses `getCommentsForPost` method by Comment Service.
Future getComments() async {
/// This function is used to get all comments on the post.
///
/// To verify things are working, check out the native platform logs.
/// **params**:
/// None
///
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled when comments are fetched.
///
Future<void> getComments() async {
setState(ViewState.busy);
final List commentsJSON =
await _commentService.getCommentsForPost(_postID) as List;
final List commentsJSON = await _commentService.getCommentsForPost(_postID);
print(commentsJSON);
commentsJSON.forEach((commentJson) {
_commentlist.add(Comment.fromJson(commentJson as Map<String, dynamic>));
});
setState(ViewState.idle);
}

/// This function add comment on the post.
/// The function uses `createComments` method provided by Comment Service.
/// This function add comment on the post. The function uses `createComments` method provided by Comment Service.
///
/// **params**:
/// * `msg`: The comment text.
///
/// params:
/// * `msg` : text of the comment to add.
Future createComment(String msg) async {
/// **returns**:
/// * `Future<void>`: promise that will be fulfilled when comment is added.
///
Future<void> createComment(String msg) async {
print("comment viewModel called");
await _commentService.createComments(_postID, msg);
addCommentLocally(msg);
}

// This function add comment locally.
/// This function add comment locally.
///
/// **params**:
/// * `msg`: BuildContext, contain parent info
///
/// **returns**:
/// None
void addCommentLocally(String msg) {
_postService.addCommentLocally(_postID);
final creator = _userConfig.currentUser;
Expand All @@ -70,7 +98,7 @@ class CommentsViewModel extends BaseModel {
createdAt: DateTime.now().toString(),
creator: creator,
);
_commentlist.insert(0, localComment);
_commentlist.add(localComment);
notifyListeners();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ class CustomDrawerViewModel extends BaseModel {
/// None
void switchOrg(OrgInfo switchToOrg) {
// if `selectedOrg` is equal to `switchOrg` and `switchToOrg` present or not.
if (selectedOrg == switchToOrg && isPresentinSwitchableOrg(switchToOrg)) {
if ((selectedOrg == switchToOrg) &&
(isPresentinSwitchableOrg(switchToOrg))) {
// _navigationService.pop();
navigationService.showTalawaErrorSnackBar(
'${switchToOrg.name} already selected',
Expand Down
Loading

0 comments on commit bd979c0

Please sign in to comment.