גיימיפיקציה של פורומים

האם ניתן לאפס ידנית את כתובת ה-URL של לוח התוצאות?

לדוגמה, leaderboards/2 ל-leaderboards/1.

Is it possible to award points to a user as an extra reward? :grin:

לייק 1

You may want to see:

which has this curl request inside:

curl --location 'https://my.discourse.com/admin/plugins/gamification/score_events' \
--header 'Api-Key: <your key>' \
--header 'Api-Username: <your username>' \
--header 'Content-Type: application/json' \
--data '{
    "user_id": "101",
    "date": "2024-05-15",
    "points": "-141",
    "description": "Gamification point adjustment"
}'
2 לייקים

הפעלתי את התוסף הזה ב-admin, אבל הלשונית Leaderboard לא הופיעה אוטומטית. גם הוספת רשימות חדשות לא הציגה אותן. למה זה קורה? איפה אני אמור לראות את הרשימות האלה?

I think you have to add them to the sidebar yourself :thinking:. The leaderboards are at /leaderboard, /leaderboard/2, /leaderboard/3 etc.

האם ניתן ליצור טבלת מובילים עבור קטגוריה או תג ספציפיים?

Leaderboards are tied to groups. But you can specify which categories affect all the leaderboards in the gamification settings. Seems like an interesting idea to move that to the leaderboard, to for example have a Support leaderboard here in this community.

3 לייקים

2 posts were split to a new topic: Reducing points for flagged users

Is there a way for me to exclude myself from the rankings?

yes add yourself to a new group (call it ‘leaderboard-exclusion’ or something) and then exclude the group in the plugin settings.

edit: this will also easily allow you to exclude anyone else if you so wish at some point, by adding them to the same group. :slight_smile:

2 לייקים

Thank you so much. That makes sense.

לייק 1

After I upgraded to version 2026.1.0, I created a monthly leaderboard, and then accessing the following route caused an error:

http://localhost:4200/admin/plugins/discourse-gamification/leaderboards

The error is as follows:

assert.js:40 
 Uncaught (in promise) Error: Assertion Failed: You attempted to update `_value` on `TrackedStorageImpl`, but it had already been used previously in the same computation.  Attempting to update a value after using it in a computation can cause logical errors, infinite revalidation bugs, and performance issues, and is not supported.

`_value` was first used:

- While rendering:
  {{outlet}} for -top-level
    -top-level
      {{outlet}} for application
        application
          DiscourseRoot
            {{outlet}} for admin
              admin
                {{outlet}} for adminPlugins
                  admin-plugins
                    {{outlet}} for adminPlugins.show
                      show
                        AdminPluginConfigPage
                          AdminPluginConfigArea
                            {{outlet}} for adminPlugins.show.discourse-gamification-leaderboards
                              adminPlugins.show.discourse-gamification-leaderboards
                                {{outlet}} for adminPlugins.show.discourse-gamification-leaderboards.index
                                  discourse-gamification-leaderboards
                                    DPageSubheader
                                      (result of a `unknown` helper)

Stack trace for the update:
    at TrackedArray._dirtyCollection2 (array.ts:163:13)
    at Object.set (array.ts:126:15)
    at Proxy.sort (<anonymous>)
    at AdminPluginsShowDiscourseGamificationLeaderboardsIndexController.sortedLeaderboards (index.js:23:1)
    at AdminPluginsShowDiscourseGamificationLeaderboardsIndexController.<anonymous> (handle-descriptor.js:67:17)

I located the problematic file as follows:

plugins/discourse-gamification/admin/assets/javascripts/discourse/controllers/admin-plugins/show/discourse-gamification-leaderboards/index.js

Specific code:

  @discourseComputed("model.leaderboards.@each.updatedAt")
  sortedLeaderboards(leaderboards) {
    return (
      leaderboards?.sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || [] // line 22
    );
  }

The reason for the error is:

Ember.js (or more accurately, the Glimmer tracking system) assertion error in reactive state management. The core reason is: within the same computation cycle, you first read a tracked (tracked state) value, and then attempt to modify that value. This “use then update” operation can lead to logical confusion, infinite loops, or performance issues, so Ember directly prohibits this behavior.

Key issue:

  • Array.sort() modifies the original array in place, which updates the @tracked leaderboards state.

  • The responsibility of a computed property (sortedLeaderboards) is to derive a new value, not to modify the original state; it should itself be a “pure function” (no side effects, does not modify the input source).

Here is the fix:

  @discourseComputed("model.leaderboards.@each.updatedAt")
  sortedLeaderboards(leaderboards) {
    return (
      //leaderboards?.sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || []
      leaderboards?.slice().sort((a, b) => compare(b?.updatedAt, a?.updatedAt)) || []
    );
  }

Screenshot after fixing:

And this kind of similar issue doesn’t seem to be an isolated case. I suspect it’s an incompatibility issue caused by the emberjs upgrade. However, many places in plugins haven’t been modified to keep up with the upgrade, as this work is not as simple as it sounds.

(post deleted by author)

You can redeem points by using the plugin’s API:

Looks like you got a similar reply here 有什么插件支持积分商城吗? - #2 by Lilly. Please don’t ask the same question in different topics.