Navigation

    • Register
    • Login
    • Search
    • Categories
    • Recent
    • Popular
    • Tags
    • Users
    • Groups
    1. Home
    2. magnusvhendin
    • Profile
    • Following 0
    • Followers 2
    • Topics 19
    • Posts 48
    • Best 6
    • Groups 1

    magnusvhendin

    @magnusvhendin

    Swedes

    6
    Reputation
    65
    Profile views
    48
    Posts
    2
    Followers
    0
    Following
    Joined Last Online
    Location Stockholm, Sweden

    magnusvhendin Unfollow Follow
    Swedes

    Best posts made by magnusvhendin

    • Append templateData to sidebar

      So I've been working with NodeBB for a while now and am familiar with several concepts, but one thing I'm not sure about.

      If I want to add data to the "global scope" before render. How would I do that?

      I know how to get data to the page templates, but that doesn't carry over into the global templates, like the sidebar menu.

      How can I, for instance, fetch my categories and place them in the sidebar?

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • Getting all recent topics in all available categories

      I'm getting all available categories for a user with categories.getCategoriesByPrivilege. Then I append to it with
      categories.getRecentTopicReplies. I'm not getting what I want, only the top post (reply).

      What I want is the following; a list of all topics with recent posts (preferably with a max limit in time range), within my available categories. What the client I'm working for want is a feed type thing with all recent activity displayed in one single flow. Then I will also drill down into specific categories but I think I've got that covered.

      This is where I'm at so far:

      Controllers.renderFeedPage = function (req, res) {
      	if (!req.uid) {
      		res.render('feed', {});
      	}
      	let categoriesData;
      	let tree;
      
      	async.waterfall([
      		(next) => {
      			categories.getCategoriesByPrivilege('categories:cid', req.uid, 'find', next);
      		},
      		(_categoriesData, next) => {
      			categoriesData = _categoriesData;
      
      			tree = categories.getTree(categoriesData, 0);
      			categories.getRecentTopicReplies(categoriesData, req.uid, next);
      		},
      		() => {
      			const data = {
      				title: meta.config.homePageTitle || '[[pages:home]]',
      				categories: tree,
      			};
      			res.render('feed', data);
      		},
      	]);
      };
      

      I haven't found a good example from the forum and I'm reading source code at this point.

      If anyone has done something similar I would really appreciate the input and a nudge in the right direction.

      Thanks!

      posted in NodeBB Development
      magnusvhendin
      magnusvhendin
    • RE: Fetching post data with formatting

      Turned out I was fetching the post data wrong. I was using getPostData when i should've been using getPostsByPids.

      posted in NodeBB Plugins
      magnusvhendin
      magnusvhendin
    • RE: Append templateData to sidebar

      @baris Just what I needed. Thanks a lot!!

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • Cached scripts

      Hi all!
      I've run into an issue that when I deploy a new version of my theme/plugin, most users don't get any changes done until they do a hard refresh. This only seems to affect the client side Javascript, so everything looks updated, but in reality functionality gets lost.

      Has anyone stumbled upon something similar? Is there a better way to release code?

      The background in this is that I have forked Persona and built upon it, so all changes to the platform is basically in the theme. Is there a way to make sure all clients receive all updates?

      Thanks!

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • RE: Client script cannot be available in both main and admin?

      Thanks for the clarification @PitaJ! I did a lot of experimenting but I guess I didn't get the right combination. I think I never tried naming the module with its extension. That might have been it. For anyone who might be interested in the actual solution, here it is:

      In file-explorer.js:

      define('azure/file-explorer', ['components'], function (components) {
      	const FileExplorer = {};
      
      	FileExplorer.init = function () {
      		// Init stuff here	
      	});
      
      	return FileExplorer;
      });
      

      In plugin.json:

      "modules": {
      	"azure/file-explorer.js": "static/lib/file-explorer.js"
      },
      

      In admin.js:

      define('admin/plugins/azure', ['settings', 'azure/file-explorer'], function (settings, fileExplorer) {
      	fileExplorer.init();
      });
      

      In main.js:

      $(document).ready(function () {
      	require(['azure/file-explorer'], (fileExplorer) => {
      		fileExplorer.init();
      	});
      });
      
      posted in Plugin Development
      magnusvhendin
      magnusvhendin

    Latest posts made by magnusvhendin

    • RE: Redirect to login

      @baris That's it. Worked like a charm. Thanks!

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • RE: Redirect to login

      I also tried to use the helper function notAllowed, but I get the same result. Redirects to /login but get errors in the log that data is undefined and there is no catch().

      library.checkLoginStatus = async (data) => {
      	if (data.req.loggedIn ||
      		allowedUrls(data.req.url)
      	) {
      		return data;
      	}
      	return Helpers.notAllowed(data.req, data.res);
      };
      
      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • RE: Redirect to login

      Seems like reverting to callbacks resolves it. I really wanted this to work with async/await, since callbacks will sooner or later be phased out I guess.

      library.checkLoginStatus = (data, callback) => {
      	if (data.req.loggedIn ||
      		allowedUrls(data.req.url)
      	) {
      		callback(null, data);
      	} else {
      		Helpers.redirect(data.res, '/login');
      	}
      };
      
      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • RE: Redirect to login

      Though this works, it also redirects every call for assets (images, stylesheets etc). So I get a site without CSS. 😄

      Maybe another hook is more appropriate?

      I also have another function that redirects to the profile page if some information is not properly filled in.

      So the overarching question is not to lock people out, it's more about how to divert a user based on some conditions. For instance, we have to require the users full name, so if it's not filled out, they get redirected to their profile edit page and asked to fill it in.

      EDIT: I forgot to tag you @baris.

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • Redirect to login

      I have been having some issues since NodeBB went all in on async/await. I have a private forum so I need to redirect to /login if the visitor isn't logged in.

      What worked before was a library function listening to filter:middleware.render, and then:

      library.checkLoginStatus = async (data) => {
      
      	if (data.req.loggedIn ||
      			allowedUrls(data.req.url)
      	) {
      		return data;
      	}
      	return Helpers.redirect(data.res, '/login');
      };
      

      allowedUrls is a function that just checks the requested url against a list of allowed ones (like /login, /email/unsubscribe and /register).

      Everything worked great but now I'm upgraded to 1.16.x.

      The issue I'm having is that there are other functions that tails this one listening to the same hook. So my question is if I can interrupt that flow somehow on redirect. Or maybe there's an even better solution, but it needs to be forum wide. The tailing functions get undefined passed in so everything breaks. The weird thing is that everything seems to work, and it semi silently drops the error. But I don't want a bunch of error logs cluttering things up.

      I know NodeBB is meant to be open and all, but in this case I need to lock it down until someone has registered. I built this functionality when on 1.12 I think so something else might be a better option.

      I'm turning to you community.

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • RE: Difference between templateValues and templateData

      Yep, I see the issue. I'm not looking to push any changes. It was more out of curiosity on why there are several different names within essentially the same function.

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • RE: Difference between templateValues and templateData

      Yeah, I guess my line of thinking is; why not just have templateValues and templateData on initial render and then templateDataon page render? It just feels a bit confusing with these different signatures and names.

      So, what is data used for when header is rendered? Is it even used? And if not, why not just use templateData on all of them with things related to their function?

      templateData on header hook is to render header.
      templateData on page hook is to render page.
      templateData on footer hook is to render footer.

      I'm guessing there are cases where it's useful for data to be passed along the ride, but they're already treated as different parts, so maybe it's just easier to separate them entirely.

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • Difference between templateValues and templateData

      Hi!
      What's the difference between templateValues (tV) and templateData (tD)?

      I know we get tD from a template hook and tV from a header hook, but we also get data from the header hook, which contains the dame data as in tD?

      Hook data object keys in the two cases:

      • [ 'req', 'res', 'templateValues', 'data' ] from header hook.
      • [ 'req', 'res', 'templateData' ] from template hook.

      So this might not be a technical question at all. I'm just wondering what the naming is meant to be. Maybe someone can shed some light on this, perhaps simple question?

      For instance, if data in header hook is the same as tD in template hook, why is it not just called templateData instead, to avoid confusion?

      I guess a header hook is only fired on initial render and not when the user navigates around, as is the case with a template hook.

      Also, when for filter:middleware.renderFooter is fired, only tV is present and not data?

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • Hide category from feeds

      Is there some way to hide all topics within a category from all feeds (recent, popular, new, the digest)?

      I need the topics to be accessible (and usable) to all users directly, but not searchable or showing up at random.

      posted in Plugin Development
      magnusvhendin
      magnusvhendin
    • RE: Send invite without a user

      Thank you for the response @gotwf!

      The issue is that I cannot delete an invite if I leave the inviter uid blank. I would think that an error would've been sent if this would cause problems. I have added a field in my plugin that will let admins select who will work as the inviter. in my case it's a system user, like no_reply@service...

      The sender is a no-person email so that's not the issue. The issue is that the invite needs to (in the system) be sent my a user. Which doesn't make sense in my opinion. It's great if an admin sends an invite, but why prevent me from deleting an invite that doesn't have an error?

      posted in Plugin Development
      magnusvhendin
      magnusvhendin