Jump to content

Topic on Extension talk:Echo/Creating a new notification type

Notification icon shows 1 but no messages displayed

8
000Tom0000 (talkcontribs)

I am not sure where I go wrong as I have almost stripped all functionality. When I trigger a createEvent the icon on the top-right shows a "1" of new notification but when I click on it, it will only show old notifications. The counter gets cleared and I need to trigger a new notification. My presentation model looks like

    <?php
    class EchoDemoPresentationModel extends EchoEventPresentationModel
    {
        public function getIconType() {
            return 'edit';
        }
        public function getPrimaryLink() {
            return false;
        }
    }

(Jup fully stripped it)


and the onBeforeCreateEvent looks like

    public static function onBeforeCreateEchoEvent(
        &$notifications, &$notificationCategories, &$icons
    ) {
        $notificationCategories['demo-notif'] = [
            'priority' => 3,
            'tooltip' => 'echo-pref-tooltip-demo-notif',
        ];
        $notifications['demo-notif'] = [
            'category' => 'demo-notif',
            'group' => 'positive',
            'section' => 'local',
            'presentation-model' => EchoDemoPresentationModel::class,
            'bundle' => [
                'web' => true,
                'expandable' => true,
            ],
        ];
    }

This results in a https://i.imgur.com/XPDGtOU.png when I trigger an createEvent.


Is there any boilerplate demo I can use? I followed the tutorial on the page but this didn't help.


Matěj Suchánek (talkcontribs)

I am not sure but you probably didn't provide all necessary methods in the presentation model. You can use the CodeSearch tool to grep for live examples.

000Tom0000 (talkcontribs)

I used one of the Echo's itself (https://github.com/wikimedia/mediawiki-extensions-Echo/blob/master/includes/formatters/EditThresholdPresentationModel.php) and according to the documentation getHeaderMessage has a default value. I stripped down as much as possible as with all methods it also failed to show up. I even tried to do a var_dump in the construct but it just seems the presentation model does not show up. I've tried setting

'presentation-model' => EchoDemoPresentationModel::class, and 'presentation-model' => "EchoDemoPresentationModel", as examples show but still no luck. It seems I am missing some crucial detail somewhere but can't find it.

Matěj Suchánek (talkcontribs)

Other problem I can think of is invalid/missing input for EchoEvent::create. It could be a typo, e.g. in 'type' => '...'. Anyway, try Manual:How to debug and inspect JavaScript console or trigger the API call action=query&meta=notifications&... yourself (using Special:ApiSandbox or by hand). With server-side debugging, you should be able to capture the problem.

000Tom0000 (talkcontribs)

I've been using your information to look further and with the API I find my notification

               {
                   "wiki": "demowiki",
                   "id": 48816,
                   "type": "demo-notif",
                   "category": "demo-notif",
                   "section": "local",
                   "timestamp": {
                       "utciso8601": "2020-09-29T10:35:15Z",
                       "utcunix": 1601375715,
                       "unix": "1601382915",
                       "utcmw": "20200929103515",
                       "mw": "20200929123515",
                       "date": "Vandaag"
                   },
                   "targetpages": []
               }

but as soon as I press the icon on my wiki, it is gone out of this list. Seems that it gets the status "seen" but without me actually seeing it. I looked into the networking of what Echo uses and saw that as soon the API call "api.php?action=query&format=json&formatversion=2&meta=notifications&notsections=alert&notformat=model&notlimit=25&notprop=list|count|seenTime&uselang=nl&notcrosswikisummary=1&_=1601375603058" happens, it gets removed out of the list. Now as soon as I create a new event and use that second api call it never shows up. My event is never in this list.

It seems from that API call "&notformat=model" is the one who deletes my event and doesn't show it. Any idea what that is related to? The documentation just tells me that notformat=model means that RAW data will be send (https://www.mediawiki.org/wiki/Notifications/API)

Matěj Suchánek (talkcontribs)

When I make the same API call on this wiki, I get stuff like:

Besides the general "*" key, the "title" and "agent" are missing in your response. Do you provide these two to the EchoEvent::create call, as per Adding code to trigger the event? They are not listed as mandatory but I believe there might be some default code (to be overridden) failing on null values.

000Tom0000 (talkcontribs)

I've just added those two but no luck. the format=nomodel keeps "deleting"

$created = EchoEvent::create([

   'type' => 'demo-notif',
   'title' => Title::newFromText( "Hoofdpagina", $defaultNamespace=NS_MAIN ),
   'extra' => [
       "achievement_id" => $id,
       "user_id" => $userId,
       "description" => "Hey daar"
   ],
   'agent' => User::newFromId(12)

]);

$created Contains a valid EchoEvent

EchoEvent(id=48831; type=demo-notif)

000Tom0000 (talkcontribs)

Ok, after filtering out the logs ([Echo] No presentation model found for event type "demo-notif") with command tail -f debug-demowiki.log | grep --line-buffered "demo-notif". It seemed that my AutoLoad of the model class wasn't working? When looking in my extension I noticed I used

"AutoloadNamespaces": {
  "MediaWiki\\Extension\\Demo\\": "includes/"


},

which doesn't actually load the classes. After adding

"AutoloadClasses": {
  "EchoDemoPresentationModel": "includes/EchoDemoPresentationModel.php"
},

It started working, thanks for the hints were to look Matěj! And for people who stumble on this thread, make sure to actually load the representation class!