33 - SPDX-License-Identifier: AGPL-3.0-or-later
44-->
55
6- <script >
7- import Account from ' vue-material-design-icons/Account.vue'
8- import VolumeHigh from ' vue-material-design-icons/VolumeHigh.vue'
9- import VolumeOff from ' vue-material-design-icons/VolumeOff.vue'
6+ <script setup lang="ts">
7+ import { computed } from ' vue'
8+
9+ import IconAccount from ' vue-material-design-icons/Account.vue'
10+ import IconVolumeHigh from ' vue-material-design-icons/VolumeHigh.vue'
11+ import IconVolumeOff from ' vue-material-design-icons/VolumeOff.vue'
1012
1113import { t } from ' @nextcloud/l10n'
1214
1315import NcCheckboxRadioSwitch from ' @nextcloud/vue/components/NcCheckboxRadioSwitch'
1416
17+ import { useStore } from ' ../../composables/useStore.js'
1518import { PARTICIPANT } from ' ../../constants.ts'
1619import { hasTalkFeature } from ' ../../services/CapabilitiesManager.ts'
20+ import { Conversation } from ' ../../types/index.ts'
1721
1822const supportImportantConversations = hasTalkFeature (' local' , ' important-conversations' )
1923const supportSensitiveConversations = hasTalkFeature (' local' , ' sensitive-conversations' )
2024
2125const notificationLevels = [
22- { value: PARTICIPANT .NOTIFY .ALWAYS , label: t (' spreed' , ' All messages' ) },
23- { value: PARTICIPANT .NOTIFY .MENTION , label: t (' spreed' , ' @-mentions only' ) },
24- { value: PARTICIPANT .NOTIFY .NEVER , label: t (' spreed' , ' Off' ) },
26+ { value: PARTICIPANT .NOTIFY .ALWAYS , icon: IconVolumeHigh , label: t (' spreed' , ' All messages' ) },
27+ { value: PARTICIPANT .NOTIFY .MENTION , icon: IconAccount , label: t (' spreed' , ' @-mentions only' ) },
28+ { value: PARTICIPANT .NOTIFY .NEVER , icon: IconVolumeOff , label: t (' spreed' , ' Off' ) },
2529]
2630
27- export default {
28- name: ' NotificationsSettings' ,
31+ const props = defineProps <{
32+ conversation: Conversation ,
33+ }>()
2934
30- components: {
31- NcCheckboxRadioSwitch,
32- },
35+ const store = useStore ()
3336
34- props: {
35- conversation: {
36- type: Object ,
37- required: true ,
38- },
39- },
37+ const showCallNotificationSettings = computed (() => {
38+ return ! props .conversation .remoteServer || hasTalkFeature (props .conversation .token , ' federation-v2' )
39+ })
4040
41- setup () {
42- return {
43- notificationLevels,
44- supportImportantConversations,
45- supportSensitiveConversations,
46- }
41+ const notifyCalls = computed ({
42+ get : () => props .conversation .notificationCalls === PARTICIPANT .NOTIFY_CALLS .ON ,
43+ set : async (value ) => {
44+ await store .dispatch (' setNotificationCalls' , {
45+ token: props .conversation .token ,
46+ notificationCalls: value ? PARTICIPANT .NOTIFY_CALLS .ON : PARTICIPANT .NOTIFY_CALLS .OFF ,
47+ })
4748 },
48-
49- data () {
50- return {
51- notifyCalls: this .conversation .notificationCalls === PARTICIPANT .NOTIFY_CALLS .ON ,
52- notificationLevel: this .conversation .notificationLevel .toString (),
53- isImportant: this .conversation .isImportant ,
54- isSensitive: this .conversation .isSensitive ,
55- }
49+ })
50+
51+ const notificationLevel = computed ({
52+ get : () => props .conversation .notificationLevel .toString (),
53+ set : async (value ) => {
54+ await store .dispatch (' setNotificationLevel' , {
55+ token: props .conversation .token ,
56+ notificationLevel: value ,
57+ })
5658 },
57-
58- computed: {
59- showCallNotificationSettings () {
60- return ! this .conversation .remoteServer || hasTalkFeature (this .conversation .token , ' federation-v2' )
61- }
59+ })
60+
61+ const isImportant = computed ({
62+ get : () => props .conversation .isImportant ,
63+ set : async (value ) => {
64+ await store .dispatch (' toggleImportant' , {
65+ token: props .conversation .token ,
66+ isImportant: value ,
67+ })
6268 },
63-
64- methods: {
65- t,
66- notificationLevelIcon (value ) {
67- switch (value) {
68- case PARTICIPANT .NOTIFY .ALWAYS :
69- return VolumeHigh
70- case PARTICIPANT .NOTIFY .MENTION :
71- return Account
72- case PARTICIPANT .NOTIFY .NEVER :
73- default :
74- return VolumeOff
75- }
76- },
77-
78- /**
79- * Set the notification level for the conversation
80- *
81- * @param {number} notificationLevel The notification level to set.
82- */
83- async setNotificationLevel (notificationLevel ) {
84- await this .$store .dispatch (' setNotificationLevel' , { token: this .conversation .token , notificationLevel })
85- },
86-
87- /**
88- * Set the call notification level for the conversation
89- *
90- * @param {boolean} isChecked Whether or not call notifications are enabled
91- */
92- async setNotificationCalls (isChecked ) {
93- const notificationCalls = isChecked ? PARTICIPANT .NOTIFY_CALLS .ON : PARTICIPANT .NOTIFY_CALLS .OFF
94- await this .$store .dispatch (' setNotificationCalls' , { token: this .conversation .token , notificationCalls })
95- },
96-
97- /**
98- * Toggle the important flag for the conversation
99- *
100- * @param {boolean} isImportant The important flag to set.
101- */
102- async toggleImportant (isImportant ) {
103- await this .$store .dispatch (' toggleImportant' , { token: this .conversation .token , isImportant })
104- },
105-
106- /**
107- * Toggle the sensitive flag for the conversation
108- *
109- * @param {boolean} isSensitive The sensitive flag to set.
110- */
111- async toggleSensitive (isSensitive ) {
112- await this .$store .dispatch (' toggleSensitive' , { token: this .conversation .token , isSensitive })
113- }
69+ })
70+
71+ const isSensitive = computed ({
72+ get : () => props .conversation .isSensitive ,
73+ set : async (value ) => {
74+ await store .dispatch (' toggleSensitive' , {
75+ token: props .conversation .token ,
76+ isSensitive: value ,
77+ })
11478 },
115- }
79+ })
11680 </script >
11781
11882<template >
@@ -126,28 +90,25 @@ export default {
12690 v-model =" notificationLevel"
12791 :value =" level.value.toString()"
12892 name =" notification_level"
129- type =" radio"
130- @update:model-value =" setNotificationLevel" >
93+ type =" radio" >
13194 <span class =" radio-button" >
132- <component :is =" notificationLevelIcon( level.value) " />
95+ <component :is =" level.icon " />
13396 {{ level.label }}
13497 </span >
13598 </NcCheckboxRadioSwitch >
13699
137100 <NcCheckboxRadioSwitch v-if =" showCallNotificationSettings"
138101 id =" notification_calls"
139102 v-model =" notifyCalls"
140- type =" switch"
141- @update:model-value =" setNotificationCalls" >
103+ type =" switch" >
142104 {{ t('spreed', 'Notify about calls in this conversation') }}
143105 </NcCheckboxRadioSwitch >
144106
145107 <NcCheckboxRadioSwitch v-if =" supportImportantConversations"
146108 id =" important"
147109 v-model =" isImportant"
148110 aria-describedby =" important-hint"
149- type =" switch"
150- @update:model-value =" toggleImportant" >
111+ type =" switch" >
151112 {{ t('spreed', 'Important conversation') }}
152113 </NcCheckboxRadioSwitch >
153114
@@ -159,8 +120,7 @@ export default {
159120 id =" sensitive"
160121 v-model =" isSensitive"
161122 aria-describedby =" sensitive-hint"
162- type =" switch"
163- @update:model-value =" toggleSensitive" >
123+ type =" switch" >
164124 {{ t('spreed', 'Sensitive conversation') }}
165125 </NcCheckboxRadioSwitch >
166126
0 commit comments