Thread Tools Display Modes
12/16/14, 02:31 PM   #1
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
cannot unregister EVENT_RAID_SCORE_NOTIFICATION_*

I am currently playing around with the notification system and have encountered some strangeness that I cannot explain to myself.
My test setup:

Lua Code:
  1. ZO_PreHook(CHAT_SYSTEM, "OnNumNotificationsChanged", function(self, totalNumNotifications)
  2.     d("changed from " .. tostring(self.currentNumNotifications) .. " to " .. totalNumNotifications)
  3.     if(totalNumNotifications > 0) then error("test") end
  4. end)
  5.  
  6. zo_callLater(function()
  7.     d(NOTIFICATIONS.eventNamespace)
  8.     d(EVENT_MANAGER:UnregisterForEvent(NOTIFICATIONS.eventNamespace, EVENT_RAID_SCORE_NOTIFICATION_ADDED))
  9.     d(EVENT_MANAGER:UnregisterForEvent(NOTIFICATIONS.eventNamespace, EVENT_RAID_SCORE_NOTIFICATION_REMOVED))
  10.  
  11.     EVENT_MANAGER:RegisterForEvent("test", EVENT_RAID_SCORE_NOTIFICATION_ADDED, function() d("add event") end)
  12.     EVENT_MANAGER:RegisterForEvent("test", EVENT_RAID_SCORE_NOTIFICATION_REMOVED, function() d("remove event") end)
  13. end, 1000)

I expect this to hide the raid notifications until some other event refreshes the notification manager.
When I load the addon I get:
Code:
KeyboardNotifications
true
true
Which means it has unregistered both events successfully, but instead of ignoring the raid notifications it still handles them as if I never unregistered the event.
When I already have got some of them in my notifications panel and press the delete button, it shows
Code:
remove event
changed from 4 to 3
and then throws my error with the following stack traceback:
Code:
	[C]: in function 'error'
	user:/AddOns/test/test.lua:42: in function 'hookFunction'
	EsoUI/Libraries/Utility/ZO_Hook.lua:19: in function 'OnNumNotificationsChanged'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:705: in function 'ZO_NotificationManager:BuildNotificationList'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:678: in function 'ZO_NotificationManager:RefreshNotificationList'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:58: in function 'ZO_NotificationProvider:PushUpdateToNotificationManager'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:34: in function '(anonymous)'
When I let myself get killed and revive, it also throws the same error two times in a row.

Notifications_Common.lua:34 is inside the handler function that gets registered to both events in question and is - as far as I can see - never used anywhere else.

Maybe somebody can explain to me what is happening.
  Reply With Quote
12/16/14, 04:05 PM   #2
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
What is happening:
  1. Lets trigger any notification event, other then raid score. For example EVENT_CAMPAIGN_QUEUE_JOINED:
    Lua Code:
    1. EVENT_MANAGER:RegisterForEvent(self.notificationManager.eventNamespace, event, self.pushUpdateCallback)
    translated to global reference it is:
    Lua Code:
    1. EVENT_MANAGER:RegisterForEvent("KeyboardNotifications", EVENT_CAMPAIGN_QUEUE_JOINED, NOTIFICATIONS.providers[3].pushUpdateCallback)
  2. NOTIFICATIONS.providers[3].pushUpdateCallback
    Lua Code:
    1. provider.pushUpdateCallback = function()
    2.     provider:PushUpdateToNotificationManager()
    3. end
  3. NOTIFICATIONS.providers[3]:PushUpdateToNotificationManager()
    Lua Code:
    1. function ZO_NotificationProvider:PushUpdateToNotificationManager()
    2.     self:BuildNotificationList()
    3.     self.notificationManager:RefreshNotificationList()
    4. end
  4. NOTIFICATIONS.providers[3].notificationManager:RefreshNotificationList() == NOTIFICATIONS:RefreshNotificationList()
    Lua Code:
    1. function ZO_NotificationManager:RefreshNotificationList()
    2.     self:ClearNotificationList()
    3.     self:BuildNotificationList()
    4.     self:FinishNotificationList()
    5. end
  5. NOTIFICATIONS:BuildNotificationList()
    Lua Code:
    1. function ZO_NotificationManager:BuildNotificationList()
    2.     for i = 1, #self.providers do
    3.         self.providers[i]:BuildNotificationList()
    4.     end
    5.  
    6.     --rest of the original code
    7.  
    8. end
  6. NOTIFICATIONS.providers[10]:BuildNotificationList() - NOTIFICATIONS.providers[10] is an instance of ZO_KeyboardLeaderboardRaidProvider

As you can see raid score notification will be eventually added to the list even if you unregister update events.
  Reply With Quote
12/16/14, 07:02 PM   #3
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Perhaps what you need to override is ZO_NotificationList:FilterScrollList()

edit: no, that wouldn't report correct numbers. So post-hook ZO_LeaderboardRaidProvider:BuildNotificationList(), removing undesired entries (which is all of them? if so, no need to call original, just ZO_ClearNumericallyIndexedTable(self.list) and done )

edit2: lol, exactly Garkin, I just edited it before reading your post

Last edited by merlight : 12/16/14 at 07:37 PM.
  Reply With Quote
12/16/14, 07:30 PM   #4
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by merlight View Post
Perhaps what you need to override is ZO_NotificationList:FilterScrollList()
I'm hooking ZO_LeaderboardRaidProvider:BuildNotificationList() in No, thank you! (and before I have used the same hook in my updated version of Thurisaz Guild Info).
I think that's the best place where you can change which notifications will be displayed. If you modify FilterScrollList instead, I believe that when you receive new notification there will be glowing notification button on the chat window. It's becuae function just counts number of items on each notification list (#provider.list), it does not check if items are filtered or not.
  Reply With Quote
12/17/14, 12:46 AM   #5
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
It's clear to me that it will trigger when any other notification event is fired, but that does not explain why it still happens in response to me clicking the delete button on a raid notification after I unregistered the EVENT_RAID_SCORE_NOTIFICATION_REMOVED event.

I will test it again with all other notification events unregistered in the evening.
In that case the push function in line 34 should never be called, right?
  Reply With Quote
12/17/14, 01:57 AM   #6
Minceraft
 
Minceraft's Avatar
AddOn Author - Click to view addons
Join Date: Jun 2014
Posts: 51
Red face

Originally Posted by sirinsidiator View Post
It's clear to me that it will trigger when any other notification event is fired, but that does not explain why it still happens in response to me clicking the delete button on a raid notification after I unregistered the EVENT_RAID_SCORE_NOTIFICATION_REMOVED event.
I was thinking maybe that each EVENT is considered a separate EVENT in terms of you're blocking only the NEXT event that fires...then it clears the clear..kinda the same way that ON_PLAYER_ACTIVATED works... When you unregister it at the end of it's own function, it will re register every time you reload the UI or the like...so when you click the delete button, maybe it's canceling out your cancel?? Clicking the delete button may reset the event registry for the function. Just a thought!

Last edited by Minceraft : 12/17/14 at 02:01 AM.
  Reply With Quote
12/17/14, 07:38 AM   #7
Garkin
 
Garkin's Avatar
AddOn Author - Click to view addons
Join Date: Mar 2014
Posts: 832
Originally Posted by Minceraft View Post
I was thinking maybe that each EVENT is considered a separate EVENT in terms of you're blocking only the NEXT event that fires...then it clears the clear..kinda the same way that ON_PLAYER_ACTIVATED works... When you unregister it at the end of it's own function, it will re register every time you reload the UI or the like...so when you click the delete button, maybe it's canceling out your cancel?? Clicking the delete button may reset the event registry for the function. Just a thought!
It has nothing to do with next event. You are either registered for that event or not. If you relaod UI, everything goes to the default state. So if default state is that you're registered fo EVENT_PLAYER_ACTIVATED, your function will be called.

Originally Posted by sirinsidiator View Post
It's clear to me that it will trigger when any other notification event is fired, but that does not explain why it still happens in response to me clicking the delete button on a raid notification after I unregistered the EVENT_RAID_SCORE_NOTIFICATION_REMOVED event.

I will test it again with all other notification events unregistered in the evening.
In that case the push function in line 34 should never be called, right?
Yes, pushUpdateCallback is called only if registered event is triggered. Try to check which events are triggered at the time when you click Delete button using the Zgoo (/zgoo events).
  Reply With Quote
12/17/14, 10:39 AM   #8
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Just tried to unregister every event related to notifications:
Lua Code:
  1. ZO_PreHook(CHAT_SYSTEM, "OnNumNotificationsChanged", function(self, totalNumNotifications)
  2.     error("test")
  3. end)
  4.  
  5. local events = {
  6.     "EVENT_INCOMING_FRIEND_INVITE_ADDED",
  7.     "EVENT_INCOMING_FRIEND_INVITE_REMOVED",
  8.     "EVENT_INCOMING_FRIEND_INVITE_NOTE_UPDATED",
  9.     "EVENT_GUILD_INVITES_INITIALIZED",
  10.     "EVENT_GUILD_INVITE_ADDED",
  11.     "EVENT_GUILD_INVITE_REMOVED",
  12.     "EVENT_CAMPAIGN_QUEUE_JOINED",
  13.     "EVENT_CAMPAIGN_QUEUE_LEFT",
  14.     "EVENT_CAMPAIGN_QUEUE_STATE_CHANGED",
  15.     "EVENT_RESURRECT_REQUEST",
  16.     "EVENT_RESURRECT_REQUEST_REMOVED",
  17.     "EVENT_PLAYER_ALIVE",
  18.     "EVENT_GROUP_INVITE_RECEIVED",
  19.     "EVENT_GROUP_INVITE_REMOVED",
  20.     "EVENT_TRADE_INVITE_CONSIDERING",
  21.     "EVENT_TRADE_INVITE_REMOVED",
  22.     "EVENT_QUEST_SHARED",
  23.     "EVENT_QUEST_SHARE_REMOVED",
  24.     "EVENT_PLEDGE_OF_MARA_OFFER",
  25.     "EVENT_PLEDGE_OF_MARA_OFFER_REMOVED",
  26.     "EVENT_AGENT_CHAT_REQUESTED",
  27.     "EVENT_AGENT_CHAT_ACCEPTED",
  28.     "EVENT_AGENT_CHAT_DECLINED",
  29.     "EVENT_RAID_SCORE_NOTIFICATION_ADDED",
  30.     "EVENT_RAID_SCORE_NOTIFICATION_REMOVED",
  31. }
  32.  
  33. local function ReassignEvent(name)
  34.     d("unregister " .. name .. ": " .. tostring(EVENT_MANAGER:UnregisterForEvent(NOTIFICATIONS.eventNamespace, _G[name])))
  35.     EVENT_MANAGER:RegisterForEvent("test", _G[name], function() d(name) end)
  36. end
  37.  
  38. zo_callLater(function()
  39.     d(NOTIFICATIONS.eventNamespace)
  40.     for _, name in ipairs(events) do
  41.         ReassignEvent(name)
  42.     end
  43. end, 1000)

The messages that were showing up when I revived obviously were caused by EVENT_PLAYER_ALIVE.

When I join a campaign queue I get:
Code:
EVENT_CAMPAIGN_QUEUE_JOINED
user:/AddOns/test/test.lua:130: test
stack traceback:
	[C]: in function 'error'
	user:/AddOns/test/test.lua:130: in function 'hookFunction'
	EsoUI/Libraries/Utility/ZO_Hook.lua:19: in function 'OnNumNotificationsChanged'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:705: in function 'ZO_NotificationManager:BuildNotificationList'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:678: in function 'ZO_NotificationManager:RefreshNotificationList'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:58: in function 'ZO_NotificationProvider:PushUpdateToNotificationManager'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:34: in function '(anonymous)'
EVENT_CAMPAIGN_QUEUE_STATE_CHANGED
user:/AddOns/test/test.lua:130: test
stack traceback:
	[C]: in function 'error'
	user:/AddOns/test/test.lua:130: in function 'hookFunction'
	EsoUI/Libraries/Utility/ZO_Hook.lua:19: in function 'OnNumNotificationsChanged'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:705: in function 'ZO_NotificationManager:BuildNotificationList'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:678: in function 'ZO_NotificationManager:RefreshNotificationList'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:58: in function 'ZO_NotificationProvider:PushUpdateToNotificationManager'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:34: in function '(anonymous)'
EVENT_CAMPAIGN_QUEUE_LEFT
user:/AddOns/test/test.lua:130: test
stack traceback:
	[C]: in function 'error'
	user:/AddOns/test/test.lua:130: in function 'hookFunction'
	EsoUI/Libraries/Utility/ZO_Hook.lua:19: in function 'OnNumNotificationsChanged'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:705: in function 'ZO_NotificationManager:BuildNotificationList'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:678: in function 'ZO_NotificationManager:RefreshNotificationList'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:58: in function 'ZO_NotificationProvider:PushUpdateToNotificationManager'
	EsoUI/Ingame/Contacts/Notifications_Common.lua:34: in function '(anonymous)'
I am not sure what I am missing here, but in my opinion this should work and not call the push function anymore...
  Reply With Quote
12/17/14, 10:48 AM   #9
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Try unregistering for GAMEPAD_NOTIFICATIONS as well, not sure how they would only use one.
  Reply With Quote
12/17/14, 10:57 AM   #10
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,578
Lua Code:
  1. local function ReassignEvent(namespace, name)
  2.     d("unregister " .. name .. ": " .. tostring(EVENT_MANAGER:UnregisterForEvent(namespace, _G[name])))
  3.     EVENT_MANAGER:RegisterForEvent("test", _G[name], function() d(name) end)
  4. end
  5.  
  6. zo_callLater(function()
  7.     d(NOTIFICATIONS.eventNamespace)
  8.     for _, name in ipairs(events) do
  9.         ReassignEvent(NOTIFICATIONS.eventNamespace, name)
  10.     end
  11.    
  12.     d(GAMEPAD_NOTIFICATIONS.eventNamespace)
  13.     for _, name in ipairs(events) do
  14.         ReassignEvent(GAMEPAD_NOTIFICATIONS.eventNamespace, name)
  15.     end
  16. end, 1000)

You deserve a medal merlight!
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » cannot unregister EVENT_RAID_SCORE_NOTIFICATION_*


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off