<commit_before><template>
	<div>
		<AppDetailsToggle @close="hideMessage" />
		<div id="app-content-wrapper">
			<Loading v-if="loading" :hint="t('mail', 'Loading messages')" />
			<template v-else>
				<EnvelopeList
					:account="account"
					:folder="folder"
					:envelopes="envelopes"
					:search-query="searchQuery"
					:show="!showMessage"
				/>
				<NewMessageDetail v-if="newMessage" />
				<Message v-else-if="showMessage" />
				<NoMessageSelected v-else-if="hasMessages" :mailbox="folder.name" />
			</template>
		</div>
	</div>
</template>

<script>
import _ from 'lodash'
import isMobile from 'nextcloud-vue/dist/Mixins/isMobile'

import AppDetailsToggle from './AppDetailsToggle'
import EnvelopeList from './EnvelopeList'
import Loading from './Loading'
import Message from './Message'
import NewMessageDetail from './NewMessageDetail'
import NoMessageSelected from './NoMessageSelected'

export default {
	name: 'FolderContent',
	components: {
		AppDetailsToggle,
		EnvelopeList,
		Loading,
		Message,
		NewMessageDetail,
		NoMessageSelected,
	},
	mixins: [isMobile],
	props: {
		account: {
			type: Object,
			required: true,
		},
		folder: {
			type: Object,
			required: true,
		},
	},
	data() {
		return {
			loading: true,
			searchQuery: undefined,
			alive: false,
		}
	},
	computed: {
		hasMessages() {
			return this.$store.getters.getEnvelopes(this.account.id, this.folder.id).length > 0
		},
		showMessage() {
			return this.hasMessages && this.$route.name === 'message'
		},
		newMessage() {
			return this.$route.params.messageUid === 'new'
		},
		envelopes() {
			if (_.isUndefined(this.searchQuery)) {
				return this.$store.getters.getEnvelopes(this.account.id, this.folder.id)
			} else {
				return this.$store.getters.getSearchEnvelopes(this.account.id, this.folder.id)
			}
		},
	},
	watch: {
		$route(to, from) {
			if (to.name === 'folder') {
				// Navigate (back) to the folder view -> (re)fetch data
				this.fetchData()
			}
		},
	},
	created() {
		this.alive = true

		new OCA.Search(this.searchProxy, this.clearSearchProxy)

		this.fetchData()
	},
	beforeDestroy() {
		this.alive = false
	},
	methods: {
		fetchData() {
			this.loading = true

			this.$store
				.dispatch('fetchEnvelopes', {
					accountId: this.account.id,
					folderId: this.folder.id,
					query: this.searchQuery,
				})
				.then(() => {
					const envelopes = this.envelopes
					console.debug('envelopes fetched', envelopes)

					this.loading = false

					if (!this.isMobile && this.$route.name !== 'message' && envelopes.length > 0) {
						// Show first message
						let first = envelopes[0]

						// Keep the selected account-folder combination, but navigate to the message
						// (it's not a bug that we don't use first.accountId and first.folderId here)
						this.$router.replace({
							name: 'message',
							params: {
								accountId: this.account.id,
								folderId: this.folder.id,
								messageUid: first.uid,
							},
						})
					}
				})
		},
		hideMessage() {
			this.$router.replace({
				name: 'folder',
				params: {
					accountId: this.account.id,
					folderId: this.folder.id,
				},
			})
		},
		searchProxy(query) {
			if (this.alive) {
				this.search(query)
			}
		},
		clearSearchProxy() {
			if (this.alive) {
				this.clearSearch()
			}
		},
		search(query) {
			this.searchQuery = query

			this.fetchData()
		},
		clearSearch() {
			this.searchQuery = undefined
		},
	},
}
</script>
<commit_msg>Do not show the "return" icon on the mobile envelope list<commit_after><template>
	<div>
		<AppDetailsToggle v-if="showMessage" @close="hideMessage" />
		<div id="app-content-wrapper">
			<Loading v-if="loading" :hint="t('mail', 'Loading messages')" />
			<template v-else>
				<EnvelopeList
					:account="account"
					:folder="folder"
					:envelopes="envelopes"
					:search-query="searchQuery"
					:show="!showMessage"
				/>
				<NewMessageDetail v-if="newMessage" />
				<Message v-else-if="showMessage" />
				<NoMessageSelected v-else-if="hasMessages" :mailbox="folder.name" />
			</template>
		</div>
	</div>
</template>

<script>
import _ from 'lodash'
import isMobile from 'nextcloud-vue/dist/Mixins/isMobile'

import AppDetailsToggle from './AppDetailsToggle'
import EnvelopeList from './EnvelopeList'
import Loading from './Loading'
import Message from './Message'
import NewMessageDetail from './NewMessageDetail'
import NoMessageSelected from './NoMessageSelected'

export default {
	name: 'FolderContent',
	components: {
		AppDetailsToggle,
		EnvelopeList,
		Loading,
		Message,
		NewMessageDetail,
		NoMessageSelected,
	},
	mixins: [isMobile],
	props: {
		account: {
			type: Object,
			required: true,
		},
		folder: {
			type: Object,
			required: true,
		},
	},
	data() {
		return {
			loading: true,
			searchQuery: undefined,
			alive: false,
		}
	},
	computed: {
		hasMessages() {
			return this.$store.getters.getEnvelopes(this.account.id, this.folder.id).length > 0
		},
		showMessage() {
			return this.hasMessages && this.$route.name === 'message'
		},
		newMessage() {
			return this.$route.params.messageUid === 'new'
		},
		envelopes() {
			if (_.isUndefined(this.searchQuery)) {
				return this.$store.getters.getEnvelopes(this.account.id, this.folder.id)
			} else {
				return this.$store.getters.getSearchEnvelopes(this.account.id, this.folder.id)
			}
		},
	},
	watch: {
		$route(to, from) {
			if (to.name === 'folder') {
				// Navigate (back) to the folder view -> (re)fetch data
				this.fetchData()
			}
		},
	},
	created() {
		this.alive = true

		new OCA.Search(this.searchProxy, this.clearSearchProxy)

		this.fetchData()
	},
	beforeDestroy() {
		this.alive = false
	},
	methods: {
		fetchData() {
			this.loading = true

			this.$store
				.dispatch('fetchEnvelopes', {
					accountId: this.account.id,
					folderId: this.folder.id,
					query: this.searchQuery,
				})
				.then(() => {
					const envelopes = this.envelopes
					console.debug('envelopes fetched', envelopes)

					this.loading = false

					if (!this.isMobile && this.$route.name !== 'message' && envelopes.length > 0) {
						// Show first message
						let first = envelopes[0]

						// Keep the selected account-folder combination, but navigate to the message
						// (it's not a bug that we don't use first.accountId and first.folderId here)
						this.$router.replace({
							name: 'message',
							params: {
								accountId: this.account.id,
								folderId: this.folder.id,
								messageUid: first.uid,
							},
						})
					}
				})
		},
		hideMessage() {
			this.$router.replace({
				name: 'folder',
				params: {
					accountId: this.account.id,
					folderId: this.folder.id,
				},
			})
		},
		searchProxy(query) {
			if (this.alive) {
				this.search(query)
			}
		},
		clearSearchProxy() {
			if (this.alive) {
				this.clearSearch()
			}
		},
		search(query) {
			this.searchQuery = query

			this.fetchData()
		},
		clearSearch() {
			this.searchQuery = undefined
		},
	},
}
</script>

{'fraction_non_alphanumeric': 0.1512076604258968, 'fraction_numerical': 0.0008575103615835358, 'mean_word_length': 2.933670601461495, 'pattern_counts': {'":': 0, '<': 35, '<?xml version=': 0, '>': 43, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7465186', 'n_tokens_mistral': 2954, 'n_tokens_neox': 2349, 'n_words': 479}