Chat app with Ionic 3 & Firebase – Ep. 15 – Leaving / deleting groups

Hi Friends,

Hope you are all well. In this post let’s see how to add the leave group functionality for a member and the delete group functionality for the owner of the group.

I assume you have read the previous posts in this series and you have a copy of the code with you.

Let’s begin.


The code for this episode is available – here

The complete code for this series is available – here. (Would highly appreciate it if you could leave a star to this repo. Thanks)

Leaving a group:

Open up groupchat.ts and add the below code to the handler function of the leave group option in the member sheet.

We are simply calling a leavegroup() function in the groups provider.

Open up groups.ts file (in the provider directory) and then add the code shown below.

Let’s break this down.

We need to perform two steps to leave a group.

  1. Remove the instance of the group under the uid of the person who leaves the group.
  2. Remove his details from the members list of that group under the group owner’s uid.

That’s exactly is what’s being done in the above snippet of code.

Deleting a group:

First of all, this option is available only to group owners. Group owners can’t leave a group that they created, they can only delete it.

Open up groupschat.ts file and add the below code in the presentOwnerSheet() function

Open up groups.ts (in the providers directory) so that we can write the deletegroup() method there.

Deleting a group involves two steps as well.

  1. Get the members list under the group instance, remove the group instance under each member’s uid.
  2. Remove the group instance under the owner’s uid.

This is what we are doing with the above snippet of code.

DB structure before deleting a group.


The group being deleted. (First group)



In our next part we’ll see how to send messages in the group.

Thanks for all the support you have been showing me on patreon guys. If you would like to support me on patreon kindly click here.

To donate click here.

Hope this helped you guys. If you found this helpful, kindly share it with someone else and help them too.

Thanks for reading.. Peace.. :)

Liked it? Take a second to support admin on Patreon!