Group chat
group chat is
optional
if you don't follow these users can't create group chat until you implement it
I have created public apis for group chat to enable full customizable and optional group chat design
- to create group chat you need to call this api
await VChatController.instance.createGroupChat(
context: context,
createGroupRoomDto: CreateGroupRoomDto(
groupImage: File(imagePath!),
groupTitle: textEditingController.text,
usersEmails: users.map((e) => e.email).toList(),
),
);
usersEmails
pass users unique id which you send to me when register- create you own design and aggregate users then send to v chat list of
emails
How to get group info
- once user click on group image in message page I will run this function
onMessageAvatarPressed
which exist onVChatRoomsView
widget (this widget you use it to show v chatrooms
)
VChatRoomsView(
onMessageAvatarPressed: (isGroupChat, uniqueId, vChatGroupChatInfo) {
if (isGroupChat) {
print("isGroupChat id is $uniqueId");
Navigator.push(
context,
MaterialPageRoute(
builder: (_) => GroupChatInfo(
groupId: uniqueId,
groupChatInfo: vChatGroupChatInfo!,
),
),
);
} else {
print("user Email is $uniqueId");
}
},
),
note
isGroupChat
iftrue
then this group icon pressed else this normal chat icon clicked you may need to open user profile page so i send back the email to help you get user data which inuniqueId
- pass vChatGroupChatInfo to the group info page then you can manage the group
groupId
pass groupId you will need it to get group datavChatGroupChatInfo
export the following data
final String title;
final String imageThumb;
final int totalGroupMembers;
final VChatUserGroupRole role;
final bool isGroupCreator;
title
group nameimageThumb
group full image urltotalGroupMembers
group total Membersrole
current user role in group[admin,member]
ar supportedisGroupCreator
is current user is group creator
To get group users
Future getGroupMembers() async {
this.members.clear();
/// this api will get group users if current use already member in this group
final members = await VChatController.instance
.getGroupMembers(groupId: widget.groupId, paginationIndex: 1);
setState(() {
this.members.addAll(members);
});
}
paginationIndex
to get next users group which it will return 20 user in each call (you will need this api also to perform pagination so increase the number by 1 to get next users list)members
is list which will returngetGroupMembers
method from with typeVChatGroupUser
which contain the following data- will throw exception if current user not in this group chat
final String id;
final String email;
final String name;
final String image;
final VChatUserGroupRole vChatUserGroupRole;
id
the user id which will need it to perform users actions like kick or upgrade or downgrade the memberemail
the user email which you send to me while register you can use it to get the user data from your systemvChatUserGroupRole
enum which contain user role like if user ismember
oradmin
so you can show it in yourlist view
Update group title for admins only
await VChatController.instance.updateGroupChatTitle(
groupId: widget.groupId, title: txt);
Update group image for admins only
final newImage = await VChatController.instance
.updateGroupChatImage(path: img.path, groupId: widget.groupId);
Add members to group for admins only
await VChatController.instance.addMembersToGroupChat(
groupId: widget.groupId,
usersEmails: users.map((e) => e.email).toList());
- build your custom page to get users emails from your system and send them back to this api Example
- also send users email which you send it to me while registrations
Downgrade admin to member for admins only
await VChatController.instance.downgradeGroupAdmin(
groupId: widget.groupId,
userId: user.id,
);
- note
userId
user id you can get it frommembers list
from this apiVChatController.instance.getGroupMembers
- this api will throw exception if current user want to downgrade him self or the group creator
Upgrade member to admin for admins only
await VChatController.instance.upgradeGroupUser(
groupId: widget.groupId, userId: user.id);
- note
userId
user id you can get it frommembers list
from this apiVChatController.instance.getGroupMembers
Kick user from group for admins only
await VChatController.instance.kickUserFromGroup(
groupId: widget.groupId, kickedId: user.id);
- note
userId
user id you can get it frommembers list
from this apiVChatController.instance.getGroupMembers
- will delete user from group only if this user in the group
- and current user is admin
- admin can delete admin but cant delete the group creator
- group creator can delete any user but can't be deleted