unit WorkmatesService; interface uses StrUtils, SysUtils, Windows, superobject, Classes, BaseService, RealICQModel; type TWorkmatesService = class(TBaseService) private FWorkmates: TStringList; FWorkmatesNeedUpdate: TStringList; public procedure HandleUsersStatus(AJo: ISuperObject); function GetWorkmates: TStringList; function GetWorkmate(ALoginName: string): TRealICQUser; procedure Init; procedure Uninstall; function IsWorkmate(ALoginName: string): Boolean; procedure AddWorkmates(AWorkmates: TStrings); constructor Create; destructor Destroy; override; class function GetService: TWorkmatesService; static; procedure RequestUserStatus; procedure RequstUserInfos; property WorkmatesNeedUpdate: TStringList read FWorkmatesNeedUpdate write FWorkmatesNeedUpdate; end; implementation uses UsersService, AsynRequestUserStatus, AsynRequestUserInfo, MainFrm, LoggerImport; var AWorkmatesService: TWorkmatesService; function WorkmatesSort(List: TStringList; Index1, Index2: Integer): Integer; var AUser1, AUser2: TRealICQUser; begin AUser1 := List.Objects[Index1] as TRealICQUser; AUser2 := List.Objects[Index2] as TRealICQUser; if AUser1.Position < AUser2.Position then Result := -1 else if AUser1.Position = AUser2.Position then Result := 0 else Result := 1; end; { TWorkmatesService } procedure TWorkmatesService.AddWorkmates(AWorkmates: TStrings); var iLoop, jLoop: Integer; ABranchIDs: TStrings; TmpUsers1, TmpUsers2: TStringList; AUser: TRealICQUser; begin // ABranchIDs := TStringList.Create; // TmpUsers1 := TStringList.Create; // TmpUsers2 := TStringList.Create; // for iLoop := 0 to AWorkmates.Count - 1 do // begin // AUser := AWorkmates.Objects[iLoop] As TRealICQUser; // if ABranchIDs.IndexOf(AUser.BranchID) < 0 then // ABranchIDs.Add(AUser.BranchID); // end; // // for iLoop := 0 to ABranchIDs.Count - 1 do // begin // for jLoop := 0 to AWorkmates.Count - 1 do // begin // AWorkmates. // AUser := AWorkmates.Objects[iLoop] As TRealICQUser; // if AUser then // // end; // end; FWorkmates.AddStrings(AWorkmates); // FWorkmates.CustomSort(WorkmatesSort); // for iLoop := 0 to FWorkmates.Count - 1 do // begin // AUser := FWorkmates.Objects[iLoop] As TRealICQUser; // Debug(AUser.LoginName + ';' + FloatToStr(AUser.Position), 'WorkmatesSort'); // end; end; constructor TWorkmatesService.Create; begin FWorkmates := TStringList.Create; FWorkmates.Duplicates := dupIgnore; FWorkmatesNeedUpdate := TStringList.Create; FWorkmatesNeedUpdate.Duplicates := dupIgnore; end; destructor TWorkmatesService.Destroy; begin FreeAndNil(FWorkmates); FreeAndNil(FWorkmatesNeedUpdate); inherited; end; class function TWorkmatesService.GetService: TWorkmatesService; begin if AWorkmatesService = nil then AWorkmatesService := TWorkmatesService.Create; Result := AWorkmatesService; end; function TWorkmatesService.GetWorkmate(ALoginName: string): TRealICQUser; var iIndex: Integer; begin iIndex := FWorkmates.Indexof(ALoginName); if iIndex > -1 then Result := FWorkmates.Objects[iIndex] as TRealICQUser else Result := nil; end; function TWorkmatesService.GetWorkmates: TStringList; var tmpList: TStringList; begin Result := TStringList.Create; Result.AddStrings(FWorkmates); // try // Result := TUsersService.GetUsersService.GetOrCreateUsers(tmpList); // finally // FreeAndNil(tmpList); // end; end; procedure TWorkmatesService.HandleUsersStatus(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 := GetWorkmate(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(LVMyContacters)); finally FreeAndNil(AUsers); end; end; procedure TWorkmatesService.Init; begin end; function TWorkmatesService.IsWorkmate(ALoginName: string): Boolean; begin Result := FWorkmates.IndexOf(ALoginName) >= 0; end; procedure TWorkmatesService.RequestUserStatus; var AsynAction: TAsynRequestUserStatus; begin AsynAction := TAsynRequestUserStatus.Create(True); AsynAction.Protocol := WORKMATES_USERSTATE_PROLOCOL; AsynAction.Users := TStringList.Create; AsynAction.Users.AddStrings(FWorkmates); AsynAction.Resume; end; procedure TWorkmatesService.RequstUserInfos; var AsynAction: TAsynRequestUserInfo; begin if FWorkmatesNeedUpdate.Count = 0 then Exit; TUsersService.GetUsersService.RequestWorkmatesInfos(FWorkmatesNeedUpdate); // AsynAction := TAsynRequestUserInfo.Create; // AsynAction.Users.AddStrings(FWorkmatesNeedUpdate); FWorkmatesNeedUpdate.Clear; // AsynAction.Resume; end; procedure TWorkmatesService.Uninstall; begin FWorkmatesNeedUpdate.Clear; FWorkmates.Clear; end; end.