Repository: louislam/uptime-kuma
File: src/components/notifications/360messenger.vue (Vue)

Code before:
                return;
            }
            this.isDropdownOpen = !this.isDropdownOpen;
        },
        ensureGroupIdsArray() {
            if (!Array.isArray(this.$parent.notification.Whatsapp360messengerGroupIds)) {
                this.$parent.notification.Whatsapp360messengerGroupIds = this.selectedGroupIds;
            }
        },
        toggleGroupId(id) {
            const trimmed = typeof id === "string" ? id.trim() : "";
            if (!trimmed) {
                return;
            }

            if (this.selectedGroupIds.includes(trimmed)) {
                this.removeGroupId(trimmed);
            } else {
                this.addGroupId(trimmed);
            }
        },
        ensureGroupIdsArray() {
            if (!Array.isArray(this.$parent.notification.Whatsapp360messengerGroupIds)) {
                this.$parent.notification.Whatsapp360messengerGroupIds = this.selectedGroupIds;
            }
        },
        addGroupId(id) {
            const trimmed = typeof id === "string" ? id.trim() : "";
            if (!trimmed) {
                return;
            }

            this.ensureGroupIdsArray();

            // Prefer the new array-based field going forward
            this.$parent.notification.Whatsapp360messengerGroupId = "";

            if (!this.$parent.notification.Whatsapp360messengerGroupIds.includes(trimmed)) {
                this.$parent.notification.Whatsapp360messengerGroupIds.push(trimmed);
            }
        },
        removeGroupId(id) {
            this.ensureGroupIdsArray();
            this.$parent.notification.Whatsapp360messengerGroupIds =
                this.$parent.notification.Whatsapp360messengerGroupIds.filter((x) => x !== id);
        },
        async fetchGroups() {
            this.isLoadingGroups = true;
            this.errorMessage = "";

            try {

Review comment (refactor):
duplicate code.

Also have you considered to watch this value instead?
Longer term, keeping hooks like you did are very hard to maintain.

```suggestion
        },
```

Code after:
                    return;
                }

                let source = value;

                if (!source && this.$parent.notification.Whatsapp360messengerGroupId) {
                    source = this.$parent.notification.Whatsapp360messengerGroupId;
                }

                let normalized = [];

                if (typeof source === "string" && source.trim() !== "") {
                    normalized = source
                        .split(/[;,]/)
                        .map((v) => v.trim())
                        .filter((v) => v !== "");
                }

                this.$parent.notification.Whatsapp360messengerGroupIds = normalized;
            },
        },
    },
    methods: {
        toggleDropdown() {
            if (!this.isOptionsEnabled || this.isLoadingGroups) {
                return;
            }
            this.isDropdownOpen = !this.isDropdownOpen;
        },
        toggleGroupId(id) {
            const trimmed = typeof id === "string" ? id.trim() : "";
            if (!trimmed) {
                return;
            }

            if (this.selectedGroupIds.includes(trimmed)) {
                this.removeGroupId(trimmed);
            } else {
                this.addGroupId(trimmed);
            }
        },
        addGroupId(id) {
            const trimmed = typeof id === "string" ? id.trim() : "";
            if (!trimmed) {
                return;
            }

            const list = this.$parent.notification.Whatsapp360messengerGroupIds;
            if (!Array.isArray(list)) {
                return;
            }