src/pages/Notifications/index.js
/**
 * Given a notification, give it a score based on its importance.
 *
 * There are some interesting workarounds that go into this algorithm to account
 * for GitHub's broken notifications API -- but we will get to that later. First,
 * let's start off with the basics of scoring.
 *
 * There are a few "reasons" that we can be getting a notification, each having
 * an initial weight of importance:
 *
 *  - MENTION           ->  8
 *  - ASSIGN            ->  14
 *  - REVIEW_REQUESTED  ->  30
 *  - SUBSCRIBED        ->  3
 *  - COMMENT           ->  3
 *  - AUTHOR            ->  10
 *  - OTHER             ->  2
 *
 * There are some rules that go to giving out these scores, primarily being the
 * first time we see one of these unique reasons, we award the notification with
 * the respective score, but a reason that transitions into itself will be awarded
 * a degraded score of min(ceil(n/3), 2). For example:
 *
 *  - null, MENTION, MENTION -> 0, 8, 3
 *  - null, ASSIGN, ASSIGN, REVIEW_REQUESTED, -> 0, 14, 5, 20
 *  - null, SUBSCRIBED, SUBSCRIBED, SUBSCRIBED -> 0, 3, 2, 2
 *
 * @param {Object} notification Some notification to score.
 * @return {number} The score.
 */
Given a notification, give it a score based on its importance.
There are some interesting workarounds that go into this algorithm to account
for GitHub's broken notifications API -- but we will get to that later. First,
let's start off with the basics of scoring.

There are a few "reasons" that we can be getting a notification, each having
an initial weight of importance.



There are some rules that go to giving out these scores, primarily being the
first time we see one of these unique reasons, we award the notification with
the respective score, but a reason that transitions into itself will be awarded
a degraded score of min(ceil(n/3), 2). For example.



@param {Object} notification Some notification to score.
@return {number} The score.
Given a notification give it a score based on its importance . There are some interesting workarounds that go into this algorithm to account for GitHub ' s broken notifications API -- but we will get to that later . First let ' s start off with the basics of scoring . There are a few " reasons " that we can be getting a notification each having an initial weight of importance . There are some rules that go to giving out these scores primarily being the first time we see one of these unique reasons we award the notification with the respective score but a reason that transitions into itself will be awarded a degraded score of min ( ceil ( n / 3 ) 2 ) . For example . @param { Object } notification Some notification to score . @return { number } The score .
function scoreOf (notification) {
  const {reasons} = notification;
  let score = 0;
  let prevReason = null;
  for (let i = 0; i < reasons.length; i++) {
    const reason = reasons[i].reason;
    if (prevReason && reason === prevReason) {
      const degradedScore = Math.ceil(scoreOfReason[reason] / 3);
      score += Math.max(degradedScore, 2);
    } else {
      score += scoreOfReason[reason];
    }
    prevReason = reason;
  }
  return score;
}
function scoreOf ( notification ) { const { reasons } = notification ; let score = 0 ; let prevReason = null ; for ( let i = 0 ; i < reasons . length ; i ++ ) { const reason = reasons [ i ] . reason ; if ( prevReason && reason === prevReason ) { const degradedScore = Math . ceil ( scoreOfReason [ reason ] / 3 ) ; score += Math . max ( degradedScore , 2 ) ; } else { score += scoreOfReason [ reason ] ; } prevReason = reason ; } return score ; }
Given a notification, give it a score based on its importance.
Given a notification give it a score based on its importance .