Extension talk:Echo/Creating a new notification type
Add topic| This page used the Structured Discussions extension to give structured discussions. It has since been converted to wikitext, so the content and history here are only an approximation of what was actually displayed at the time these comments were made. |
Save notification body text in the event?
[edit]The example on this page adds an 'excerpt' extra parameter to the event, which is then displayed as the notification body. Is this best practice? Or, is it preferred if possible to store the least amount of data in the event, and look up anything else when the notification is displayed?
For example, the Thanks extension stores an edit excerpt (using EchoDiscussionParser::getEditExcerpt()) in the event, but then when displaying the notification first tries to look up the revision comment and will use that if it can (i.e. if it's still visible to the user) and only if it can't use that will it display the stored excerpt. Sam Wilson 07:32, 14 February 2018 (UTC)
Notification icon shows 1 but no messages displayed
[edit]The following discussion is closed. Please do not modify it. Subsequent comments should be made on the appropriate discussion page. No further edits should be made to this discussion.
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.
000Tom0000 (talk) 06:41, 29 September 2020 (UTC)
- I am not sure but you probably didn't provide all necessary methods in the presentation model. You can use the CodeSearch tool to
grepfor live examples. Matěj Suchánek (talk) 09:40, 29 September 2020 (UTC) - 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. 000Tom0000 (talk) 10:11, 29 September 2020 (UTC)- 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 callaction=query&meta=notifications&...yourself (using Special:ApiSandbox or by hand). With server-side debugging, you should be able to capture the problem. Matěj Suchánek (talk) 10:20, 29 September 2020 (UTC) - 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¬sections=alert¬format=model¬limit=25¬prop=list|count|seenTime&uselang=nl¬crosswikisummary=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 "¬format=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) 000Tom0000 (talk) 10:48, 29 September 2020 (UTC)
- When I make the same API call on this wiki, I get stuff like:
| Extended content |
|---|
{
"wiki": "mediawikiwiki",
"id": 1230609,
"type": "mention",
"category": "mention",
"section": "alert",
"timestamp": {
"utciso8601": "2020-09-23T00:43:09Z",
"utcunix": 1600821789,
"unix": "1600821789",
"utcmw": "20200923004309",
"mw": "20200923004309",
"date": "23. 9. 2020"
},
"title": {
"full": "Extension talk:Wikibase Client/Lua",
"namespace": "Extension_talk",
"namespace-key": 103,
"text": "Wikibase Client/Lua"
},
"agent": {
"id": 1006910,
"name": "Evolution and evolvability"
},
"revid": 4128415,
"read": "20200924074142",
"targetpages": [],
"*": {
"header": "Evolution and evolva… vás zmínil v diskusi <strong>Extension talk:Wikibase Client/Lua</strong> u „<strong>wikibase.getEntityIdForCurrentPage() when called f…</strong>“.",
"compactHeader": "Evolution and evolva… vás zmínil v diskusi <strong>Extension talk:Wikibase Client/Lua</strong> u „<strong>wikibase.getEntityIdForCurrentPage() when called f…</strong>“.",
"body": "@Matěj Suchánek: thanks. Would there be a way to pull the pagetitle automatically from within the lua module to pass to that function? I'm pretty new…",
"icon": "mention",
"links": {
"primary": {
"url": "https://www.mediawiki.org/wiki/Extension_talk:Wikibase_Client/Lua?markasread=1230609&markasreadwiki=mediawikiwiki#wikibase.getEntityIdForCurrentPage()_when_called_from_talkpage",
"label": "Zobrazit zmínku"
},
"secondary": [
{
"url": "https://www.mediawiki.org/wiki/User:Evolution_and_evolvability",
"label": "Evolution and e…",
"tooltip": "Evolution and evolvability",
"description": "",
"icon": "userAvatar",
"prioritized": true
},
{
"url": "https://www.mediawiki.org/w/index.php?title=Extension_talk:Wikibase_Client/Lua&oldid=prev&diff=4128415",
"label": "Zobrazit změny",
"description": "",
"icon": "changes",
"prioritized": true
}
]
},
"iconUrl": "/w/extensions/Echo/modules/icons/mention-progressive.svg"
}
}
|
- Besides the general
"*"key, the"title"and"agent"are missing in your response. Do you provide these two to theEchoEvent::createcall, 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. Matěj Suchánek (talk) 11:32, 29 September 2020 (UTC) - 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 (talk) 12:47, 29 September 2020 (UTC)- 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! 000Tom0000 (talk) 13:26, 29 September 2020 (UTC)
Translation markup
[edit]@Shirayuki FYI, I will restore proper translation markup on this page soon in the areas I recently edited, I just didn't want to bother with that while I was writing new content. Matma Rex (talk) 12:45, 29 May 2025 (UTC)