Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(groups): group user list #810

Merged
merged 8 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
48 changes: 19 additions & 29 deletions src/lib/components/group/ViewMembers.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@
import { Appearance, Shape, Size } from "$lib/enums"
import type { Chat, User } from "$lib/types"
import ProfilePicture from "../profile/ProfilePicture.svelte"
import { Checkbox, Input, Text } from "$lib/elements"
import Controls from "$lib/layouts/Controls.svelte"
import { Checkbox, Text } from "$lib/elements"
import Button from "$lib/elements/Button.svelte"
import Icon from "$lib/elements/Icon.svelte"
import Label from "$lib/elements/Label.svelte"
Expand All @@ -20,37 +19,28 @@
let allRecipients: User[] = []
let friends: User[] = [] // Initialize friends as an empty array

function update_members(user: User) {
let group_members = [...members]

if (group_members.includes(user)) {
group_members.splice(group_members.indexOf(user), 1)
} else {
group_members.push(user)
}

members = group_members
RaygunStoreInstance.addGroupParticipants(activeChat.id, [user.key])
}

function remove_member(user: User) {
if (members.length < 3) {
Store.addToastNotification(new ToastMessage("", `A group can not exist with one person`, 2))
return
}
function updateMembers(user: User) {
if (user.key === activeChat.creator) {
Store.addToastNotification(new ToastMessage("", `You can not remove the group creator`, 2))
Store.addToastNotification(new ToastMessage("", $_("chat.group.removeCreator"), 2))
members = members
return
}
let groupMembers = [...members]

let group_members = [...members]

if (group_members.includes(user)) {
group_members.splice(group_members.indexOf(user), 1)
if (groupMembers.includes(user)) {
if (members.length < 3) {
Store.addToastNotification(new ToastMessage("", $_("chat.group.removeTooSmall"), 2))
members = members
return
}
groupMembers.splice(groupMembers.indexOf(user), 1)
RaygunStoreInstance.removeGroupParticipants(activeChat.id, [user.key])
} else {
groupMembers.push(user)
RaygunStoreInstance.addGroupParticipants(activeChat.id, [user.key])
}

members = group_members
RaygunStoreInstance.removeGroupParticipants(activeChat.id, [user.key])
members = groupMembers
}

function contains_user(list: User[], user: User): boolean {
Expand Down Expand Up @@ -104,7 +94,7 @@
<Text hook="mini-recipient-name" singleLine size={Size.Small} appearance={Appearance.Alt}>
{recipient.name}
</Text>
<Button hook="mini-recipient-button" small icon on:click={() => remove_member(recipient)} appearance={Appearance.Alt}>
<Button hook="mini-recipient-button" small icon on:click={() => updateMembers(recipient)} appearance={Appearance.Alt}>
<Icon icon={Shape.XMark} alt class="control" />
</Button>
</div>
Expand All @@ -113,7 +103,7 @@
<Label hook="label-edit-members" text={$_("chat.group.settings.edit")} />
<div class="recipient-selection-list" data-cy="recipient-selection-list">
{#each allRecipients as recipient (recipient.key)}
<button data-cy="recipient-single" class="recipient" on:click={() => update_members(recipient)}>
<button data-cy="recipient-single" class="recipient" on:click={() => updateMembers(recipient)}>
<ProfilePicture hook="recipient-single-profile-picture" size={Size.Small} image={recipient.profile.photo.image} status={recipient.profile.status} />
<div data-cy="recipient-single-info" class="info">
<Text hook="recipient-single-name" singleLine size={Size.Medium}>
Expand Down
4 changes: 3 additions & 1 deletion src/lib/lang/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,9 @@
"details.description": "Allow anyone to change the name and MOTD of the group",
"photo": "Change Photo",
"photo.description": "Allow anyone to change the group photo"
}
},
"removeCreator": "You can not remove the group creator",
"removeTooSmall": "A group can not exist with one person"
},
"call": "Audio Call",
"videocall": "Video Call",
Expand Down