I have built a forum app. Each main post is captured in one table. Replies to each main post are in a second table, connected by a relation to the row ID of the main post in the main post table. When a person replies to a post the original poster and anyone who has replied to the post receive a notification. This is accomplished by: In the main table, a query identifies everyone who has replied to the post and then a join column creates a common separated list of emails of each user who has replied, which is fed into the bcc: of the email that is sent when they submit their reply.
I’m trying to figure out the best approach to allow a user mute notifications for a post that they have responded to. So far, the approach I have taken is to use a template column to combine the main-post row id and the user’s email address to create a unique key (I.e. fuE1ogQiTBOoZO-2unb.Pw-marie@example.com) in the replies table. When a user wants to mute updates, it clicks a button in the post screen which writes that value and their email address to a third table. I then use that with a query in the main post table to basically create a second column of emails (similar to the approach above) to exclude those users where they have an entry in the third table muting notifications for that post.
That works fine but I’m wondering if :
- There is a cleaner way than my approach because it’s a little convoluted to use two different queries to accomplish this.
2. More importantly, (and possibly a consequence of my approach) I can’t figure out how to give the user the ability to unmute. What I want is to have one “mute” action that is displayed only to those users that have replied to the post (it doesn’t make sense to mute the post if you haven’t replied) and only if they haven’t yet muted it. This works. What I can’t figure out how to do is to create an action that displays when they’ve muted the post that allows them to “unmute”…to basically delete the entry in the third table and undo the “mute”. The delete row action can’t reference “this row” because that is a row in the replies or main post table. I tried to use a relation between the third table and the replies table using the unique key and use the relation in place of “this row” but so far that doesn’t work. Selecting that makes the action disappear, presumably because the relation is blank.
Welcome thoughts on one or both…
Update: I figured out a solution to number 2 by writing the unique value to the user table temporality and then using a relation between the user table and table 3 to target the correct row to delete. Still welcome feedback on whether there is a more straight forward approach.