Created
May 6, 2012 18:26
-
-
Save prof7bit/2623653 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
procedure OnLogin(Account: PPurpleAccount); cdecl; | |
var | |
Client: TTorChatPurpleClient; | |
Status: PPurpleStatus; | |
TorChatBuddy: TABuddy; | |
PurpleBuddy: PPurpleBuddy; | |
TorchatList: TABuddyList; | |
PurpleList: PGSList; | |
ID : String; | |
begin | |
WriteLn('OnLogin'); | |
Client := TTorChatPurpleClient.Create(nil); | |
Client.PurpleAccount := Account; | |
Client.PurpleTimer := purple_timeout_add(1000, @OnPurpleTimer, Client); | |
TorChatClients.Add(Account^.username, Client); | |
purple_connection_set_state(Account^.gc, PURPLE_CONNECTED); | |
WriteLn('created torchat client object for ' + Account^.username); | |
// remove buddies from purple's list that not in TorChat's list | |
TorchatList := TorChatClients.Get(Account).BuddyList; | |
PurpleList := purple_find_buddies(Account, nil); | |
while Assigned(PurpleList) do begin | |
ID := purple_buddy_get_name(PurpleList^.data); | |
WriteLn('found ' + ID + ' on purple buddy list'); | |
if not Assigned(TorchatList.FindBuddy(ID)) then begin | |
purple_blist_remove_buddy(PurpleList^.data); | |
end; | |
PurpleList := g_slist_delete_link(PurpleList, PurpleList); | |
end; | |
// add buddies to purple's buddy list that are not in purple's list | |
TorchatList.Lock; | |
for TorChatBuddy in TorchatList.Buddies do begin | |
if purple_find_buddy(Account, PChar(TorChatBuddy.ID)) = nil then begin | |
PurpleBuddy := purple_buddy_new(Account, PChar(TorChatBuddy.ID), PChar(TorChatBuddy.FriendlyName)); | |
purple_blist_add_buddy(PurpleBuddy, nil, nil, nil); | |
end; | |
end; | |
TorchatList.Unlock; | |
// it won't call set_status after login, so we have to do it ourselves | |
Status := purple_presence_get_active_status(Account^.presence); | |
OnSetStatus(Account, Status); | |
end; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment