mirror of
https://github.com/Athou/commafeed.git
synced 2026-03-21 21:37:29 +00:00
remove the possibility to receive notifications when subscribing because that sends a lot of notifications, one for each entry in the feed
This commit is contained in:
@@ -304,7 +304,6 @@ export interface SubscribeRequest {
|
|||||||
url: string
|
url: string
|
||||||
title: string
|
title: string
|
||||||
categoryId?: string
|
categoryId?: string
|
||||||
pushNotificationsEnabled: boolean
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface TagRequest {
|
export interface TagRequest {
|
||||||
|
|||||||
@@ -11,7 +11,6 @@ import { useAppDispatch } from "@/app/store"
|
|||||||
import { reloadTree } from "@/app/tree/thunks"
|
import { reloadTree } from "@/app/tree/thunks"
|
||||||
import type { FeedInfoRequest, SubscribeRequest } from "@/app/types"
|
import type { FeedInfoRequest, SubscribeRequest } from "@/app/types"
|
||||||
import { Alert } from "@/components/Alert"
|
import { Alert } from "@/components/Alert"
|
||||||
import { ReceivePushNotificationsChechbox } from "@/components/ReceivePushNotificationsChechbox"
|
|
||||||
import { CategorySelect } from "./CategorySelect"
|
import { CategorySelect } from "./CategorySelect"
|
||||||
|
|
||||||
export function Subscribe() {
|
export function Subscribe() {
|
||||||
@@ -29,7 +28,6 @@ export function Subscribe() {
|
|||||||
url: "",
|
url: "",
|
||||||
title: "",
|
title: "",
|
||||||
categoryId: Constants.categories.all.id,
|
categoryId: Constants.categories.all.id,
|
||||||
pushNotificationsEnabled: false,
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
@@ -105,9 +103,6 @@ export function Subscribe() {
|
|||||||
<TextInput label={<Trans>Feed URL</Trans>} {...step1Form.getInputProps("url")} disabled />
|
<TextInput label={<Trans>Feed URL</Trans>} {...step1Form.getInputProps("url")} disabled />
|
||||||
<TextInput label={<Trans>Feed name</Trans>} {...step1Form.getInputProps("title")} required autoFocus />
|
<TextInput label={<Trans>Feed name</Trans>} {...step1Form.getInputProps("title")} required autoFocus />
|
||||||
<CategorySelect label={<Trans>Category</Trans>} {...step1Form.getInputProps("categoryId")} clearable />
|
<CategorySelect label={<Trans>Category</Trans>} {...step1Form.getInputProps("categoryId")} clearable />
|
||||||
<ReceivePushNotificationsChechbox
|
|
||||||
{...step1Form.getInputProps("pushNotificationsEnabled", { type: "checkbox" })}
|
|
||||||
/>
|
|
||||||
</Stack>
|
</Stack>
|
||||||
</Stepper.Step>
|
</Stepper.Step>
|
||||||
</Stepper>
|
</Stepper>
|
||||||
|
|||||||
@@ -77,7 +77,7 @@ public class OPMLImporter {
|
|||||||
}
|
}
|
||||||
// make sure we continue with the import process even if a feed failed
|
// make sure we continue with the import process even if a feed failed
|
||||||
try {
|
try {
|
||||||
feedSubscriptionService.subscribe(user, outline.getXmlUrl(), name, parent, position, false);
|
feedSubscriptionService.subscribe(user, outline.getXmlUrl(), name, parent, position);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("error while importing {}: {}", outline.getXmlUrl(), e.getMessage());
|
log.error("error while importing {}: {}", outline.getXmlUrl(), e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ public class FeedSubscriptionService {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
public long subscribe(User user, String url, String title, FeedCategory category, int position, boolean pushNotificationsEnabled) {
|
public long subscribe(User user, String url, String title, FeedCategory category, int position) {
|
||||||
Integer maxFeedsPerUser = config.database().cleanup().maxFeedsPerUser();
|
Integer maxFeedsPerUser = config.database().cleanup().maxFeedsPerUser();
|
||||||
if (maxFeedsPerUser > 0 && feedSubscriptionDAO.count(user) >= maxFeedsPerUser) {
|
if (maxFeedsPerUser > 0 && feedSubscriptionDAO.count(user) >= maxFeedsPerUser) {
|
||||||
String message = String.format("You cannot subscribe to more feeds on this CommaFeed instance (max %s feeds per user)",
|
String message = String.format("You cannot subscribe to more feeds on this CommaFeed instance (max %s feeds per user)",
|
||||||
@@ -73,7 +73,6 @@ public class FeedSubscriptionService {
|
|||||||
sub.setCategory(category);
|
sub.setCategory(category);
|
||||||
sub.setPosition(position);
|
sub.setPosition(position);
|
||||||
sub.setTitle(FeedUtils.truncate(title, 128));
|
sub.setTitle(FeedUtils.truncate(title, 128));
|
||||||
sub.setPushNotificationsEnabled(pushNotificationsEnabled);
|
|
||||||
return feedSubscriptionDAO.merge(sub).getId();
|
return feedSubscriptionDAO.merge(sub).getId();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -27,8 +27,4 @@ public class SubscribeRequest implements Serializable {
|
|||||||
@Schema(description = "id of the user category to place the feed in")
|
@Schema(description = "id of the user category to place the feed in")
|
||||||
@Size(max = 128)
|
@Size(max = 128)
|
||||||
private String categoryId;
|
private String categoryId;
|
||||||
|
|
||||||
@Schema(description = "whether to send push notifications for new entries of this feed")
|
|
||||||
private boolean pushNotificationsEnabled;
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -365,8 +365,7 @@ public class FeedREST {
|
|||||||
|
|
||||||
FeedInfo info = fetchFeedInternal(prependHttp(req.getUrl()));
|
FeedInfo info = fetchFeedInternal(prependHttp(req.getUrl()));
|
||||||
User user = authenticationContext.getCurrentUser();
|
User user = authenticationContext.getCurrentUser();
|
||||||
long subscriptionId = feedSubscriptionService.subscribe(user, info.getUrl(), req.getTitle(), category, 0,
|
long subscriptionId = feedSubscriptionService.subscribe(user, info.getUrl(), req.getTitle(), category, 0);
|
||||||
req.isPushNotificationsEnabled());
|
|
||||||
return Response.ok(subscriptionId).build();
|
return Response.ok(subscriptionId).build();
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error("Failed to subscribe to URL {}: {}", req.getUrl(), e.getMessage(), e);
|
log.error("Failed to subscribe to URL {}: {}", req.getUrl(), e.getMessage(), e);
|
||||||
@@ -385,7 +384,7 @@ public class FeedREST {
|
|||||||
Preconditions.checkNotNull(url);
|
Preconditions.checkNotNull(url);
|
||||||
FeedInfo info = fetchFeedInternal(prependHttp(url));
|
FeedInfo info = fetchFeedInternal(prependHttp(url));
|
||||||
User user = authenticationContext.getCurrentUser();
|
User user = authenticationContext.getCurrentUser();
|
||||||
feedSubscriptionService.subscribe(user, info.getUrl(), info.getTitle(), null, 0, false);
|
feedSubscriptionService.subscribe(user, info.getUrl(), info.getTitle(), null, 0);
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.info("Could not subscribe to url {} : {}", url, e.getMessage());
|
log.info("Could not subscribe to url {} : {}", url, e.getMessage());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,8 +46,7 @@ class OPMLImporterTest {
|
|||||||
importer.importOpml(user, xml);
|
importer.importOpml(user, xml);
|
||||||
|
|
||||||
Mockito.verify(feedSubscriptionService)
|
Mockito.verify(feedSubscriptionService)
|
||||||
.subscribe(Mockito.eq(user), Mockito.anyString(), Mockito.anyString(), Mockito.any(FeedCategory.class), Mockito.anyInt(),
|
.subscribe(Mockito.eq(user), Mockito.anyString(), Mockito.anyString(), Mockito.any(FeedCategory.class), Mockito.anyInt());
|
||||||
Mockito.anyBoolean());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -123,15 +123,10 @@ public abstract class BaseIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected Long subscribe(String feedUrl, String categoryId) {
|
protected Long subscribe(String feedUrl, String categoryId) {
|
||||||
return subscribe(feedUrl, categoryId, false);
|
|
||||||
}
|
|
||||||
|
|
||||||
protected Long subscribe(String feedUrl, String categoryId, boolean pushNotificationsEnabled) {
|
|
||||||
SubscribeRequest subscribeRequest = new SubscribeRequest();
|
SubscribeRequest subscribeRequest = new SubscribeRequest();
|
||||||
subscribeRequest.setUrl(feedUrl);
|
subscribeRequest.setUrl(feedUrl);
|
||||||
subscribeRequest.setTitle("my title for this feed");
|
subscribeRequest.setTitle("my title for this feed");
|
||||||
subscribeRequest.setCategoryId(categoryId);
|
subscribeRequest.setCategoryId(categoryId);
|
||||||
subscribeRequest.setPushNotificationsEnabled(pushNotificationsEnabled);
|
|
||||||
return RestAssured.given()
|
return RestAssured.given()
|
||||||
.body(subscribeRequest)
|
.body(subscribeRequest)
|
||||||
.contentType(ContentType.JSON)
|
.contentType(ContentType.JSON)
|
||||||
|
|||||||
@@ -1,7 +1,9 @@
|
|||||||
package com.commafeed.integration;
|
package com.commafeed.integration;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
import java.time.Duration;
|
import java.time.Duration;
|
||||||
|
|
||||||
|
import org.apache.hc.core5.http.HttpStatus;
|
||||||
import org.awaitility.Awaitility;
|
import org.awaitility.Awaitility;
|
||||||
import org.junit.jupiter.api.AfterEach;
|
import org.junit.jupiter.api.AfterEach;
|
||||||
import org.junit.jupiter.api.BeforeEach;
|
import org.junit.jupiter.api.BeforeEach;
|
||||||
@@ -13,6 +15,8 @@ import org.mockserver.verify.VerificationTimes;
|
|||||||
import com.commafeed.TestConstants;
|
import com.commafeed.TestConstants;
|
||||||
import com.commafeed.backend.model.UserSettings.PushNotificationType;
|
import com.commafeed.backend.model.UserSettings.PushNotificationType;
|
||||||
import com.commafeed.frontend.model.Settings;
|
import com.commafeed.frontend.model.Settings;
|
||||||
|
import com.commafeed.frontend.model.Subscription;
|
||||||
|
import com.commafeed.frontend.model.request.FeedModificationRequest;
|
||||||
|
|
||||||
import io.quarkus.test.junit.QuarkusTest;
|
import io.quarkus.test.junit.QuarkusTest;
|
||||||
import io.restassured.RestAssured;
|
import io.restassured.RestAssured;
|
||||||
@@ -33,7 +37,7 @@ class PushNotificationIT extends BaseIT {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
void receivedPushNotifications() {
|
void receivedPushNotifications() throws IOException {
|
||||||
// mock ntfy server
|
// mock ntfy server
|
||||||
HttpRequest ntfyPost = HttpRequest.request().withMethod("POST").withPath("/ntfy/integration-test");
|
HttpRequest ntfyPost = HttpRequest.request().withMethod("POST").withPath("/ntfy/integration-test");
|
||||||
getMockServerClient().when(ntfyPost).respond(HttpResponse.response().withStatusCode(200));
|
getMockServerClient().when(ntfyPost).respond(HttpResponse.response().withStatusCode(200));
|
||||||
@@ -45,8 +49,22 @@ class PushNotificationIT extends BaseIT {
|
|||||||
settings.getPushNotificationSettings().setTopic("integration-test");
|
settings.getPushNotificationSettings().setTopic("integration-test");
|
||||||
RestAssured.given().body(settings).contentType(ContentType.JSON).post("rest/user/settings").then().statusCode(200);
|
RestAssured.given().body(settings).contentType(ContentType.JSON).post("rest/user/settings").then().statusCode(200);
|
||||||
|
|
||||||
// subscribe with push notifications enabled
|
// subscribe
|
||||||
subscribe(getFeedUrl(), null, true);
|
Long subscriptionId = subscribeAndWaitForEntries(getFeedUrl());
|
||||||
|
Subscription subscription = getSubscription(subscriptionId);
|
||||||
|
|
||||||
|
// enable push notifications
|
||||||
|
FeedModificationRequest req = new FeedModificationRequest();
|
||||||
|
req.setId(subscriptionId);
|
||||||
|
req.setName(subscription.getName());
|
||||||
|
req.setCategoryId(subscription.getCategoryId());
|
||||||
|
req.setPosition(1);
|
||||||
|
req.setPushNotificationsEnabled(true);
|
||||||
|
RestAssured.given().body(req).contentType(ContentType.JSON).post("rest/feed/modify").then().statusCode(HttpStatus.SC_OK);
|
||||||
|
|
||||||
|
// receive two additional entries, those will trigger two push notifications
|
||||||
|
feedNowReturnsMoreEntries();
|
||||||
|
forceRefreshAllFeeds();
|
||||||
|
|
||||||
// await push notification for the two entries in the feed
|
// await push notification for the two entries in the feed
|
||||||
Awaitility.await()
|
Awaitility.await()
|
||||||
|
|||||||
Reference in New Issue
Block a user