diff --git a/src/components/ChatSettingsComponent.vue b/src/components/ChatSettingsComponent.vue index d58b682..0cb6150 100644 --- a/src/components/ChatSettingsComponent.vue +++ b/src/components/ChatSettingsComponent.vue @@ -2,20 +2,20 @@ -
{{ props.chat!.displayName }}
+
{{ chat!.displayName }}
-
+
-
Mitglieder ({{ members.length }})
+
Mitglieder ({{ chat!.members.length }})
- + - @@ -24,24 +24,24 @@ - +
Namen ändern
- +
Aktionen
- Gruppenchat verlassen - Grupepnchat löschen + Gruppenchat verlassen + Gruppenchat löschen
- +
Gruppenbild ändern
import { computed, ref } from 'vue'; import ProfileCardComponent from './ProfileCardComponent.vue'; -import { useUserStore } from 'src/stores/user-store'; -import { chat, profilePicture, ptpUser, responseModel } from 'src/models'; -import { useChatStore } from 'src/stores/chat-store'; -import { useQuasar } from 'quasar'; -import { sendNotification } from 'src/utils'; + import { useUserStore } from 'src/stores/user-store'; + import { profilePicture, ptpUser, responseModel } from 'src/models'; + import type { chat } from 'src/models'; + import { useChatStore } from 'src/stores/chat-store'; + import { useQuasar } from 'quasar'; + import { sendNotification } from 'src/utils'; - const showDialog = ref(true); const userStore = useUserStore(); const chatStore = useChatStore(); @@ -81,7 +81,8 @@ import { sendNotification } from 'src/utils'; const emit = defineEmits(['update:showDialog', 'showModal']); const props = defineProps({ showDialog: Boolean, - chat: Object + chatID: Number, + leaveChat: Function }); const internalShowDialog = computed({ @@ -94,37 +95,39 @@ import { sendNotification } from 'src/utils'; } const selectProfilePicture = (image: profilePicture) => { - props.chat!.profilepictureAsString = image.url; + chat.value!.profilepictureAsString = image.url; + //props.chat!.profilepictureAsString = image.url; showUnsavedChangesAlert(); } const $q = useQuasar(); - const members = ref([] as ptpUser[]); - members.value = props.chat!.members; + const chat = ref(chatStore.chats.find((chat) => chat.id == props.chatID)); + + const currentUserIsAdmin = computed(() => { + return chat.value!.adminIds.includes(userStore.user!.id); + }); const removeUser = (keycloakID : string) => { - chatStore.removeUserFromChat(keycloakID, props.chat!.id).then((response : responseModel) => { - reloadChats(); - sendNotification(response.message, response.success); - if(response.success) { - members.value = members.value.filter((user) => user.id != keycloakID); - } + chatStore.removeUserFromChat(keycloakID, props.chatID!).then((response : responseModel) => { + chatStore.loadChatsByUser().then(() => { + if(response.success) { + if(userStore.user!.id == keycloakID) { + sendNotification("Du hast den Chat verlassen", true); + props.leaveChat!(); + closeDialog(); + } else { + sendNotification(response.message, response.success); + } - if(members.value.length == 1) { - sendNotification("Es ist ein kritischer Fehler aufgetreten", false); - } else if(members.value.length == 2) { - closeDialog(); - } + chat.value = chatStore.chats.find((chat) => chat.id == props.chatID); + } + }); }); } - const reloadChats = async() => { - await chatStore.loadChatsByUser(); - }; - const saveChatChanges = () => { - chatStore.updateChat(props.chat! as chat).then((response : responseModel) => { + chatStore.updateChat(chat.value as chat).then((response : responseModel) => { showingAlert.value = false; sendNotification(response.message, response.success); });
+