Need to hook to /api/user/username/topics .build

Plugin Development

Suggested Topics


  • 0 Votes
    5 Posts
    502 Views

    @baris
    thx a lot !!!!
    it's work finally!

  • 0 Votes
    10 Posts
    422 Views

    topics.getUnreadData doesn't take an array of pids. You should use Topics.hasReadTopics(tids, uid);

  • 0 Votes
    4 Posts
    2k Views

    @PitaJ I think I found a way, I use client-side on 'action:ajaxify.end': components.get('topic').append(html) where html is the parsed (by jQuery) element I want to show.

    If there is a way to do that server side instead of client side, I would really appreciate if you let me know 😂

    And also I don't really get how can I understand what every hook method takes as parameters, when I click on one of them in the hooks list on GitHub, it just show me a line of code, and I don't get what that line means (for example in filters:parse.post goes where there is an if statement, what that means?)

  • 0 Votes
    4 Posts
    2k Views

    @snodejoke

    Hey, yeah. I've been meaning to reply as well. What I typed above was actually and older 0.6.0 way of searching, and it doesn't actually work the way you want anyway.

    From what I can see, there is no way to search for custom fields using users.js

    It seems the proper way of doing would be to add a sorted set value when you create the field. If the field is a number, something like db.sortedSetAdd('users:yourfield', yourfield, uid, callback) then lookup with db.getSortedSetRangeByScore('users:yourfield', 0, count, min, max, callback), that's how I do it in my plugins now.

    If it's not a number, you need to store it as db.sortedSetAdd('yourfield:sorted', yourfield + ':' + uid, callback) then lookup with db.getSortedSetRangeByLex('yourfield:sorted', min, max, 0, count, callback)

    Here's how I sorted a custom field on my forum without creating a sortedset if you're interested:

    // Get all uids db.getSortedSetRange('users:joindate', 0, -1, function (err, uids) { // Get their custom_field User.getMultipleUserFields(uids, ['uid', custom_field], function (err, users) { // Sort by custom_field async.sortBy(users, function (user, next) { return next(null, user.custom_field); }, function (err, results) { console.log(results); }); }); });

    If not all users have the field, you can use the 'filter:users.get' hook to filter user results to only users that have the field, like I had to do.

    Hooks.filterUsersGet = function (users, next) { // If 'custom_field' isn't in the results, don't filter. if (users && users[0] && users[0].custom_field !== void 0) { // Filter it out if it's null. async.filter(users, function (user, next) { return next(user.custom_field !== null); }, function (results) { next(null, results); }); }else{ next(null, users); } };

    Result:

    [ { uid: '18', uuid: '069a79f444e94726a5befca90e38aaf5' }, { uid: '4', uuid: '294ecf637f1242c6a95d9cf8cc6da3ef' }, { uid: '3', uuid: '32a46cc646d64ffea4da962692858288' }, { uid: '5', uuid: '621ad5087ed448dd92dbc83950a222d9' }, { uid: '17', uuid: 'a85e5f36dc5e465d9c86c6ad88912e99' }, { uid: '1', uuid: 'f19cb1605bc24838835a07757d60ce80' } ]
  • API: Groups

    Solved Plugin Development
    0 Votes
    6 Posts
    3k Views

    Created a small plugin, to have access to all groups - https://community.nodebb.org/topic/4591/nodebb-plugin-ns-api-ns-api-extended