Skip to main content

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

  1. 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(),
),
);
  1. usersEmails pass users unique id which you send to me when register
  2. 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 on VChatRoomsView widget (this widget you use it to show v chat rooms)
      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 if true 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 in uniqueId

  1. pass vChatGroupChatInfo to the group info page then you can manage the group
  2. groupId pass groupId you will need it to get group data
  3. vChatGroupChatInfo export the following data
  final String title;
final String imageThumb;
final int totalGroupMembers;
final VChatUserGroupRole role;
final bool isGroupCreator;
  1. title group name
  2. imageThumb group full image url
  3. totalGroupMembers group total Members
  4. role current user role in group [admin,member] ar supported
  5. isGroupCreator 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 return getGroupMembers method from with type VChatGroupUser 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;

  1. id the user id which will need it to perform users actions like kick or upgrade or downgrade the member
  2. email the user email which you send to me while register you can use it to get the user data from your system
  3. vChatUserGroupRole enum which contain user role like if user is member or admin so you can show it in your list 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 from members list from this api VChatController.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 from members list from this api VChatController.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 from members list from this api VChatController.instance.getGroupMembers
  1. will delete user from group only if this user in the group
  2. and current user is admin
  3. admin can delete admin but cant delete the group creator
  4. group creator can delete any user but can't be deleted

From admins mean if member try to update will trow exception you dont have access

More info here With Example