-
Notifications
You must be signed in to change notification settings - Fork 232
Add dismiss all alerts and delete all messages buttons. #1046
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ArneBab
merged 6 commits into
hyphanet:next
from
ArneBab:fproxy--add-dismiss-all-alerts-buttons
Jun 28, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
9f77b50
Add dismiss all alerts and delete all messages buttons.
ArneBab 7d70133
doc: fix docstring wording
ArneBab 31f13af
Remove unused constructor
ArneBab b97037f
Remove unused methods
ArneBab 447417c
Assign fields with this.field = in constructor
ArneBab 670673c
Remove unnecessary constructor
ArneBab File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -11,6 +11,9 @@ | |||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| import freenet.client.HighLevelSimpleClient; | ||||||||||||||||||||||||||||||||||||||
| import freenet.l10n.NodeL10n; | ||||||||||||||||||||||||||||||||||||||
| import freenet.node.useralerts.AbstractNodeToNodeFileOfferUserAlert; | ||||||||||||||||||||||||||||||||||||||
| import freenet.node.useralerts.NodeToNodeMessageUserAlert; | ||||||||||||||||||||||||||||||||||||||
| import freenet.node.useralerts.UserAlert; | ||||||||||||||||||||||||||||||||||||||
| import freenet.support.HTMLNode; | ||||||||||||||||||||||||||||||||||||||
| import freenet.support.MultiValueTable; | ||||||||||||||||||||||||||||||||||||||
| import freenet.support.api.HTTPRequest; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -21,13 +24,17 @@ | |||||||||||||||||||||||||||||||||||||
| */ | ||||||||||||||||||||||||||||||||||||||
| public class UserAlertsToadlet extends Toadlet { | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private static final String DISMISS_ALL_ALERTS_PART = "dismissAllAlerts"; | ||||||||||||||||||||||||||||||||||||||
| private static final String DELETE_ALL_MESSAGES_PART = "deleteAllMessages"; | ||||||||||||||||||||||||||||||||||||||
| private static final String REALLY_DELETE_AFFIRMED = "reallyDeleteAffirmed"; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| UserAlertsToadlet(HighLevelSimpleClient client) { | ||||||||||||||||||||||||||||||||||||||
| super(client); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public void handleMethodGET(URI uri, HTTPRequest request, ToadletContext ctx) throws ToadletContextClosedException, IOException { | ||||||||||||||||||||||||||||||||||||||
| if(!ctx.checkFullAccess(this)) | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
| if(!ctx.checkFullAccess(this)) | ||||||||||||||||||||||||||||||||||||||
| return; | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| PageNode page = ctx.getPageMaker().getPageNode(l10n("title"), ctx); | ||||||||||||||||||||||||||||||||||||||
| HTMLNode pageNode = page.outer; | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -36,18 +43,64 @@ public void handleMethodGET(URI uri, HTTPRequest request, ToadletContext ctx) th | |||||||||||||||||||||||||||||||||||||
| if (alertsNode.getFirstTag() == null) { | ||||||||||||||||||||||||||||||||||||||
| alertsNode = new HTMLNode("div", "class", "infobox"); | ||||||||||||||||||||||||||||||||||||||
| alertsNode.addChild("div", "class", "infobox-content").addChild("div", NodeL10n.getBase().getString("UserAlertsToadlet.noMessages")); | ||||||||||||||||||||||||||||||||||||||
| } else { | ||||||||||||||||||||||||||||||||||||||
| addDismissAllButtons(ctx, contentNode); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| contentNode.addChild(alertsNode); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| writeHTMLReply(ctx, 200, "OK", pageNode.generate()); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| private void addDismissAllButtons(ToadletContext ctx, HTMLNode contentNode) { | ||||||||||||||||||||||||||||||||||||||
| HTMLNode dismissAlertsContainer = contentNode.addChild("div", "class", "dismiss-all-alerts-container"); | ||||||||||||||||||||||||||||||||||||||
| HTMLNode dismissAlertsForm = ctx.addFormChild(dismissAlertsContainer, "", "deleteAllNotificationsForm"); | ||||||||||||||||||||||||||||||||||||||
| dismissAlertsForm.addChild("input", | ||||||||||||||||||||||||||||||||||||||
| new String[]{"name", "type", "title", "value"}, | ||||||||||||||||||||||||||||||||||||||
| new String[]{ DISMISS_ALL_ALERTS_PART, "submit", l10n("dismissAlertsButtonTitle"), l10n("dismissAlertsButtonContent")}); | ||||||||||||||||||||||||||||||||||||||
| HTMLNode deleteMessagesForm = ctx.addFormChild(dismissAlertsContainer, "", "deleteAllNotificationsForm"); | ||||||||||||||||||||||||||||||||||||||
| deleteMessagesForm.addChild("input", | ||||||||||||||||||||||||||||||||||||||
| new String[]{"name", "type", "title", "value"}, | ||||||||||||||||||||||||||||||||||||||
| new String[]{ DELETE_ALL_MESSAGES_PART, "submit", l10n("deleteMessagesButtonTitle"), l10n("deleteMessagesButtonContent")}); | ||||||||||||||||||||||||||||||||||||||
| String deleteMessagesReallyCheckboxId = "reallyDeleteAllMessagesCheckbox"; | ||||||||||||||||||||||||||||||||||||||
| deleteMessagesForm.addChild( | ||||||||||||||||||||||||||||||||||||||
| "input", | ||||||||||||||||||||||||||||||||||||||
| new String[]{ "type", "name", "id", "required" }, | ||||||||||||||||||||||||||||||||||||||
| new String[]{ "checkbox", REALLY_DELETE_AFFIRMED, deleteMessagesReallyCheckboxId, "true" }); | ||||||||||||||||||||||||||||||||||||||
| deleteMessagesForm.addChild("label", "for", deleteMessagesReallyCheckboxId, l10n("deleteMessagesButtonReallyDeleteLabel")); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| public void handleMethodPOST(URI uri, HTTPRequest request, ToadletContext ctx) throws ToadletContextClosedException, IOException { | ||||||||||||||||||||||||||||||||||||||
| if (request.isPartSet("dismiss-user-alert")) { | ||||||||||||||||||||||||||||||||||||||
| int userAlertHashCode = request.getIntPart("disable", -1); | ||||||||||||||||||||||||||||||||||||||
| ctx.getAlertManager().dismissAlert(userAlertHashCode); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (request.isPartSet(DISMISS_ALL_ALERTS_PART)) { | ||||||||||||||||||||||||||||||||||||||
| for (UserAlert alert : ctx.getAlertManager().getAlerts()) { | ||||||||||||||||||||||||||||||||||||||
| if (!alert.userCanDismiss()) { | ||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (alert instanceof NodeToNodeMessageUserAlert) { | ||||||||||||||||||||||||||||||||||||||
| continue; // keep all node to node messages | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ctx.getAlertManager().dismissAlert(alert.hashCode()); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| if (request.isPartSet(DELETE_ALL_MESSAGES_PART) && request.isPartSet(REALLY_DELETE_AFFIRMED)) { | ||||||||||||||||||||||||||||||||||||||
| for (UserAlert alert : ctx.getAlertManager().getAlerts()) { | ||||||||||||||||||||||||||||||||||||||
| if (!(alert instanceof NodeToNodeMessageUserAlert)) { | ||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (alert instanceof AbstractNodeToNodeFileOfferUserAlert) { | ||||||||||||||||||||||||||||||||||||||
| continue; // not deleting file offers, because these need a decision | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| if (!alert.userCanDismiss()) { | ||||||||||||||||||||||||||||||||||||||
| continue; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| ctx.getAlertManager().dismissAlert(alert.hashCode()); | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+90
to
+101
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. (More yak shaving.)
Suggested change
|
||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
| String redirect; | ||||||||||||||||||||||||||||||||||||||
| try { | ||||||||||||||||||||||||||||||||||||||
| redirect = request.getPartAsStringThrowing("redirectToAfterDisable", 1024); | ||||||||||||||||||||||||||||||||||||||
|
|
@@ -57,9 +110,9 @@ public void handleMethodPOST(URI uri, HTTPRequest request, ToadletContext ctx) t | |||||||||||||||||||||||||||||||||||||
| // hard whitelist of allowed origins to avoid https://www.owasp.org/index.php/Unvalidated_Redirects_and_Forwards_Cheat_Sheet | ||||||||||||||||||||||||||||||||||||||
| // TODO: Parse the URL to ensure that it is a valid fproxy URL | ||||||||||||||||||||||||||||||||||||||
| if (!("/alerts/".equals(redirect) || | ||||||||||||||||||||||||||||||||||||||
| "/".equals(redirect) || | ||||||||||||||||||||||||||||||||||||||
| "/#bookmarks".equals(redirect))) { | ||||||||||||||||||||||||||||||||||||||
| redirect = "."; | ||||||||||||||||||||||||||||||||||||||
| "/".equals(redirect) || | ||||||||||||||||||||||||||||||||||||||
| "/#bookmarks".equals(redirect))) { | ||||||||||||||||||||||||||||||||||||||
| redirect = "."; | ||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||
| MultiValueTable<String, String> headers = MultiValueTable.from("Location", redirect); | ||||||||||||||||||||||||||||||||||||||
| ctx.sendReplyHeaders(302, "Found", headers, null, 0); | ||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
10 changes: 10 additions & 0 deletions
10
src/freenet/node/useralerts/AbstractNodeToNodeFileOfferUserAlert.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,10 @@ | ||
| package freenet.node.useralerts; | ||
|
|
||
| import freenet.support.HTMLNode; | ||
|
|
||
| /** | ||
| * Helper to create anonymous classes with interface NodeToNodeMessageUserAlert | ||
| */ | ||
| public abstract class AbstractNodeToNodeFileOfferUserAlert extends AbstractUserAlert implements NodeToNodeMessageUserAlert { | ||
| // intentionally left blank | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 12 additions & 0 deletions
12
src/freenet/node/useralerts/NodeToNodeMessageUserAlert.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package freenet.node.useralerts; | ||
|
|
||
| import java.lang.ref.WeakReference; | ||
|
|
||
| import freenet.node.PeerNode; | ||
| import freenet.support.HTMLNode; | ||
|
|
||
| /** | ||
| * Tagging interface for user alerts that are node to node messages. | ||
| */ | ||
| public interface NodeToNodeMessageUserAlert { | ||
Bombe marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(Sorry for shaving this yak, feel free to ignore, but if you don’t ignore it, make sure I got it right, negations are confusing. 😄)