استيراد فئة User بدلاً من استخدام User

Hello dear community,
I have some time to fix the warnings in our community. One of them is the following:

Deprecation notice: Import the User class instead of using User (deprecated since Discourse 2.4.0) (removal in Discourse 2.6.0)

I’m trying to debug if from the DevTools but It does not let me enter the file where the warning is coming from. It says:

Could not load content for URL/assets/var/www/discourse/public/assets/_application-d88a387e24ec4397c59d853355d071080a32aa58498a2ea0a509cebee72839c0.js : HTTP status code: 404

Anyway, I entered the safe mode with leaving only the theme. It looks like the warning is coming from my theme. In my theme I found out that I use in an HTML file:

<script type="text/discourse-plugin" version="0.8.13">
api.decorateWidget('header:before', helper => {
  // ... code
  var currentUser = Discourse.User.current();
  // ... code
});
</script>

So my technical questions are as follows:

  1. Could the warning come from this line? if so, how should I import User and solve the warning?
  2. How should I debug the compressed JS files from DevTools?

Thank you in advance! :slight_smile:

Change

var currentUser = Discourse.User.current();

to

var currentUser = api.getCurrentUser();

6 إعجابات

No need to import anything as it says in the message?

No, as the API already provides that for you.

إعجابَين (2)

Awesome! thank you very much :slight_smile:
It looks like I have more places to fix like Discourse.Site.currentProp('trustLevels').
Is there a proper documentation I could read in order to understand which method to use instead of the old ones?

Same here, would I need to replace Discourse.Site.currentProp('user_fields') (see here) with something else?

إعجاب واحد (1)

أعتقد أن هذا الموضوع يجب أن يكون ضمن فئة Support - Discourse Meta.

أواجه نفس المشكلة: تنبيه بإلغاء الدعم: استيراد فئة User بدلاً من استخدام User (تم إلغاؤه منذ Discourse 2.4.0) (سيتم إزالته في Discourse 2.6.0) في أحدث إصدار، 2.6.0.beta3.

موقعي الإلكتروني يعمل ببطء عند زيارة المستخدم لأول مرة.

هل يمكنك شرح أين يجب أن أبدأ؟ كيف أغير هذه القيمة؟ من منطقة الإدارة؟

شكرًا لك

تُوجَّه هذه الإشعارات المتعلقة بالإيقاف التدريجي إلى مطوري السمات والإضافات.

“إذا لم تكن تعرف كيفية القيام بذلك، فأنت لست الشخص الذي ينبغي عليه القيام بذلك”.

3 إعجابات

كمطور سمات، إذا كنت تستخدم أكثر من مجرد User.current()، فإن الاستبدال هو:

const User = require('discourse/model/user').default;
إعجابَين (2)