|
|
@@ -4,9 +4,10 @@ interface
|
|
|
|
|
|
uses
|
|
|
superobject, GroupUtility, WebSocket2, WebSocketClient, Classes, Graphics,
|
|
|
- blcksock, SysUtils, DateUtils, GroupConfig, GroupProtocols, synautil,RealICQModel;
|
|
|
+ blcksock, SysUtils, DateUtils, GroupConfig, GroupProtocols, synautil,
|
|
|
+ RealICQModel;
|
|
|
|
|
|
-type
|
|
|
+type
|
|
|
TGroupClient = class
|
|
|
private
|
|
|
FClient: TTestWebSocketClientConnection;
|
|
|
@@ -15,7 +16,6 @@ type
|
|
|
FConnected: Boolean;
|
|
|
FGroupMonitor: TObject;
|
|
|
FLastRecvMsg: ISuperObject;
|
|
|
-
|
|
|
procedure GetMyGroups;
|
|
|
procedure OnOpen(aSender: TWebSocketCustomConnection);
|
|
|
procedure OnRead(aSender: TWebSocketCustomConnection; aFinal, aRes1, aRes2, aRes3: boolean; aCode: integer; aData: TMemoryStream);
|
|
|
@@ -23,7 +23,6 @@ type
|
|
|
public
|
|
|
constructor Create();
|
|
|
destructor Destroy; override;
|
|
|
-
|
|
|
procedure Send(AData: string); overload;
|
|
|
procedure Send(AProtocol: string; AData: ISuperObject); overload;
|
|
|
procedure Ping;
|
|
|
@@ -37,7 +36,7 @@ type
|
|
|
procedure SearchTeam(ATeamID, AName, AIntro, ANotice: string; AMatchingType: TRealICQMatchingType; ASkip: Integer = 0; ALimit: Integer = 20);
|
|
|
procedure AsynTeam(ATeamID: string);
|
|
|
procedure GetHistoryMessageCount(ATeamID: string);
|
|
|
- procedure GetHistoryMessages(ATeamID: string; ts: Cardinal);
|
|
|
+ procedure GetHistoryMessages(ATeamID: string; ts: Int64);
|
|
|
procedure ChangeActiveDevice;
|
|
|
|
|
|
{ TODO -olqq -c : 群成员操作 2015/6/2 10:03:30 }
|
|
|
@@ -45,18 +44,17 @@ type
|
|
|
procedure RemoveTeamMembers(ATeamID: string; AMembersID, AManagersID: TStringList);
|
|
|
procedure SetAlias(ATeamID, AMemberID, Alias: string);
|
|
|
function GetAlias(ATeamID, AMemberID: string): string;
|
|
|
- procedure InviteJoin(ATeamID,AOperatorID,AOperatorMsg: string;AMembers: TStringList);
|
|
|
+ procedure InviteJoin(ATeamID, AOperatorID, AOperatorMsg: string; AMembers: TStringList);
|
|
|
procedure JoinTeam(ATeamID, AMsg: string);
|
|
|
procedure JoinTeamResponse(ATeamID, ALoginName, ATag: string; Accepted: Boolean);
|
|
|
{ TODO -olqq -c : 群消息 2015/6/2 10:11:20 }
|
|
|
- procedure SendTeamMessage(ATeamID, ASender, AMsg: string; AFont: TFont; AFaces: TStringList; Attachs: String);
|
|
|
+ procedure SendTeamMessage(ATeamID, ASender, AMsg: string; AFont: TFont; AFaces: TStringList; Attachs: string);
|
|
|
procedure GetOffineMessage;
|
|
|
procedure MessageMisc(ATeamID: string);
|
|
|
procedure MessageMiscMust(ATeamID: string);
|
|
|
{ TODO -olqq -c : 群图片 2015/6/3 9:39:26 }
|
|
|
function UploadFile(Hash, FileName, ID, GroupID: string): Boolean;
|
|
|
procedure SendFilesRequest(AGroupId, AUserId, FileName: string);
|
|
|
-
|
|
|
property Connected: Boolean read FConnected write FConnected;
|
|
|
end;
|
|
|
|
|
|
@@ -73,10 +71,9 @@ const
|
|
|
|
|
|
{ TGroupClient }
|
|
|
|
|
|
-procedure TGroupClient.CreateTeam(ATeamName, ATeamCallBoard, ATeamIntro: String;
|
|
|
- ATeamMembers: TStringList; AIsTempTeam: Boolean);
|
|
|
+procedure TGroupClient.CreateTeam(ATeamName, ATeamCallBoard, ATeamIntro: string; ATeamMembers: TStringList; AIsTempTeam: Boolean);
|
|
|
var
|
|
|
- createGroup:String;
|
|
|
+ createGroup: string;
|
|
|
jo, AData: ISuperObject;
|
|
|
AMemebers: TSuperArray;
|
|
|
iLoop: Integer;
|
|
|
@@ -91,11 +88,11 @@ begin
|
|
|
AMemebers := jo.A['group.members'];
|
|
|
for iLoop := 0 to ATeamMembers.Count - 1 do
|
|
|
AMemebers.S[iloop] := ATeamMembers[iLoop];
|
|
|
-
|
|
|
+
|
|
|
Send(GROUP_CREATE_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.RemoveTeam(ATeamID: String);
|
|
|
+procedure TGroupClient.RemoveTeam(ATeamID: string);
|
|
|
var
|
|
|
jo: ISuperObject;
|
|
|
begin
|
|
|
@@ -104,8 +101,7 @@ begin
|
|
|
Send(GROUP_DEL_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.UpdateTeamInfo(ATeamID, AIntro, ANotice, AName: string;
|
|
|
- AAuth: Integer);
|
|
|
+procedure TGroupClient.UpdateTeamInfo(ATeamID, AIntro, ANotice, AName: string; AAuth: Integer);
|
|
|
var
|
|
|
jo: ISuperObject;
|
|
|
begin
|
|
|
@@ -118,7 +114,7 @@ begin
|
|
|
Send(GROUP_UPDATE_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.AsynTeam(ATeamID: String);
|
|
|
+procedure TGroupClient.AsynTeam(ATeamID: string);
|
|
|
var
|
|
|
jo: ISuperObject;
|
|
|
begin
|
|
|
@@ -128,11 +124,10 @@ begin
|
|
|
Send(GROUP_GET_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.SearchTeam(ATeamID, AName, AIntro, ANotice: string;
|
|
|
- AMatchingType: TRealICQMatchingType; ASkip: Integer = 0; ALimit: Integer = 20);
|
|
|
+procedure TGroupClient.SearchTeam(ATeamID, AName, AIntro, ANotice: string; AMatchingType: TRealICQMatchingType; ASkip: Integer = 0; ALimit: Integer = 20);
|
|
|
var
|
|
|
jo: ISuperObject;
|
|
|
- SearchGroup: String;
|
|
|
+ SearchGroup: string;
|
|
|
begin
|
|
|
jo := SO('{"id":"","group":{"id":"","intro":"","name":"","notice":""},"skip":0,"limit":0}');
|
|
|
|
|
|
@@ -163,12 +158,11 @@ begin
|
|
|
Send(GROUP_QUERY_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.AddTeamMembers(ATeamID: string; AMembersID,
|
|
|
- AManagersID: TStringList);
|
|
|
+procedure TGroupClient.AddTeamMembers(ATeamID: string; AMembersID, AManagersID: TStringList);
|
|
|
var
|
|
|
- jo :ISuperObject;
|
|
|
- ja,ja1: TSuperArray;
|
|
|
- iLoop : Integer;
|
|
|
+ jo: ISuperObject;
|
|
|
+ ja, ja1: TSuperArray;
|
|
|
+ iLoop: Integer;
|
|
|
begin
|
|
|
jo := SO('{"id":"", "group":{"id":"","members":[],"managers": []}}');
|
|
|
jo.S['group.id'] := ATeamID;
|
|
|
@@ -185,12 +179,11 @@ begin
|
|
|
Send(MEMBER_ADD_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.RemoveTeamMembers(ATeamID: string; AMembersID,
|
|
|
- AManagersID: TStringList);
|
|
|
+procedure TGroupClient.RemoveTeamMembers(ATeamID: string; AMembersID, AManagersID: TStringList);
|
|
|
var
|
|
|
- jo :ISuperObject;
|
|
|
- ja,ja1: TSuperArray;
|
|
|
- iLoop : Integer;
|
|
|
+ jo: ISuperObject;
|
|
|
+ ja, ja1: TSuperArray;
|
|
|
+ iLoop: Integer;
|
|
|
begin
|
|
|
jo := SO('{"id":"", "group":{"id":"","members":[],"managers": []}}');
|
|
|
jo.S['group.id'] := ATeamID;
|
|
|
@@ -214,31 +207,30 @@ end;
|
|
|
|
|
|
procedure TGroupClient.SetAlias(ATeamID, AMemberID, Alias: string);
|
|
|
var
|
|
|
- jo,jo1: ISuperObject;
|
|
|
+ jo, jo1: ISuperObject;
|
|
|
ja: TSuperArray;
|
|
|
begin
|
|
|
jo := SO('{"id":"","group":{"id":"","members":[]}}');
|
|
|
- jo1:= SO('{"id":"","alias":""}');
|
|
|
- jo.S['group.id']:= ATeamID;
|
|
|
- jo1.S['id'] := AMemberID;
|
|
|
- jo1.S['alias'] := Alias;
|
|
|
+ jo1 := SO('{"id":"","alias":""}');
|
|
|
+ jo.S['group.id'] := ATeamID;
|
|
|
+ jo1.S['id'] := AMemberID;
|
|
|
+ jo1.S['alias'] := Alias;
|
|
|
ja := jo.A['group.members'];
|
|
|
ja.Add(jo1);
|
|
|
|
|
|
Send(MEMBER_UPDATE_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.InviteJoin(ATeamID, AOperatorID, AOperatorMsg: string;
|
|
|
- AMembers: TStringList);
|
|
|
+procedure TGroupClient.InviteJoin(ATeamID, AOperatorID, AOperatorMsg: string; AMembers: TStringList);
|
|
|
var
|
|
|
jo: ISuperObject;
|
|
|
ja: TSuperArray;
|
|
|
- ILoop : Integer;
|
|
|
+ ILoop: Integer;
|
|
|
begin
|
|
|
jo := SO('{"id":"","group":{"id":"","members":[], "operator":{"id":"","msg":""}}}');
|
|
|
- jo.S['group.id']:= ATeamID;
|
|
|
- jo.S['group.operator.id']:= AOperatorID;
|
|
|
- jo.S['group.operator.msg']:= AOperatorMsg;
|
|
|
+ jo.S['group.id'] := ATeamID;
|
|
|
+ jo.S['group.operator.id'] := AOperatorID;
|
|
|
+ jo.S['group.operator.msg'] := AOperatorMsg;
|
|
|
ja := jo.A['group.members'];
|
|
|
for iLoop := 0 to AMembers.Count - 1 do
|
|
|
ja.S[iloop] := AMembers[iLoop];
|
|
|
@@ -251,7 +243,7 @@ var
|
|
|
jo: ISuperObject;
|
|
|
begin
|
|
|
jo := SO('{"group":{"id":"","apply":{"uid":"","msg":""}}}');
|
|
|
- jo.S['group.id'] := ATeamID;
|
|
|
+ jo.S['group.id'] := ATeamID;
|
|
|
jo.S['group.apply.msg'] := AMsg;
|
|
|
jo.S['group.apply.uid'] := FLoginName;
|
|
|
Send(MEMBER_APPLY_REQUEST, jo);
|
|
|
@@ -262,11 +254,11 @@ var
|
|
|
jo: ISuperObject;
|
|
|
begin
|
|
|
jo := SO('{"id":"","group":{"id":"","apply":{"uid":""},"reply":{"uid":"", "ret":0}}}');
|
|
|
- jo.S['group.id'] := ATeamID;
|
|
|
+ jo.S['group.id'] := ATeamID;
|
|
|
jo.S['group.apply.uid'] := ALoginName;
|
|
|
jo.S['group.reply.uid'] := FLoginName;
|
|
|
jo.S['group.reply.msg'] := ATag;
|
|
|
- if Accepted then
|
|
|
+ if Accepted then
|
|
|
jo.I['group.reply.ret'] := 1
|
|
|
else
|
|
|
jo.I['group.reply.ret'] := 0;
|
|
|
@@ -274,13 +266,12 @@ begin
|
|
|
Send(MEMBER_REPLY_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.SendTeamMessage(ATeamID, ASender, AMsg: String;
|
|
|
- AFont: TFont; AFaces: TStringList; Attachs: String);
|
|
|
+procedure TGroupClient.SendTeamMessage(ATeamID, ASender, AMsg: string; AFont: TFont; AFaces: TStringList; Attachs: string);
|
|
|
var
|
|
|
jo, jofile, joNotify, joFont: ISuperObject;
|
|
|
ja, jaHashs: TSuperArray;
|
|
|
- iLoop : Integer;
|
|
|
- sendstr: String;
|
|
|
+ iLoop: Integer;
|
|
|
+ sendstr: string;
|
|
|
AFace: TFace;
|
|
|
IMG_TAG, ATT_TAG: string;
|
|
|
begin
|
|
|
@@ -308,7 +299,7 @@ begin
|
|
|
joFont := FontToJson(AFont);
|
|
|
if joFont <> nil then
|
|
|
jo.O['style'] := joFont;
|
|
|
-
|
|
|
+
|
|
|
if Attachs <> '' then
|
|
|
begin
|
|
|
jo.A['attach'].S[0] := Attachs;
|
|
|
@@ -341,7 +332,8 @@ begin
|
|
|
MessageMisc(ATeamID);
|
|
|
{$ELSE}
|
|
|
ChangeActiveDevice;
|
|
|
- {$ENDIF}
|
|
|
+ MessageMisc(ATeamID);
|
|
|
+ {$ENDIF}
|
|
|
end;
|
|
|
|
|
|
procedure TGroupClient.MessageMisc(ATeamID: string);
|
|
|
@@ -374,7 +366,7 @@ begin
|
|
|
Result := '';
|
|
|
AStream := TStringStream.Create(AResponseStr);
|
|
|
try
|
|
|
- AStream.Position :=1;
|
|
|
+ AStream.Position := 1;
|
|
|
Len := 0;
|
|
|
AStream.Read(ACode, 1);
|
|
|
while ACode <> $FF do
|
|
|
@@ -422,8 +414,8 @@ end;
|
|
|
|
|
|
function TGroupClient.Connect(ALoginName: string = ''): Boolean;
|
|
|
var
|
|
|
- AIdHttp:TIdHTTP;
|
|
|
- ResponeStr,sid: string;
|
|
|
+ AIdHttp: TIdHTTP;
|
|
|
+ ResponeStr, sid: string;
|
|
|
config: TGroupConfig;
|
|
|
AURL: string;
|
|
|
begin
|
|
|
@@ -431,13 +423,13 @@ begin
|
|
|
FLoginName := ALoginName;
|
|
|
if Trim(FLoginName) = '' then
|
|
|
Exit;
|
|
|
-
|
|
|
- AIdHttp:= TIdHTTP.Create(nil);
|
|
|
+
|
|
|
+ AIdHttp := TIdHTTP.Create(nil);
|
|
|
try
|
|
|
config := TGroupConfig.GetConfig;
|
|
|
|
|
|
if config.GatewayEnable then
|
|
|
- begin
|
|
|
+ begin
|
|
|
config.RandomGatewayServer;
|
|
|
AURL := Format(GATEWAY_URL, [config.GatewayIP, config.GatewayPort]);
|
|
|
ResponeStr := AIdHttp.Get(AURL);
|
|
|
@@ -446,11 +438,11 @@ begin
|
|
|
Exit;
|
|
|
end;
|
|
|
SUCCESS(Format('%s:%d', [config.IP, config.Port]), '群组服务地址');
|
|
|
- AURL := Format(SHAKEHANDS_STEP1, [config.IP, config.Port, HTTPEncode(AnsiToUtf8(FLoginName)), (DateTimeToUnix(Now) - 8*60*60) * 1000]);
|
|
|
+ AURL := Format(SHAKEHANDS_STEP1, [config.IP, config.Port, HTTPEncode(AnsiToUtf8(FLoginName)), (DateTimeToUnix(Now) - 8 * 60 * 60) * 1000]);
|
|
|
ResponeStr := AIdHttp.get(AURL);
|
|
|
ResponeStr := GetSID(ResponeStr);
|
|
|
- sid := SO(ResponeStr).S['sid'];
|
|
|
- AURL := Format(SHAKEHANDS_STEP2, [config.IP, config.Port, HTTPEncode(AnsiToUtf8(FLoginName)), (DateTimeToUnix(Now) - 8*60*60) * 1000, sid]);
|
|
|
+ sid := SO(ResponeStr).S['sid'];
|
|
|
+ AURL := Format(SHAKEHANDS_STEP2, [config.IP, config.Port, HTTPEncode(AnsiToUtf8(FLoginName)), (DateTimeToUnix(Now) - 8 * 60 * 60) * 1000, sid]);
|
|
|
ResponeStr := AIdHttp.get(AURL);
|
|
|
if FClient <> nil then
|
|
|
FreeAndNil(FClient);
|
|
|
@@ -471,25 +463,25 @@ begin
|
|
|
Freeandnil(AIdHttp);
|
|
|
end;
|
|
|
|
|
|
-function TGroupClient.UploadFile(Hash, FileName, ID, GroupID: String): Boolean;
|
|
|
+function TGroupClient.UploadFile(Hash, FileName, ID, GroupID: string): Boolean;
|
|
|
var
|
|
|
AHttp: TIdHttp;
|
|
|
MutPartForm: TIdMultiPartFormDataStream;
|
|
|
- Ret:TStringStream;
|
|
|
- response,UpUrl: String;
|
|
|
- jo,t,jofile: ISuperObject;
|
|
|
- SendStr: String;
|
|
|
+ Ret: TStringStream;
|
|
|
+ response, UpUrl: string;
|
|
|
+ jo, t, jofile: ISuperObject;
|
|
|
+ SendStr: string;
|
|
|
config: TGroupConfig;
|
|
|
begin
|
|
|
Result := False;
|
|
|
config := TGroupConfig.GetConfig;
|
|
|
UpUrl := Format(UPLOAD_URL, [config.ImageIP, config.ImagePort]);
|
|
|
AHttp := Tidhttp.Create(nil);
|
|
|
- AHttp.Request.ContentType:='multipart/form-data';
|
|
|
+ AHttp.Request.ContentType := 'multipart/form-data';
|
|
|
AHttp.HandleRedirects := true;
|
|
|
AHttp.AllowCookies := true;
|
|
|
MutPartForm := TIdMultiPartFormDataStream.Create;
|
|
|
- MutPartForm.AddFile('file1', TRealICQClient.GetReceivedFaceDir+FileName,'');
|
|
|
+ MutPartForm.AddFile('file1', TRealICQClient.GetReceivedFaceDir + FileName, '');
|
|
|
|
|
|
try
|
|
|
response := AHttp.Post(UpUrl, MutPartForm);
|
|
|
@@ -514,14 +506,13 @@ var
|
|
|
PInt: PInteger;
|
|
|
begin
|
|
|
FreeAndNil(FGroupMonitor);
|
|
|
- if FClient <> nil then
|
|
|
+ if FClient <> nil then
|
|
|
FreeAndNil(FClient);
|
|
|
FLastRecvMsg := nil;
|
|
|
FProtocol.Free;
|
|
|
inherited;
|
|
|
end;
|
|
|
|
|
|
-
|
|
|
procedure TGroupClient.Disconnect;
|
|
|
begin
|
|
|
(FGroupMonitor as TGroupMonitor).Stop;
|
|
|
@@ -552,7 +543,8 @@ end;
|
|
|
skip: <Number>, // *偏移
|
|
|
limit: <Number> // *限制
|
|
|
}
|
|
|
-procedure TGroupClient.GetHistoryMessages(ATeamID: string; ts: Cardinal);
|
|
|
+
|
|
|
+procedure TGroupClient.GetHistoryMessages(ATeamID: string; ts: Int64);
|
|
|
var
|
|
|
jo, joFilter: ISuperObject;
|
|
|
begin
|
|
|
@@ -563,7 +555,7 @@ begin
|
|
|
joFilter := SO();
|
|
|
|
|
|
joFilter.S['group'] := ATeamID;
|
|
|
- joFilter.S['ts'] := '<'+ IntToStr(ts);
|
|
|
+ joFilter.S['ts'] := '>' + IntToStr(ts);
|
|
|
joFilter.I['limit'] := 10000;
|
|
|
jo.O['filter'] := joFilter;
|
|
|
Send(HISTORY_H_Q, jo);
|
|
|
@@ -588,8 +580,7 @@ begin
|
|
|
// Send(MESSAGE_OFFLINE_REQUEST, jo);
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.OnClose(aSender: TWebSocketCustomConnection;
|
|
|
- aCloseCode: integer; aCloseReason: string; aClosedByPeer: boolean);
|
|
|
+procedure TGroupClient.OnClose(aSender: TWebSocketCustomConnection; aCloseCode: integer; aCloseReason: string; aClosedByPeer: boolean);
|
|
|
begin
|
|
|
FConnected := False;
|
|
|
FClient := nil;
|
|
|
@@ -610,8 +601,7 @@ begin
|
|
|
(FGroupMonitor as TGroupMonitor).KeepAlive := True;
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.OnRead(aSender: TWebSocketCustomConnection; aFinal,
|
|
|
- aRes1, aRes2, aRes3: boolean; aCode: integer; aData: TMemoryStream);
|
|
|
+procedure TGroupClient.OnRead(aSender: TWebSocketCustomConnection; aFinal, aRes1, aRes2, aRes3: boolean; aCode: integer; aData: TMemoryStream);
|
|
|
var
|
|
|
s: UTF8String;
|
|
|
Recvdata: string;
|
|
|
@@ -639,7 +629,7 @@ begin
|
|
|
FProtocol.Proccess(Recvdata);
|
|
|
except
|
|
|
on E: Exception do
|
|
|
- Error(E.Message, 'TGroupClient.OnRead('+Recvdata+')');
|
|
|
+ Error(E.Message, 'TGroupClient.OnRead(' + Recvdata + ')');
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
@@ -668,14 +658,15 @@ begin
|
|
|
except
|
|
|
on E: Exception do
|
|
|
begin
|
|
|
- Error(E.Message, 'TGroupClient.Send('+AData+')');
|
|
|
+ Error(E.Message, 'TGroupClient.Send(' + AData + ')');
|
|
|
end;
|
|
|
end;
|
|
|
end;
|
|
|
|
|
|
-procedure TGroupClient.SendFilesRequest(AGroupId, AUserId, FileName: String);
|
|
|
+procedure TGroupClient.SendFilesRequest(AGroupId, AUserId, FileName: string);
|
|
|
begin
|
|
|
|
|
|
end;
|
|
|
|
|
|
end.
|
|
|
+
|