-
Notifications
You must be signed in to change notification settings - Fork 50
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
Event blacklisting #104
Event blacklisting #104
Conversation
As much for my own future reference as anything else, one of the non-obvious decisions I made was to order it in such a way that if it is (or becomes) possible to also add a custom |
c9c4a12
to
3a7c7cc
Compare
f9a939f
to
c3a9df0
Compare
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.
Additionally I'd like to hear your opinion on making the notificationBlacklist field case insensitive.
Having it case sensitive lets a user have various custom events with different capitalization in the same contact while blacklisting only some of them, but I can imagine it could also cause lots of issues like "I blacklisted the 'birthday' [first letter lowercase] event in one of my contacts, why do I still receive a birthday notification for that contact?"
We could try dealing with this by inserting a warning in the documentation of this option, but:
- given the notorious ability users have to ignore warnings
- considering the extremely small number of users that actually
- will have a contact with multiple events only differing in capitalization
- want to blacklist just some of them
I'd opt for the case-insensitive comparison.
code.gs
Outdated
thisEventDay = dateField.getDay(); | ||
if (((!eventDay && !eventMonth) || | ||
(thisEventMonth === eventMonth && thisEventDay === eventDay)) && | ||
(!self.blacklist || !self.blacklist.length || !isIn(beautifyLabel(thisEventLabel), self.blacklist))) { |
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.
I think this conditional should be formatted differently: as it is now it's quite difficult to grasp operators precedences and meanings.
It could use some more spacing (not so pleasing to look at, but easy to understand at first glance):
if (
(
(!eventDay && !eventMonth) ||
(thisEventMonth === eventMonth && thisEventDay === eventDay)
) && (
!self.blacklist || !self.blacklist.length || !isIn(beautifyLabel(thisEventLabel), self.blacklist)
)
) {
or extracting partial conditions (prettier in my opinion, but still easily understandable):
dateMatches = (!eventDay && !eventMonth) || (thisEventMonth === eventMonth && thisEventDay === eventDay));
blacklistMatches = self.blacklist && self.blacklist.length && isIn(beautifyLabel(thisEventLabel), self.blacklist)
if (dateMatches && !blacklistMatches) {
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.
OK, in a while I will change it to use the partially extracted conditions you showed (or if you prefer not to wait feel free to add that change as a commit to the PR branch).
I had considered the case-insensitivity option, and was kind of on the fence about it because the problem you explain about users not heeding warnings and getting confused by "under-matching" due to case-sensitivity may also apply a bit with "over-matching" due to case-insensitivity. The decider for me was that accidentally sending a reminder-email which shouldn't be sent is less of a disaster than accidentally not sending one which is expected (and possibly missing a birthday, and ending up sleeping on the sofa). On the one hand - considering the I suppose the option which scores lower on the Principle of least astonishment scale would be case-insensitivity. In a while I will change the PR to be case-insensitive unless you change your mind and let me know before then. |
…ents * Also add and use deleteFromField() method for pruning blacklisted events which may have already been added from e.g. raw event * Also add and use eventLabelToLowerCase() function * Also reinstate uniqueStrings() function for deduping the user blacklist field - use `uniqueStrings()`, `.length`, and `isIn()`, because GAS doesn't support `Set()`, `.size`, and `.has(x)` * Also use toLocaleLowerCase() instead of toLowerCase() * Also make "events > 0 && contacts == 0" just an early-exit instead of a fatal error. If the contact's only events are blacklisted then this is a valid condition * Closes GioBonvi#70
The subject was built using a list of all the contacts with events on the given day, without considerng the `notification.eventTypes` setting. This meant that, for example, if a contact had an ANNIVERSARY event on XX/YY/ZZZZ and the user set `notification.eventTypes` to filter out anniversaries, while the email notification text did not display the anniversary (correct) the notification subject included the name of that contact (wrong). Now the events excluded from the `notification.eventTypes` setting are blacklisted and do not appear in the final list of contacts. Closes GioBonvi#105.
c3a9df0
to
5f648c1
Compare
While addressing the case-insensitivity issue, because the whole state of event-labels, coercions thereof, and fuzzy-matching of stringified labels had already been nagging at me for a long time, I rewrote my commit to make event-label handling less "fuzzy" in general (not just in my new code, but throughout the script):
That should hopefully make event-label handling more straightforward and predictable from now on. I also split the monolithic conditional into partially extracted conditions as you requested. Because these changes impacted your |
As mentioned in #103 I have based this PR on the HEAD of that PR rather than the present HEAD of
development
, as it makes sense to merge that first, which will then leave this PR with just the one commit on top of it. If reviewing this PR before merging the other one, only look at the last commit - all the others are just the commits from #103.This commit ended up being more complex than I expected - mainly because it requires:
rawEvent
dataGoogle Contact
(including the blacklist field if it exists)Google Contact
that aren't in the blacklistGoogle+
profile if it existsrawEvent
if they turned out to be in the blacklist subsequently retrieved from theGoogle Contact
...a bit like being locked inside a trunk, holding the key to open the padlock on the outside of the trunk...