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

fix(post): fixed the profile picture feature for users liking and commenting on post #2355

Closed
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
16 changes: 16 additions & 0 deletions lib/services/post_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ 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';
import 'package:talawa/models/user/user_info.dart';
import 'package:talawa/services/database_mutation_functions.dart';
import 'package:talawa/services/user_config.dart';
import 'package:talawa/utils/post_queries.dart';
Expand Down Expand Up @@ -145,13 +146,28 @@ class PostService {
return result;
}


Future<User> fetchUserInfoById(String userId) async {
final QueryResult result1 = await databaseFunctions.gqlAuthQuery(
queries.fetchUserInfo,
variables: {'id': userId},
) as QueryResult;
final User userInfo = User.fromJson(
((result1.data!['users'] as List<dynamic>)[0]) as Map<String, dynamic>,
fromOrg: true,
);
return userInfo;
}


/// Locally add like on a Post and updates it using updated Post Stream.
///
/// **params**:
/// * `postID`: ID of the post to add like locally
///
/// **returns**:
/// None

void _localAddLike(String postID) {
_posts.forEach((post) {
if (post.sId == postID) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class LikeButtonViewModel extends BaseModel {
// Local Variables for session caching
bool _isLiked = false;
late User _user;
late User _likedByUser;
List<LikedBy> _likedBy = [];
late String _postID;

Expand All @@ -33,6 +34,7 @@ class LikeButtonViewModel extends BaseModel {
bool get isLiked => _isLiked;
List<LikedBy> get likedBy => _likedBy;
int get likesCount => _likedBy.length;
User get likedByUser => _likedByUser;

/// First function to initialize the ViewModel.
///
Expand Down Expand Up @@ -65,6 +67,10 @@ class LikeButtonViewModel extends BaseModel {
}
}

Future<void> fetchLikedByUser(String userId) async {
_likedByUser = await _postService.fetchUserInfoById(userId);
}

/// function to set isLiked boolean.
///
/// **params**:
Expand Down
57 changes: 32 additions & 25 deletions lib/views/after_auth_screens/feed/individual_post.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:talawa/models/comment/comment_model.dart';
import 'package:talawa/models/post/post_model.dart';
import 'package:talawa/utils/app_localization.dart';
import 'package:talawa/view_model/widgets_view_models/comments_view_model.dart';
import 'package:talawa/view_model/widgets_view_models/like_button_view_model.dart';
import 'package:talawa/views/base_view.dart';
import 'package:talawa/widgets/post_widget.dart';

Expand Down Expand Up @@ -193,7 +194,8 @@ class CommentTemplate extends StatelessWidget {
return Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const CircleAvatar(),
CircleAvatar(
backgroundImage: NetworkImage(comment.creator?.image ?? "")),
Expanded(
Comment on lines +197 to 199
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please also add a fallback image to this as well

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will do it, thanks!

child: Container(
decoration: BoxDecoration(
Expand Down Expand Up @@ -230,28 +232,33 @@ class CommentTemplate extends StatelessWidget {

/// likedUserCircleAvatar returns a widget of the individual user liked the post.
Widget likedUserCircleAvatar(LikedBy user) {
return const Padding(
padding: EdgeInsets.only(right: 10.0, bottom: 16.0),
child: Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
CircleAvatar(
backgroundColor: Color(0xfff2f2f2),
radius: 20,
),
Positioned(
top: 30,
right: 0,
bottom: 20,
left: 20,
child: Icon(
Icons.thumb_up,
color: Colors.blue,
size: 20,
),
),
],
),
);
return BaseView<LikeButtonViewModel>(
onModelReady: (model) async {
await model.fetchLikedByUser(user.sId ?? "");
},
builder: (context, model, child) => Padding(
padding: const EdgeInsets.only(right: 10.0, bottom: 16.0),
child: Stack(
clipBehavior: Clip.none,
alignment: Alignment.center,
children: [
CircleAvatar(
backgroundImage: NetworkImage(model.likedByUser.image ?? ""),
backgroundColor: const Color(0xfff2f2f2),
radius: 20,
),
const Positioned(
top: 30,
right: 0,
bottom: 20,
left: 20,
child: Icon(
Icons.thumb_up,
color: Colors.blue,
size: 20,
),
),
],
),
));
}
Loading