Jump to content

Notification Confusion


Midnight Modding

Recommended Posts

I looked through files trying to figure this out, but a couple areas get a bit confusing.

I have a notification that is sent during status changes of the item. So 1. it may need to be sent to the same member multiple times, and can be different each time. and 2. the email subject needs a replacement word based on which status we have for the current send().

Docs seem to indicate that one reason to pass $item is for it to prevent duplicates, but it doesn't seem to even use $item in that manner. It seems to only stop duplicates for the current call to save(), by using $sentTo. Am I missing something?

If I want to use a lang bit as a replacement word in the email subject (a different one for each status), I have to get each member's lang stack myself and pass the actual value from the beginning? Looking at suite code, sure looks that way... that you have to pass the actual words, not simply data to retrieve the words later.

Also, why is there both $emailParams and $inlineExtra? Wouldn't you be needing the same data in both cases? And it says use $inlineExtra sparingly....

Link to comment
Share on other sites

edit: I tried hard to edit that post many times to get more to the point, but felt like I needed to explain thoroughly. Again, I did look in the suite files and tracked some answers down, but just am confused on the 2 situations above.

Also, hopefully I won't be having much else to ask after this. Maybe a tad help on html, but I did read through the docs and am fairly optimistic there about syntax, buttons, dropdowns, messages, etc...

Link to comment
Share on other sites

If you wish to prevent duplicates, then yes you will want to populate the $sentTo array, or ensure you only call the send notifications method once (whether that's tracking to prevent calling it more than once in a single execution regardless of how many times save() is called, or if that's ensuring you only call save() once regardless of how many things are updated).

Look at mailsub__core_notification_new_content_bulk as a language string example for the subject:

New {$email->language->addToStack( $contentClass::$title . "_pl" )} in {$container->_title}

The same parameters passed to the email template are available in the subject language strings.

The $emailParams parameter is used to swap out variables within the notification. The $inlineExtra parameter is used to store additional data that is later used for showing the inline notification. The bulk content submission notification, for instance, uses this to store the author who submitted the multiple items to show that in the notification. You can see an example of how this can be used in /applications/core/extensions/core/Notifications/Content.php.

Link to comment
Share on other sites

Thanks! That new_content_bulk lang bit is a good example of what I wanted. I could pass the relevant key and then do that. (I already had done replacements in subjects similar to that $container_title one, also).

The reason I wondered about the need for both $emailParams and $inlineExtra is because I personally was only needing to pass info related to which lang bit to use, so for me it would be the same info needed in both situations.

I don't really need to prevent duplicates. I was worried about the opposite, that the system would automatically not allow separate calls to send() to send a notification with the same notification key, item, and member id to receive it. I looked in the files and saw only that $sentTo array, though. So it seems all fine for my needs.

Too bad there's not really a way to use if/else logic there or I wouldn't need to pass anything for $emailParams. i probably already don't need to for $inlineExtra in this particular case.

Anyway, thanks. I'm really making a lot of progress and hoping to be done soon. (even though, people made new versions of the apps they knew I was finishing up.... but at least this is a private version).

Link to comment
Share on other sites

Sigh. All this time I thought $item is automatically passed to the email template as the first parameter, but judging by notification_new_react and me re-reading docs, I assume I was wrong and I have to pass it in $emailParams. lol.

Also, still torn on what I want to pass to the email template. I see IPS a lot of times passes multiple objects for various reasons, not just subjects, so I guess it depends if I already have them loaded or not. And for inline, I try to just load them on the fly.

Btw, shouldn't try/catch technically be used for author of inline notifications? Just in case the member has been deleted before the notification is read? (just assuming it would throw something, but havent looked it up...in all examples, I see it not using try/catch, though). I'm mostly not even setting an author id, anyway.

Link to comment
Share on other sites

Thanks, both of you. I did wonder about that. originally in my post, I talked even more about maybe it not throwing one. lol. (I forgot about guest accounts, actually, though...)

Here's another thing... sometimes the url comes from a secondary object. Should I go ahead and store that object as $inlineExtra, even though it can be loaded on the fly from an id in the main object?

Or actually... I sometimes store a joined row as a property of the main object, as aiwa showed me how to do. Since notifications store the whole $item in the db, I guess it would stil have that joined row with it.

Anddddd last thing: in 4.x is there no way to do like 3.x, where instead of redirecting to a url, you can have it go to a built in page for the notification that shows more details about it? If not, I need to figure out sending a PM I guess.

edit: oh, one final thing... what if $item subsequently gets deleted? Then it will be calling url() from an object of a row that doesn't exist anymore. I guess it would still at least return a url, due to the db storing $item from when the notification was sent?

Link to comment
Share on other sites

2 hours ago, bfarber said:

There is no "full page notification" functionality.

If you delete the item, the notification should be deleted too.

Automatically or I should do it in my delete() method? I don't see it done for topics, so I assume you mean automatically for anything that extends the active record class.

Link to comment
Share on other sites

Hmm. I found where it deletes notifications in function delete() for Item.php. I have some rare cases where the object my notification is "about" is not a content item, though, so guess I need to do it myself for those or else change my main notification object (it uses invitation rows, so I have my main object the actual invite row and have it join the content item row... it's more complex than club invitations because those don't need a separate invite row, due to the needs of that setup).

So... I think only in those invitation examples do I need to delete these myself.

Link to comment
Share on other sites

Thanks for all the help.

I think I finally have everything all straight. I looked some more through files, saw the setter for item and that had a lot more click for me in how this is all set up, as well. And went through my ton of notifications and improved my overall setup, I feel.

I'm feeling good overall about the overall 4.x framework now. I haven't really done much with tables or front side html yet, but that's about it... I did a lot of "behind the scenes" methods before the html leading to them.

Link to comment
Share on other sites

On ‎3‎/‎1‎/‎2018 at 8:21 AM, bfarber said:

 


New {$email->language->addToStack( $contentClass::$title . "_pl" )} in {$container->_title}

 

This gives a "call to member function addToStack on null" when in_dev is on. Is that normal and you just turn in_dev off when testing publicly? I guess when in_dev it executes the code within the lang strings, and when not, it doesn't?

Link to comment
Share on other sites

Are you calling the string directly somewhere? If so, you shouldn't be - the email system handles loading up the email subject line automatically (and then parses it).

Is this a notification email being sent by the notification system, or are you sending it manually?

Link to comment
Share on other sites

9 hours ago, bfarber said:

Are you calling the string directly somewhere? If so, you shouldn't be - the email system handles loading up the email subject line automatically (and then parses it).

Is this a notification email being sent by the notification system, or are you sending it manually?

No I am not calling it anywhere. I am only using it with the notification system. It gives that error just by browsing the board with the lang file uploaded.

This is an example of how I have it:

'mailsub__abc_notification_locked'	=> "{$def->name} {$email->language->addToStack( 'locked_' . $extra['locked'] )}"

I don't call it anywhere and haven't even tested a notification, just to be clear. Just by browsing on the board it gives that error when in_dev.

Link to comment
Share on other sites

7 hours ago, Midnight Modding said:

This is an example of how I have it:


'mailsub__abc_notification_locked'	=> "{$def->name} {$email->language->addToStack( 'locked_' . $extra['locked'] )}"

I don't call it anywhere and haven't even tested a notification, just to be clear. Just by browsing on the board it gives that error when in_dev.

Your string in double quotes.

Link to comment
Share on other sites

9 hours ago, bfarber said:

What was the problem with doing it with double quotes in this exact case, though? It being in double quotes caused it to attempt to execute the code within it for in_dev mode, automatically? It's not a parse error, it's more that it's being executed at a time when it doesn't have the variable available to it, right?

I said single vs. double has given me problems, but actually it's been years. I really never have actual parse errors anymore, except when I typo.

Link to comment
Share on other sites

With PHP, using double quotes evaluates the variables in the string which wouldn't be set/defined at this point (and thus treating as an object would fail). Using IN_DEV, the lang.php files are required (as opposed to pulling strings from the database when IN_DEV is disabled, where they won't be evaluated).

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...