Welcome to mirror list, hosted at ThFree Co, Russian Federation.

ExpirationSettings.vue « ConversationSettings « components « src - github.com/nextcloud/spreed.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 26aebc6589c90fdb7ab10367dd7de6974dc4b675 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!--
  - @copyright Copyright (c) 2022 Joas Schilling <coding@schilljs.com>
  -
  - @author Joas Schilling <coding@schilljs.com>
  -
  - @license GNU AGPL version 3 or any later version
  -
  - This program is free software: you can redistribute it and/or modify
  - it under the terms of the GNU Affero General Public License as
  - published by the Free Software Foundation, either version 3 of the
  - License, or (at your option) any later version.
  -
  - This program is distributed in the hope that it will be useful,
  - but WITHOUT ANY WARRANTY; without even the implied warranty of
  - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  - GNU Affero General Public License for more details.
  -
  - You should have received a copy of the GNU Affero General Public License
  - along with this program. If not, see <http://www.gnu.org/licenses/>.
-->

<template>
	<div>
		<div class="app-settings-section__hint">
			{{ t('spreed', 'Expire chat messages after a certain time. Note files shared into the chat will only be unshared from the conversation but are not deleted for the owner.') }}
		</div>
		<Multiselect :value="selectedOption"
			:options="expirationOptions"
			:allow-empty="false"
			track-by="id"
			label="label"
			:close-on-select="true"
			@update:value="changeExpiration" />
	</div>
</template>

<script>
import Multiselect from '@nextcloud/vue/dist/Components/Multiselect'
import { showError, showSuccess } from '@nextcloud/dialogs'

export default {
	name: 'ExpirationSettings',

	components: {
		Multiselect,
	},

	props: {
		token: {
			type: String,
			default: null,
		},
	},

	data() {
		return {
			overwriteExpiration: undefined,
			defaultExpirationOptions: [
				{ id: 0, label: t('spreed', 'Off') },
				{ id: 2419200, label: n('spreed', '%n week', '%n weeks', 4) },
				{ id: 604800, label: n('spreed', '%n week', '%n weeks', 1) },
				{ id: 86400, label: n('spreed', '%n day', '%n days', 1) },
				{ id: 28800, label: n('spreed', '%n hour', '%n hours', 8) },
				{ id: 3600, label: n('spreed', '%n hour', '%n hours', 1) },
			],
		}
	},

	computed: {
		conversation() {
			return this.$store.getters.conversation(this.token) || this.$store.getters.dummyConversation
		},

		expirationOptions() {
			const expirationOptions = [...this.defaultExpirationOptions]

			const found = expirationOptions.find((option) => {
				return option.id === this.conversation.messageExpiration
			})
			if (!found) {
				expirationOptions.push({ id: this.conversation.messageExpiration, label: t('spreed', 'Custom expiration time') })
			}

			return expirationOptions
		},

		selectedOption() {
			if (this.overwriteExpiration) {
				return this.overwriteExpiration
			}

			const option = this.expirationOptions.find((option) => {
				return option.id === this.conversation.messageExpiration
			})
			if (option) {
				return option
			}

			return this.expirationOptions[this.expirationOptions.length - 1]
		},
	},

	methods: {
		async changeExpiration(expiration) {
			this.overwriteExpiration = expiration

			try {
				await this.$store.dispatch('setMessageExpiration', {
					token: this.token,
					seconds: expiration.id,
				})

				if (expiration.id === 0) {
					showSuccess(t('spreed', 'Message expiration disabled'))
				} else {
					showSuccess(t('spreed', 'Message expiration set: {duration}', {
						duration: expiration.label,
					}))
				}
			} catch (error) {
				showError(t('spreed', 'Error when trying to set the messages expiration'))
				console.error(error)
			}

			this.overwriteExpiration = undefined
		},
	},
}
</script>

<style lang="scss" scoped>
::v-deep .mx-input {
	margin: 0;
}
</style>