Code Monkey home page Code Monkey logo

Comments (10)

iMattPro avatar iMattPro commented on June 12, 2024

I discovered this has to do with IDs. Since we are sending a notification for the entire rules, not individual rules with IDs, our notification's item_id is usually 0. So same ID means no new notification generated until the old one is pruned at some point.

So the question is, is this behavior acceptable? Or do we want to do something like generate a bogus unique ID, like:

public static function get_item_id($data)
{
    return !empty($data['rule_id']) ? $data['rule_id'] : rand(0, 16777215);
}

Although this may have negative consequences on the URL generated for the notification's link to the rules page.

from boardrules.

EXreaction avatar EXreaction commented on June 12, 2024

Would the unix timestamp work as the id or is that too long?

from boardrules.

iMattPro avatar iMattPro commented on June 12, 2024

Too long. Field is mediumint 8

from boardrules.

EXreaction avatar EXreaction commented on June 12, 2024

Is there no way to over-ride the method checking for duplicates? I thought there was...

from boardrules.

iMattPro avatar iMattPro commented on June 12, 2024

I have not looked deep into the notification system to know the answer to that.

from boardrules.

iMattPro avatar iMattPro commented on June 12, 2024

Should we run delete_notifications() prior to add_notifications() ?

In theory, this would delete the notification we are about to add, if it currently exists, clearing the way for a fresh new one.

from boardrules.

EXreaction avatar EXreaction commented on June 12, 2024

That could work, but I don't really like deleting history...
On Jul 1, 2014 11:16 PM, "Matt Friedman" [email protected] wrote:

Should we run delete_notifications() prior to add_notifications() ?


Reply to this email directly or view it on GitHub
#134 (comment)
.

from boardrules.

iMattPro avatar iMattPro commented on June 12, 2024

I have come up with two other options, but I do not know which one is the best solution:

Option 1:
We set the notification's item_id using truncated time() instead of the rule_id. In the board's current set up, we are not actually getting rule_id's because the notification is global, which is why the rule_id/item_id we get is always 0. I originally set up the board notifications to use rule_ids in case we ever decided to make the notifications work per rule.

So to do option 1, we would change:

public static function get_item_id($data)
{
    //return $data['rule_id']; // the old code
    return substr(time(), -7);
}
public function get_url()
{
    //$rule_id = ($this->item_id) ? array('#' => $this->item_id) : array(); // the old code
    $rule_id = ($this->get_data('rule_id')) ? array('#' => $this->get_data('rule_id')) : array();

    return $this->helper->route('boardrules_main_controller', $rule_id);
}

Option 2:
Instead look for users who have existing notifications that they marked as read, and reset them back to unread by adding this code to find_users_for_notification()

// Try to find the users who already have been notified about rules and just update their notifications
$sql = 'SELECT n.*
    FROM ' . $this->notifications_table . ' n, ' . $this->notification_types_table . ' nt
    WHERE n.notification_type_id = ' . (int) $this->notification_type_id . '
        AND n.item_parent_id = ' . (int) self::get_item_parent_id($data) . '
        AND n.notification_read = 1
        AND nt.notification_type_id = n.notification_type_id
        AND nt.notification_type_enabled = 1';
$result = $this->db->sql_query($sql);
while ($row = $this->db->sql_fetchrow($result))
{
    // Do not create a new notification
    unset($users[$row['user_id']]);

    $sql = 'UPDATE ' . $this->notifications_table . '
        SET notification_read = 0
        WHERE notification_id = ' . $row['notification_id'];
    $this->db->sql_query($sql);
}
$this->db->sql_freeresult($result);

I'm not really a fan of any of the options presented, but I haven't been able to find some magic method buried inside the notifications system that would solve this more elegantly. I worry about the side effects of option 2 on a board with thousands and thousands of users too.

from boardrules.

EXreaction avatar EXreaction commented on June 12, 2024

Well, the least hacky way I'd vote for is to add a counter as a config option that we just increment each time.

I checked the notifications code and there isn't any way to get around this for now...

from boardrules.

iMattPro avatar iMattPro commented on June 12, 2024

Solved by PR #138

from boardrules.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.