Skip to content

Commit

Permalink
feat: Filter deleted user from user related api
Browse files Browse the repository at this point in the history
  • Loading branch information
kornsitti committed Jul 26, 2024
1 parent bfb3264 commit ce6157b
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 22 deletions.
5 changes: 5 additions & 0 deletions lib/core/widget/channel_member_info_row_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,11 @@ class ChannelMemberInfoRowWidget extends StatelessWidget {
style: themeData.textTheme.bodySmall,
textAlign: TextAlign.start,
),
Text(
'isDeleted - ${value.isDeleted ?? false}',
style: themeData.textTheme.bodySmall,
textAlign: TextAlign.start,
),
Text(
'Flag Count - ${value.user?.flagCount ?? 0}',
style: themeData.textTheme.bodySmall,
Expand Down
5 changes: 5 additions & 0 deletions lib/core/widget/community_member_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,11 @@ class _CommunityMemberInfoRowWidget extends StatelessWidget {
style: themeData.textTheme.bodySmall,
textAlign: TextAlign.start,
),
Text(
'isDeleted - ${value.isDeleted ?? false}',
style: themeData.textTheme.bodySmall,
textAlign: TextAlign.start,
),
],
),
),
Expand Down
10 changes: 5 additions & 5 deletions lib/core/widget/dialog/amity_user_info_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,27 +67,27 @@ class AmityUserInfoWidget extends StatelessWidget {
),
// Text(
// 'roles - $rolesText',
// style: _themeData.textTheme.caption,
// style: _themeData.textTheme.bodySmall,
// textAlign: TextAlign.start,
// ),
// Text(
// 'permissions - $permissionText',
// style: _themeData.textTheme.caption,
// style: _themeData.textTheme.bodySmall,
// textAlign: TextAlign.start,
// ),
// Text(
// 'isBanned - ${value.isBanned ?? false}',
// style: _themeData.textTheme.caption,
// style: _themeData.textTheme.bodySmall,
// textAlign: TextAlign.start,
// ),
// Text(
// 'isMuted - ${value.isMuted ?? false}',
// style: _themeData.textTheme.caption,
// style: _themeData.textTheme.bodySmall,
// textAlign: TextAlign.start,
// ),
// Text(
// 'Flag Count - ${value.flagCount ?? 0}',
// style: _themeData.textTheme.caption,
// style: _themeData.textTheme.bodySmall,
// textAlign: TextAlign.start,
// ),
],
Expand Down
10 changes: 5 additions & 5 deletions lib/core/widget/message_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ class MessageWidget extends StatelessWidget {
Text(

value.createdAt?.toLocal().toIso8601String() ?? DateTime.now().toLocal().toIso8601String(),
style: themeData.textTheme.caption!.copyWith(),
style: themeData.textTheme.bodySmall!.copyWith(),

),
const SizedBox(width: 12),
Expand Down Expand Up @@ -394,7 +394,7 @@ class MessageWidget extends StatelessWidget {
child: Text(

value.reactions!.getCount('like').toString(),
style: themeData.textTheme.caption!.copyWith(fontSize: 14),
style: themeData.textTheme.bodySmall!.copyWith(fontSize: 14),

),
),
Expand Down Expand Up @@ -442,7 +442,7 @@ class MessageWidget extends StatelessWidget {
child: Text(

value.reactions!.getCount('like').toString(),
style: themeData.textTheme.caption!.copyWith(fontSize: 14),
style: themeData.textTheme.bodySmall!.copyWith(fontSize: 14),

),
),
Expand Down Expand Up @@ -488,7 +488,7 @@ class MessageWidget extends StatelessWidget {
children: [
Text(
value.reactions!.getCount('love').toString(),
style: themeData.textTheme.caption!.copyWith(fontSize: 14),
style: themeData.textTheme.bodySmall!.copyWith(fontSize: 14),
),
const SizedBox(width: 2),
Image.asset(
Expand Down Expand Up @@ -532,7 +532,7 @@ class MessageWidget extends StatelessWidget {
children: [
Text(
value.reactions!.getCount('love').toString(),
style: themeData.textTheme.caption!.copyWith(fontSize: 14),
style: themeData.textTheme.bodySmall!.copyWith(fontSize: 14),
),
const SizedBox(width: 2),
Image.asset(
Expand Down
28 changes: 28 additions & 0 deletions lib/presentation/screen/channel_member/channel_member_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ class ChannelMemberScreenState extends State<ChannelMemberScreen> {

String _keyboard = '';

bool _includeDeleted = false;

final _debouncer = Debouncer(milliseconds: 500);

@override
Expand All @@ -35,6 +37,7 @@ class ChannelMemberScreenState extends State<ChannelMemberScreen> {
pageFuture: (token) => AmityChatClient.newChannelRepository()
.membership(widget.channelId)
.searchMembers(_keyboard)
.includeDeleted(_includeDeleted)
.getPagingData(token: token, limit: GlobalConstant.pageSize),
pageSize: GlobalConstant.pageSize,
)..addListener(
Expand Down Expand Up @@ -108,6 +111,31 @@ class ChannelMemberScreenState extends State<ChannelMemberScreen> {
decoration: const InputDecoration(hintText: 'Enter Keybaord'),
),
),
Container(
child: Row(
children: [
Container(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
value: _includeDeleted,
onChanged: (value) {
setState(() {
_includeDeleted = (value ?? false);
_controller.reset();
_controller.fetchNextPage();
});
},
),
const Text('Include Deleted')
],
),
)
],
),
),
Expanded(
child: amityChannelMembers.isNotEmpty
? RefreshIndicator(
Expand Down
62 changes: 50 additions & 12 deletions lib/presentation/screen/community_list/community_list_screen.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import 'dart:developer';

import 'package:amity_sdk/amity_sdk.dart';
import 'package:flutter/material.dart';
import 'package:flutter_social_sample_app/core/route/app_route.dart';
Expand All @@ -14,7 +16,9 @@ class CommunityListScreen extends StatefulWidget {
}

class _CommunityListScreenState extends State<CommunityListScreen> {
var amityCommunities = <AmityCommunity>[];
// var amityCommunities = <AmityCommunity>[];
final List<AmityCommunity> _amityCommunities = [];
final List<AmityCommunity> _amityCommunitiesForFeed = [];

final scrollcontroller = ScrollController();
bool loading = false;
Expand All @@ -35,6 +39,7 @@ class _CommunityListScreenState extends State<CommunityListScreen> {
void initState() {

communityLiveCollectionInit();
initMyCommunity();
super.initState();
}

Expand All @@ -51,13 +56,13 @@ class _CommunityListScreenState extends State<CommunityListScreen> {
.build());


communityLiveCollection.getStreamController().stream.listen((event) {
if (mounted) {
setState(() {
amityCommunities = event;
});
}
});
// communityLiveCollection.getStreamController().stream.listen((event) {
// if (mounted) {
// setState(() {
// amityCommunities = event;
// });
// }
// });

WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
communityLiveCollection.loadNext();
Expand All @@ -66,6 +71,39 @@ class _CommunityListScreenState extends State<CommunityListScreen> {
scrollcontroller.addListener(pagination);
}

Future<void> initMyCommunity([String? keyword]) async {
final repository = AmitySocialClient.newCommunityRepository()
.getCommunities()
.filter(AmityCommunityFilter.MEMBER)
.includeDeleted(false);
if (keyword != null && keyword.isNotEmpty) {
repository.withKeyword(
keyword); // Add keyword filtering only if keyword is provided and not empty
}
communityLiveCollection = repository.getLiveCollection(pageSize: 20);
communityLiveCollection.getStreamController().stream.listen((event) {
print("getStreamController");
_amityCommunitiesForFeed.clear();
_amityCommunitiesForFeed.addAll(event);

_amityCommunities.clear();
_amityCommunities.addAll(event);

setState(() {

});

}).onError((error, stackTrace) {
log("error:${error.error.toString()}");
// await AmityDialog().showAlertErrorDialog(
// title: "Error!",
// message: _communityController.error.toString());
});

scrollcontroller.removeListener(() {});
scrollcontroller.addListener(pagination);
}

void pagination() {
if ((scrollcontroller.position.pixels ==
scrollcontroller.position.maxScrollExtent) &&
Expand Down Expand Up @@ -216,17 +254,17 @@ class _CommunityListScreenState extends State<CommunityListScreen> {
),
),
Expanded(
child: amityCommunities.isNotEmpty
child: _amityCommunities.isNotEmpty
? RefreshIndicator(
onRefresh: () async {
communityLiveCollection.reset();
communityLiveCollectionInit();
},
child: ListView.builder(
controller: scrollcontroller,
itemCount: amityCommunities.length,
itemCount: _amityCommunities.length,
itemBuilder: (context, index) {
final amityCommunity = amityCommunities[index];
final amityCommunity = _amityCommunities[index];
return Container(
margin: const EdgeInsets.all(12),
child: CommunityWidget(
Expand All @@ -248,7 +286,7 @@ class _CommunityListScreenState extends State<CommunityListScreen> {
: const Text('No Post'),
),
),
if (amityCommunities.isNotEmpty && communityLiveCollection.isFetching)
if (_amityCommunities.isNotEmpty && communityLiveCollection.isFetching)
Container(
alignment: Alignment.center,
child: const CircularProgressIndicator(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CommunityMemberScreenState extends State<CommunityMemberScreen> {

AmityCommunityMembershipFilter _filter = AmityCommunityMembershipFilter.MEMBER;
AmityCommunityMembershipSortOption _sort = AmityCommunityMembershipSortOption.LAST_CREATED;
bool _includeDeleted = false;
@override
void initState() {
_controller = PagingController(
Expand All @@ -35,6 +36,7 @@ class CommunityMemberScreenState extends State<CommunityMemberScreen> {
.searchMembers(_keyboard)
.filter(_filter)
.sortBy(_sort)
.includeDeleted(_includeDeleted)
.getPagingData(token: token, limit: GlobalConstant.pageSize),
pageSize: GlobalConstant.pageSize,
)..addListener(
Expand Down Expand Up @@ -181,6 +183,25 @@ class CommunityMemberScreenState extends State<CommunityMemberScreen> {
},
),
),
Container(
padding: const EdgeInsets.all(8),
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Checkbox(
value: _includeDeleted,
onChanged: (value) {
setState(() {
_includeDeleted = (value ?? false);
_controller.reset();
_controller.fetchNextPage();
});
},
),
const Text('Include Deleted')
],
),
)
],
),
),
Expand Down

0 comments on commit ce6157b

Please sign in to comment.