<p></p>
<p dir="auto">After a bit of research on some libraries that offer such functionalities and implementation details that we could potentially use for this:</p>
<h3 dir="auto">1. <a href="https://github.com/jonhue/notifications-rails">notifications-rails</a></h3>
<p dir="auto"><code class="notranslate">notifications-rails</code> provides a modular structure for creating, rendering, pushing, and managing settings for notifications, with each module backed by the database. This setup supports on-site notifications with user-configurable preferences, allowing users to see unread counts and mark notifications as read.</p>
<p dir="auto"><strong>Database Structure and Requirements:</strong></p>
<ul dir="auto">
<li>
<p dir="auto"><strong>New Tables:</strong></p>
<ul dir="auto">
<li><strong><code class="notranslate">notifications</code>:</strong> Main table storing each notification. Key columns:
<ul dir="auto">
<li><code class="notranslate">target_id</code> and <code class="notranslate">target_type</code> (polymorphic association for the recipient)</li>
<li><code class="notranslate">object_id</code> and <code class="notranslate">object_type</code> (polymorphic link to the notification’s subject, e.g., a <code class="notranslate">Comment</code>)</li>
<li><code class="notranslate">metadata</code> (JSON for additional data), <code class="notranslate">category</code> (notification type), and <code class="notranslate">read</code> (boolean for read/unread).</li>
</ul>
</li>
<li><strong><code class="notranslate">notification_groups</code> (optional):</strong> Allows bulk notifications for groups (e.g., subscribers).</li>
</ul>
</li>
<li>
<p dir="auto"><strong>Modified Tables:</strong></p>
<ul dir="auto">
<li><strong>User Table</strong>: Adds optional columns for <code class="notranslate">read_notification_count</code> and <code class="notranslate">unread_notification_count</code> to cache unread counts, and <code class="notranslate">settings</code> for storing user-specific notification preferences.</li>
</ul>
</li>
<li>
<p dir="auto"><strong>Indexes:</strong></p>
<ul dir="auto">
<li>Indexes on <code class="notranslate">target_id</code>, <code class="notranslate">target_type</code>, and <code class="notranslate">category</code> for quick lookups in the <code class="notranslate">notifications</code> table.</li>
</ul>
</li>
</ul>
<p dir="auto"><strong>Database Workflow:</strong></p>
<ol dir="auto">
<li><strong>Creating Notifications:</strong> Notifications are inserted into <code class="notranslate">notifications</code> with details on target, subject, metadata, and category.</li>
<li><strong>Marking as Read:</strong> Updating <code class="notranslate">read</code> marks notifications as read, and <code class="notranslate">unread_notification_count</code> can be adjusted for caching.</li>
<li><strong>Bulk Notifications:</strong> The <code class="notranslate">notification_groups</code> table can manage batch notifications by defining recipient groups.</li>
</ol>
<h3 dir="auto">2. <a href="https://github.com/excid3/noticed">noticed</a></h3>
<p dir="auto"><code class="notranslate">noticed</code> offers individual and bulk notifications, supporting multiple delivery methods, such as ActionCable for real-time updates. It’s suitable for creating on-site notifications tied to specific events, each managed through ActiveJob for asynchronous processing.</p>
<p dir="auto"><strong>Database Structure and Requirements:</strong></p>
<ul dir="auto">
<li>
<p dir="auto"><strong>New Tables:</strong></p>
<ul dir="auto">
<li>
<p dir="auto"><strong><code class="notranslate">notified_events</code>:</strong> Logs each event that triggers notifications. Key columns:</p>
<ul dir="auto">
<li><code class="notranslate">type</code> (event type, e.g., “NewCommentNotifier”)</li>
<li><code class="notranslate">record_id</code> and <code class="notranslate">record_type</code> (polymorphic association to link with the event’s subject, e.g., <code class="notranslate">Post</code>)</li>
<li><code class="notranslate">params</code> (JSON to store event details, like message and URL).</li>
</ul>
</li>
<li>
<p dir="auto"><strong><code class="notranslate">notifications</code>:</strong> Links notifications to events and tracks each recipient. Key columns:</p>
<ul dir="auto">
<li><code class="notranslate">event_id</code> (foreign key to <code class="notranslate">notified_events</code>), <code class="notranslate">recipient_id</code> and <code class="notranslate">recipient_type</code> (polymorphic association for the recipient), and <code class="notranslate">read_at</code> (datetime for read status).</li>
</ul>
</li>
</ul>
</li>
<li>
<p dir="auto"><strong>Modified Tables:</strong></p>
<ul dir="auto">
<li><strong>User Table</strong>: No required modifications, but adding <code class="notranslate">has_many :notifications</code> makes it easier to manage notifications.</li>
</ul>
</li>
<li>
<p dir="auto"><strong>Indexes:</strong></p>
<ul dir="auto">
<li>Indexes on <code class="notranslate">type</code>, <code class="notranslate">record_type</code>, and <code class="notranslate">record_id</code> in <code class="notranslate">notified_events</code> for efficient filtering and quick retrieval.</li>
</ul>
</li>
</ul>
<p dir="auto"><strong>Database Workflow:</strong></p>
<ol dir="auto">
<li><strong>Logging Events:</strong> Each new event (e.g., a comment) is logged in <code class="notranslate">notified_events</code>, capturing relevant metadata.</li>
<li><strong>Creating Notifications:</strong> Notifications are linked to events in <code class="notranslate">notifications</code>, enabling individual tracking for each recipient.</li>
<li><strong>Read Status:</strong> Users mark notifications as read by updating <code class="notranslate">read_at</code>, enabling quick querying for unread notifications and visual badges.</li>
</ol>
<p dir="auto">Hope you find this helpful <a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/gravitystorm/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/gravitystorm">@gravitystorm</a></p>
<p style="font-size:small;-webkit-text-size-adjust:none;color:#666;">—<br />Reply to this email directly, <a href="https://github.com/openstreetmap/openstreetmap-website/issues/1387#issuecomment-2443324208">view it on GitHub</a>, or <a href="https://github.com/notifications/unsubscribe-auth/AAK2OLNGSCMIBIEDOXVEHSTZ54TXPAVCNFSM6AAAAABQZDLHDCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDINBTGMZDIMRQHA">unsubscribe</a>.<br />You are receiving this because you are subscribed to this thread.<img src="https://github.com/notifications/beacon/AAK2OLKPWFKM2XB53UWX6YLZ54TXPA5CNFSM6AAAAABQZDLHDCWGG33NNVSW45C7OR4XAZNMJFZXG5LFINXW23LFNZ2KUY3PNVWWK3TUL5UWJTURUIVTA.gif" height="1" width="1" alt="" /><span style="color: transparent; font-size: 0; display: none; visibility: hidden; overflow: hidden; opacity: 0; width: 0; height: 0; max-width: 0; max-height: 0; mso-hide: all">Message ID: <span><openstreetmap/openstreetmap-website/issues/1387/2443324208</span><span>@</span><span>github</span><span>.</span><span>com></span></span></p>
<script type="application/ld+json">[
{
"@context": "http://schema.org",
"@type": "EmailMessage",
"potentialAction": {
"@type": "ViewAction",
"target": "https://github.com/openstreetmap/openstreetmap-website/issues/1387#issuecomment-2443324208",
"url": "https://github.com/openstreetmap/openstreetmap-website/issues/1387#issuecomment-2443324208",
"name": "View Issue"
},
"description": "View this Issue on GitHub",
"publisher": {
"@type": "Organization",
"name": "GitHub",
"url": "https://github.com"
}
}
]</script>