feat(messaging): only show topics that have related subscribers

This commit is contained in:
Steven Nguyen committed 2024-02-21 19:01:31 -08:00
1 parent 4b14119a34
commit 4cd9fdcb9a
2 files changed
+13 -3

No files matched your search

@@ -28,6 +28,7 @@
</DropList>
<TopicsModal
{providerType}
bind:show={showTopics}
bind:topicsById={$topicsById}
on:update={(e) => {
@@ -3,11 +3,12 @@
import { Button, FormList, InputCheckbox, InputSearch } from '$lib/elements/forms';
import { Table, TableBody, TableCell, TableRow } from '$lib/elements/table';
import { sdk } from '$lib/stores/sdk';
import { Query, type Models } from '@appwrite.io/console';
import { Query, type Models, MessagingProviderType } from '@appwrite.io/console';
import { createEventDispatcher } from 'svelte';
import { providerType, getTotal } from './wizard/store';
import { getTotal } from './wizard/store';
import ProviderType from './providerType.svelte';
export let providerType: MessagingProviderType;
export let show: boolean;
export let topicsById: Record<string, Models.Topic>;
export let title = 'Select topics';
@@ -35,6 +36,14 @@
if (!show) return;
const queries = [Query.limit(5), Query.offset(offset)];
if (providerType === MessagingProviderType.Email) {
queries.push(Query.greaterThan('emailTotal', 0));
} else if (providerType === MessagingProviderType.Sms) {
queries.push(Query.greaterThan('smsTotal', 0));
} else if (providerType === MessagingProviderType.Push) {
queries.push(Query.greaterThan('pushTotal', 0));
}
const response = await sdk.forProject.messaging.listTopics(queries, search || undefined);
totalResults = response.total;
@@ -84,7 +93,7 @@
<Modal {title} bind:show onSubmit={submit} on:close={reset} headerDivider={false} size="big">
<p class="text">
Select existing topics you want to send this message to its targets. The message will be
sent only to <ProviderType type={$providerType} noIcon /> targets.
sent only to <ProviderType type={providerType} noIcon /> targets.
</p>
<InputSearch
autofocus