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 type { 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' ,
29-
30- components: {
31- NcCheckboxRadioSwitch,
32- },
33-
34- props: {
35- conversation: {
36- type: Object ,
37- required: true ,
38- },
39- },
40-
41- setup () {
42- return {
43- notificationLevels,
44- supportImportantConversations,
45- supportSensitiveConversations,
46- }
47- },
31+ const props = defineProps <{
32+ conversation: Conversation ,
33+ }>()
34+
35+ const store = useStore ()
36+
37+ const showCallNotificationSettings = computed (() => {
38+ return ! props .conversation .remoteServer || hasTalkFeature (props .conversation .token , ' federation-v2' )
39+ })
40+
41+ const notificationLevel = computed (() => props .conversation .notificationLevel .toString ())
42+
43+ /**
44+ * Set the notification level for the conversation
45+ * FIXME: should be a computed with type "number", but it doesn't work at Vue 2 TS
46+ *
47+ * @param value The notification level to set.
48+ */
49+ async function setNotificationLevel(value : string ) {
50+ await store .dispatch (' setNotificationLevel' , {
51+ token: props .conversation .token ,
52+ notificationLevel: + value ,
53+ })
54+ }
4855
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- }
56+ const notifyCalls = computed ( {
57+ get : () => props . conversation . notificationCalls === PARTICIPANT . NOTIFY_CALLS . ON ,
58+ set : async ( value ) => {
59+ await store . dispatch ( ' setNotificationCalls ' , {
60+ token: props .conversation .token ,
61+ notificationCalls: value ? PARTICIPANT . NOTIFY_CALLS . ON : PARTICIPANT . NOTIFY_CALLS . OFF ,
62+ })
5663 },
57-
58- computed: {
59- showCallNotificationSettings () {
60- return ! this .conversation .remoteServer || hasTalkFeature (this .conversation .token , ' federation-v2' )
61- }
64+ })
65+
66+ const isImportant = computed ({
67+ get : () => props .conversation .isImportant ,
68+ set : async (value ) => {
69+ await store .dispatch (' toggleImportant' , {
70+ token: props .conversation .token ,
71+ isImportant: value ,
72+ })
6273 },
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- }
74+ })
75+
76+ const isSensitive = computed ({
77+ get : () => props .conversation .isSensitive ,
78+ set : async (value ) => {
79+ await store .dispatch (' toggleSensitive' , {
80+ token: props .conversation .token ,
81+ isSensitive: value ,
82+ })
11483 },
115- }
84+ })
11685 </script >
11786
11887<template >
@@ -123,31 +92,29 @@ export default {
12392
12493 <NcCheckboxRadioSwitch v-for =" level in notificationLevels"
12594 :key =" level.value"
126- v- model =" notificationLevel"
95+ : model-value =" notificationLevel"
12796 :value =" level.value.toString()"
12897 name =" notification_level"
12998 type =" radio"
13099 @update:model-value =" setNotificationLevel" >
131100 <span class =" radio-button" >
132- <component :is =" notificationLevelIcon( level.value) " />
101+ <component :is =" level.icon " />
133102 {{ level.label }}
134103 </span >
135104 </NcCheckboxRadioSwitch >
136105
137106 <NcCheckboxRadioSwitch v-if =" showCallNotificationSettings"
138107 id =" notification_calls"
139108 v-model =" notifyCalls"
140- type =" switch"
141- @update:model-value =" setNotificationCalls" >
109+ type =" switch" >
142110 {{ t('spreed', 'Notify about calls in this conversation') }}
143111 </NcCheckboxRadioSwitch >
144112
145113 <NcCheckboxRadioSwitch v-if =" supportImportantConversations"
146114 id =" important"
147115 v-model =" isImportant"
148116 aria-describedby =" important-hint"
149- type =" switch"
150- @update:model-value =" toggleImportant" >
117+ type =" switch" >
151118 {{ t('spreed', 'Important conversation') }}
152119 </NcCheckboxRadioSwitch >
153120
@@ -159,8 +126,7 @@ export default {
159126 id =" sensitive"
160127 v-model =" isSensitive"
161128 aria-describedby =" sensitive-hint"
162- type =" switch"
163- @update:model-value =" toggleSensitive" >
129+ type =" switch" >
164130 {{ t('spreed', 'Sensitive conversation') }}
165131 </NcCheckboxRadioSwitch >
166132
0 commit comments