View Single Post
05-22-14, 12:30 AM   #11
Niketa
A Wyrmkin Dreamwalker
 
Niketa's Avatar
AddOn Author - Click to view addons
Join Date: Jul 2013
Posts: 54
Finally got a chance to look at this again and I think I have it working like I want.

I solved the issue with the login spam by starting off watching only PLAYER_ENTERING_WORLD and registering the other events when that went off after adding all the friends to the table (this seemed to be what fixed it moreso than the events). I checked and BNGetFriendInfo() returns nil for client if the person is offline so there wasn't really a need for checking if they're online or anything of that sorts.

As far as the issue with the message not showing game specific login alerts, that was because we were passing in the presence id as arg13 when we actually needed to pass that the toon id instead.

I added an extra check for printing the message to make sure the chat window is supposed to display those toast alerts first (I actually have a custom window I dedicate to whispers only and it was posting there before I did this).

When a player logs off, I think the message works because it still has a player link since they are on the desktop app so you can differentiate it between a real log off and a game log off but I am not sure if I care much for the spam personally of the log off AND log on. I mainly worry about the log on because usually I will know if I'm waiting for someone to log on but it is helpful to see when they start switching too. I think for my indecisiveness it probably calls for a toggle option and personal preference of whether or not offline messages should display.

lua Code:
  1. local events = CreateFrame("Frame")
  2.       events:RegisterEvent("PLAYER_ENTERING_WORLD")
  3.  
  4. local friends = {}
  5.  
  6. events:SetScript("OnEvent", function(self, event)
  7.     if event == "PLAYER_ENTERING_WORLD" then
  8.         for x = 1, BNGetNumFriends() do
  9.             local id, _, _, _, _, _, client = BNGetFriendInfo(x)
  10.             friends[id] = client
  11.         end
  12.  
  13.         events:RegisterEvent("BN_TOON_NAME_UPDATED")
  14.         events:RegisterEvent("BN_FRIEND_TOON_ONLINE")
  15.         events:RegisterEvent("BN_FRIEND_ACCOUNT_OFFLINE")
  16.     else
  17.         for x = 1, BNGetNumFriends() do
  18.             local id, name, _, _, _, toonid, client = BNGetFriendInfo(x)
  19.             local prev = friends[id]
  20.  
  21.             if prev and prev ~= client then
  22.                 local message = prev == "App" and "FRIEND_ONLINE" or client == "App" and "FRIEND_OFFLINE"
  23.  
  24.                 if message and toonid then
  25.                     for i = 1, NUM_CHAT_WINDOWS do
  26.                         local types = {GetChatWindowMessages(i)}
  27.  
  28.                         for k, v in pairs(types) do
  29.                             if v == "BN_INLINE_TOAST_ALERT" then
  30.                                 ChatFrame_MessageEventHandler(_G["ChatFrame"..i], "CHAT_MSG_BN_INLINE_TOAST_ALERT", message, name, nil, 0, nil, nil, nil, nil, nil, nil, 0, nil, toonid)
  31.                                 break
  32.                             end
  33.                         end
  34.                     end
  35.                 end
  36.             end
  37.  
  38.             friends[id] = client
  39.         end
  40.     end
  41. end)

Now the only issue I'm having, however is if I am on the app and I log onto a toon, say Rainbowcat again, and I log off WoW and then immediately back onto Rainbowcat, no message is posted. Then, when I log off and back onto Rainbowcat and it posts.

If I started out on Rainbowcat, then logged on Niketa it would post that I logged on Niketa too but it seems that if you log on the same toon twice in a row it doesn't alert the logon.

When I was printing out some of the things, the toonid would be the same for the toon every time so I'm wondering if it's something in the Blizz code that tries to prevent double posts or something?

Anyhow, a quick fix I can think of is just if the message is "FRIEND_ONLINE" to print twice (as below) but it just seems like a workaround to me. Is there a better way to fix it or is that what it's going to come down to?

lua Code:
  1. if message == "FRIEND_ONLINE" then
  2.     ChatFrame_MessageEventHandler(_G["ChatFrame"..i], "CHAT_MSG_BN_INLINE_TOAST_ALERT", message, name, nil, 0, nil, nil, nil, nil, nil, nil, 0, nil, toonid)
  3. end
  4. ChatFrame_MessageEventHandler(_G["ChatFrame"..i], "CHAT_MSG_BN_INLINE_TOAST_ALERT", message, name, nil, 0, nil, nil, nil, nil, nil, nil, 0, nil, toonid)

Last edited by Niketa : 05-22-14 at 12:46 AM.
  Reply With Quote