userDigest.getUsersInterval(uid) returns false even if default digest is set to daily

  • Gamers

    I'm trying to get user digest interval by uid.

    there is a user digest library here to be used

    const userDigest = require.main.require('./src/user/digest');
    

    and there is a function

    Digest.getUsersInterval = async (uids) => {...
    

    that returns the users digest interval

    My problem is that this functions returns false, if user has set the digest to false, and also return false if the user has the default value set, and default value is different to "off" (daily or weekly or monthly). So I can't tell the difference if a user is subscribed to digest or not.

    Am I doing this query wrong? should I be using another library / function ?

  • Gamers

    @Sebastián-Cisneros I just noticed one thing related to this issue.

    if a users sets digest to "off", digest are not actually deactivated but forced to "default". So there is no real way do unsusbcribe to digest if digest default value if different to "off" .

    is this right? or Am I gettting it wrong?

  • NodeBB Admin

    That function doesn't seem to be used to determine the uids to send the digest. The function for that is Digest.getSubscribers.

    Digest.getUsersInterval seems to be used on the ACP page to display the users digest setting.

  • Gamers

    @baris I'm actually looking to get the digest setting of one uid.

    what I just noticed is that, if you set in ACP the default "subscribe to digest" value to other than "OFF", indivudual users can't avoid receiving these digest. If a user sets in his personal profile settings "subscribe to digest" to "OFF" , and default value is "weeekly" the user will get the digest, event if the usr has set it to "OFF", beacuse it seems that "OFF" seams to be the same as Default.

    e8360c3b-0211-49cc-be2f-a89f7e85d247-image.png

  • NodeBB Admin

    That doesn't sound right, if the user sets their digest setting to off and saves their user settings then on this line dailyDigestFreq will be off meanwhile interval will be one of day/week/biweek/month so it won't send an email to that uid.

  • Gamers

    @baris are you sure? if you check the source code here

    https://github.com/NodeBB/NodeBB/blob/master/src/user/digest.js#L53

    const settings = await Promise.all([
    		db.isSortedSetMembers('digest:day:uids', uids),
    		db.isSortedSetMembers('digest:week:uids', uids),
    		db.isSortedSetMembers('digest:biweek:uids', uids),
    		db.isSortedSetMembers('digest:month:uids', uids),
    	]);
    
    	const interval = uids.map((uid, index) => {
    		if (settings[0][index]) {
    			return 'day';
    		} else if (settings[1][index]) {
    			return 'week';
    		} else if (settings[2][index]) {
    			return 'biweek';
    		} else if (settings[3][index]) {
    			return 'month';
    		}
    		return false;
    	});
    

    you can see that is only asking if the setting is day, week, biweek, or month. Anything different from that is false. So Off and default are the same (false)

    I will be doing a clean install of nodebb tomorrow in a new enviroment, and will tetst it, but Im pretty sure that is how is working now (Off = Default).

  • NodeBB Admin

    @Sebastián-Cisneros The code you pasted isn't used to determine who to send the digest emails to, it is only used to show the setting of the user in the acp page at https://community.nodebb.org/admin/manage/digest.

    If they set their setting to off then Digest.getSubscribers will not consider that user for the digest.

  • Gamers

    @baris I recommend you giving this a test. I just made a clean nodebb 2.0 install, and its working like I'm telling you, off = default , so if user sets digest to OFF, and default is set to weekly, the user will get the digest anyway.

    • This was my test, I've installed a clean nodebb 2.0 install in my local. I have 2 users, 1 admin, one regular user with email validated.

    • I've added a filter:email.send to persona theme just to consol.log when email is sent

    • with admin user, go to ACP, set digest default to weekly

    • with regular user go to front end user settings, and you will see the digest set weekly, this is ok, as its defaulted to weekly. In the same settings page make any changes to the profile, keep digest to weekly, save.

    • with admin user in ACP you can in MANAGE->DIGEST you can force send the digest, you also have in that page a column with "Subscription Type". If you search for the regular user there, you will see the subscription set to "week", if you click "resend digest" you will send the digest to that user, and you will see the console.log we've set before. This is OK so far.

    • with regular user go to front end user settings, and you will see the digest set weekly, this is ok, change it to OFF, and save.

    • with admin user in ACP go to MANAGE->DIGEST. If you search for the regular user there, you will see the subscription set to "System default". But wait.... the user has set it to OFF, here is the error. If you click "resend digest" the user will get the digest email, and the user has digest set to OFF.

    I really this this is a problem on nodebb core. Let me know what you think.

  • NodeBB Admin

    61e8172f-d9d1-4f4a-be9d-f327a7eb08e7-image.png

    As far as I know clicking 1 will always send a digest to that user because it uses the uid of the user directly. https://github.com/NodeBB/NodeBB/blob/master/src/socket.io/admin/digest.js#L19

    Clicking 2 should respect the settings of the users. Which one did you use for the testing?

  • Gamers

    @baris I've clicked 1, I can do testing with 2 in a couple hours. I will let you know the result.

  • NodeBB Admin

    Try with 2, the button next to the user (1) always sends the digest because of the above code.

  • Gamers

    @baris 1 and 2 both sending the digest, and user has personal digest set to off

    ded7b7fe-a7ed-4171-b4a6-2de744175bba-image.png

  • NodeBB Admin

    So I tested with the above config, I have two users admin (uid1) emailtest(uid 2).

    // uid2 digest set to "weekly"
    // "resend button"
    sending to  [ '2' ]
    // "weekly button"
    sending to  [ '1', '2' ]
    

    After changing emailtest digest setting to off

    uid2 digest set to "off"
    // "resend button"
    sending to  [ '2' ] 
    // "weekly button"
    sending to  [ '1' ] // it didn't send to uid 2 since setting is off
    
  • Gamers

    @baris got it. I think you are right. Sorry about all the confussion. I did your testing and is working like you say. I will do more testing in the next few days, but I think you are right. I was testing with "1", and that one always send the digest. and "2" only sends the digest to the users that should received it.

  • Gamers

    @Sebastián-Cisneros here is my confussion,

    04c06334-ffc9-447b-a05f-283305edb6c6-image.png

    if emailtest user has set digest to off, here you will see system default in the "subscription type" column. Shouldn't it say off? should the emailtest user have the option to set the digest back to nodebb default at some point (like adding a new option in the digest select "default")? just wondering....

  • NodeBB Admin

    @Sebastián-Cisneros Yeah I think that label should say off if the user set it to off in their settings. I will open an issue for that.

    https://github.com/NodeBB/NodeBB/issues/10631


  • @baris thanks! This was very helpful. @Sebastián-Cisneros and I really appreciate it.


Suggested Topics

  • 1
  • 1
  • 6
  • 2
  • 3
| | |

© 2014 – 2022 NodeBB, Inc. — Made in Canada.