unit FriendsService; interface uses StrUtils, SysUtils, Windows, superobject, Classes, BaseService; type TFriendsService = class(TBaseService) private FFriends: TStrings; public function GetFriends: TStringList; procedure Init; procedure Uninstall; procedure AddFriends(AFriends: TStrings); procedure AddFriend(AFriend: TObject); function IsFriend(ALoginName: string): Boolean; constructor Create; destructor Destroy; override; class function GetService: TFriendsService; static; /// /// 批量处理好友状态,处理09协议 /// /// procedure HandeFriendsState(AJo: ISuperObject); procedure RequestUserStatus(AUsers: TStringList); end; implementation uses MainFrm, DataProviderImport, InterfaceDataProvider, LoggerImport, Messages, UsersService, RealICQClient, AsynRequestUserStatus, RealICQModel; var AFriendsService: TFriendsService; { TFriendsService } function TFriendsService.GetFriends: TStringList; var tmpList: TStringList; begin tmpList := TStringList.Create; tmpList.AddStrings(FFriends); try Result := TUsersService.GetUsersService.GetOrCreateUsers(tmpList); finally FreeAndNil(tmpList); end; end; procedure TFriendsService.RequestUserStatus(AUsers: TStringList); var AsynAction: TAsynRequestUserStatus; begin AsynAction := TAsynRequestUserStatus.Create(True); AsynAction.Protocol := FRIENDS_USERSTATE_PROLOCOL; AsynAction.Users := TStringList.Create; AsynAction.Users.AddStrings(AUsers); AsynAction.Resume; end; procedure TFriendsService.Init; begin Uninstall; end; function TFriendsService.IsFriend(ALoginName: string): Boolean; begin Result := FFriends.IndexOf(ALoginName) >= 0; end; procedure TFriendsService.Uninstall; begin FFriends.Clear; end; destructor TFriendsService.Destroy; begin FreeAndNil(FFriends); Inherited; end; procedure TFriendsService.AddFriend(AFriend: TObject); begin if not AFriend.ClassNameIs('TRealICQUser') then Exit; FFriends.Add((AFriend as TRealICQUser).LoginName); TUsersService.GetUsersService.UpdateOrAddFriend(AFriend as TRealICQUser); end; procedure TFriendsService.AddFriends(AFriends: TStrings); var iLoop: Integer; begin for iLoop := 0 to AFriends.Count - 1 do if FFriends.IndexOf(AFriends[iLoop]) < 0 then FFriends.Add(AFriends[iLoop]); end; constructor TFriendsService.Create; begin FFriends := TStringList.Create; Inherited; end; class function TFriendsService.GetService: TFriendsService; begin if AFriendsService = nil then AFriendsService := TFriendsService.Create; Result := AFriendsService; end; procedure TFriendsService.HandeFriendsState(AJo: ISuperObject); var iLoop: Integer; joUser: ISuperObject; ja: TSuperArray; AServerid: string; // AKeyValues: TKeyValues; AUser: TRealICQUser; AUSers: TStringList; // ATreeView: TRealICQContacterTreeView; begin ja := AJo.A['us']; AServerid := AJo.S['s']; AUsers := TStringList.Create; for iLoop := 0 to ja.Length - 1 do begin joUser := ja[iLoop]; if joUser.S['l'] = '' then Continue; joUser.S['l'] := TUsersService.FullLoginName(MainForm.RealICQClient.CenterServerID, AServerid, joUser.S['l']); AUser := TUsersService.GetUsersService.GetUser(joUser.S['l']); if AUser = nil then Continue; AUser.LoginState := TRealICQLoginState(joUser.I['os']); AUsers.AddObject(AUser.LoginName, AUser); end; if AUsers.Count = 0 then Exit; try TUsersService.GetUsersService.UpdateUserStateToTreeView(AUsers, GetTreeView(LvFriends)); finally FreeAndNil(AUsers); end; end; end.