Skip to content

Instantly share code, notes, and snippets.

@hieptl
Last active October 27, 2021 10:09
Show Gist options
  • Save hieptl/e9cb49babe799b3e60498d3d23aa3106 to your computer and use it in GitHub Desktop.
Save hieptl/e9cb49babe799b3e60498d3d23aa3106 to your computer and use it in GitHub Desktop.
ManageGroup.tsx - Delete Group & Leave Group - Ionic Chat App
...
const handleDeleteGroup = () => {
if (selectedConversation && selectedConversation.name && selectedConversation.guid) {
setIsLoading(true);
cometChat.deleteGroup(selectedConversation.guid).then(
(response: any) => {
setIsLoading(false);
alert(`${selectedConversation.name} was deleted successfully`);
history.push('/');
},
(error: any) => {
setIsLoading(false);
alert(`Failure to delete ${selectedConversation.name}`)
}
);
}
};
const deleteGroup = () => {
const shouldDeleteGroup = window.confirm(`Do you want to delete group ${selectedConversation.name}`);
if (shouldDeleteGroup) {
handleDeleteGroup();
}
};
const handleLeaveGroup = () => {
if (selectedConversation && selectedConversation.guid && selectedConversation.name) {
setIsLoading(true);
cometChat.leaveGroup(selectedConversation.guid).then(
(hasLeft: any) => {
setIsLoading(false);
alert(`${user.name} has left the group ${selectedConversation.name}`);
history.push('/');
}, (error: any) => {
}
);
}
};
const leaveGroup = () => {
const shouldLeaveGroup = window.confirm(`Do you want to leave group ${selectedConversation.name}`);
if (shouldLeaveGroup) {
handleLeaveGroup();
}
};
...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment