Skip to content

Commit

Permalink
Add channel flag for sending notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytv committed Aug 11, 2023
1 parent 3704cdf commit 9eda874
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum ChannelFlag {
FROZEN(false, false),
UNSTABLE(true, false),
PINNED(true, true),
SENDS_NOTIFICATIONS(true, false),
;

public static final Set<ChannelFlag> EDITABLE = Arrays.stream(values()).filter(ChannelFlag::isEditable).collect(Collectors.toUnmodifiableSet());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public ProjectTable createProject(final NewProjectForm newProject) {
ProjectTable projectTable = null;
try {
projectTable = this.projectsDAO.insert(new ProjectTable(projectOwner, newProject));
this.channelService.createProjectChannel(this.config.channels.nameDefault(), this.config.channels.descriptionDefault(), this.config.channels.colorDefault(), projectTable.getId(), Set.of(ChannelFlag.FROZEN, ChannelFlag.PINNED));
this.channelService.createProjectChannel(this.config.channels.nameDefault(), this.config.channels.descriptionDefault(), this.config.channels.colorDefault(), projectTable.getId(), Set.of(ChannelFlag.FROZEN, ChannelFlag.PINNED, ChannelFlag.SENDS_NOTIFICATIONS));
this.projectMemberService.addNewAcceptedByDefaultMember(ProjectRole.PROJECT_OWNER.create(projectTable.getId(), null, projectOwner.getUserId(), true));
String newPageContent = newProject.getPageContent();
if (newPageContent == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,9 @@ public void publishPendingVersion(final long projectId, final PendingVersion pen
this.downloadsDAO.insertPlatformDownloads(platformDownloadsTables);

// send notifications
this.notificationService.notifyUsersNewVersion(projectTable, projectVersionTable, this.projectService.getProjectWatchers(projectTable.getId()));
if (projectChannelTable.getFlags().contains(ChannelFlag.SENDS_NOTIFICATIONS)) {
this.notificationService.notifyUsersNewVersion(projectTable, projectVersionTable, this.projectService.getProjectWatchers(projectTable.getId()));
}
this.actionLogger.version(LogAction.VERSION_CREATED.create(VersionContext.of(projectId, projectVersionTable.getId()), "published", ""));

if (projectTable.getVisibility() == Visibility.NEW) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
-- Add the sends_notifications flag to all existing channels
UPDATE project_channels SET flags = flags || ARRAY[3]
13 changes: 11 additions & 2 deletions frontend/src/components/modals/ChannelModal.vue
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const i18n = useI18n();
const v = useVuelidate();
const frozen = props.channel && props.channel.flags.includes(ChannelFlag.FROZEN);
const possibleFlags = frozen ? [ChannelFlag.PINNED] : [ChannelFlag.UNSTABLE, ChannelFlag.PINNED];
const possibleFlags = frozen ? [ChannelFlag.PINNED] : [ChannelFlag.UNSTABLE, ChannelFlag.PINNED, ChannelFlag.SENDS_NOTIFICATIONS];
const form = reactive<ProjectChannel>({
name: "",
Expand Down Expand Up @@ -136,7 +136,16 @@ reset();
/>
<div class="mb-4" />
</div>
<InputCheckbox v-for="f in possibleFlags" :key="f" v-model="flags" :label="i18n.t(`channel.modal.flags.${f.toLowerCase()}`)" :value="f" />
<InputCheckbox v-for="f in possibleFlags" :key="f" v-model="flags" :value="f">
<template #label>
<span class="mr-1">
<IconMdiAlertOutline v-if="f === ChannelFlag.UNSTABLE" />
<IconMdiPinOutline v-else-if="f === ChannelFlag.PINNED" />
<IconMdiBellOutline v-else-if="f === ChannelFlag.SENDS_NOTIFICATIONS" />
</span>
{{ i18n.t("channel.modal.flags." + f.toLowerCase()) }}
</template>
</InputCheckbox>
<Button class="mt-3" :disabled="noChange || v.$invalid" @click="create(on.click)">{{ edit ? i18n.t("general.save") : i18n.t("general.create") }}</Button>
</template>
Expand Down
3 changes: 2 additions & 1 deletion frontend/src/i18n/locales/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -596,7 +596,8 @@
"pickedColor": "Picked channel color (must be unique)",
"flags": {
"unstable": "Versions are to be considered unstable",
"pinned": "Latest version is pinned on main project page"
"pinned": "Latest version is pinned on main project page",
"sends_notifications": "New versions in this channel send notifications to watching users"
},
"error": {
"invalidName": "Invalid channel name",
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ export enum ChannelFlag {
FROZEN = "FROZEN",
UNSTABLE = "UNSTABLE",
PINNED = "PINNED",
SENDS_NOTIFICATIONS = "SENDS_NOTIFICATIONS",
}

export enum PinnedStatus {
Expand Down
1 change: 1 addition & 0 deletions frontend/src/types/generated/icons.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ declare module "vue" {
IconMdiPencil: typeof import("~icons/mdi/pencil")["default"];
IconMdiPin: typeof import("~icons/mdi/pin")["default"];
IconMdiPinOff: typeof import("~icons/mdi/pin-off")["default"];
IconMdiPinOutline: typeof import("~icons/mdi/pin-outline")["default"];
IconMdiPlay: typeof import("~icons/mdi/play")["default"];
IconMdiPlus: typeof import("~icons/mdi/plus")["default"];
IconMdiPuzzleOutline: typeof import("~icons/mdi/puzzle-outline")["default"];
Expand Down

0 comments on commit 9eda874

Please sign in to comment.