Merge pull request #178 from woakesd/master

Fix issues with GetDialogs
This commit is contained in:
Ilya Pirozhenko 2016-07-20 10:22:20 +03:00 committed by GitHub
commit f136513ab9
4 changed files with 51 additions and 20 deletions

View file

@ -537,6 +537,9 @@ namespace TLSharp.Core.MTProto
{0x427425e7, typeof (AudioConstructor)},
{0x36f8c871, typeof (DocumentEmptyConstructor)},
{0xf9a39f4f, typeof (DocumentConstructor)},
{0xab3a99ac, typeof (DialogConstructor)},
{0xd9ccc4ef, typeof (UserRequestConstructor)},
{0x075cf7a8, typeof (UserForeignConstructor)},
};
public static TLObject Parse(BinaryReader reader, uint code)
@ -1035,9 +1038,9 @@ namespace TLSharp.Core.MTProto
return new MessageActionChatDeleteUserConstructor(user_id);
}
public static Dialog dialog(Peer peer, int top_message, int unread_count)
public static Dialog dialog(Peer peer, int top_message, int unread_count, PeerNotifySettings peerNotifySettings)
{
return new DialogConstructor(peer, top_message, unread_count);
return new DialogConstructor(peer, top_message, unread_count, peerNotifySettings);
}
public static Photo photoEmpty(long id)
@ -5957,23 +5960,33 @@ namespace TLSharp.Core.MTProto
}
}
public class MessageDialogs
{
public int? Count { get; set; }
public List<Dialog> Dialogs { get; set; }
public List<Message> Messages { get; set; }
public List<Chat> Chats { get; set; }
public List<User> Users { get; set; }
}
public class DialogConstructor : Dialog
{
public Peer peer;
public int top_message;
public int unread_count;
public PeerNotifySettings peerNotifySettings;
public DialogConstructor()
{
}
public DialogConstructor(Peer peer, int top_message, int unread_count)
public DialogConstructor(Peer peer, int top_message, int unread_count, PeerNotifySettings peerNotifySettings)
{
this.peer = peer;
this.top_message = top_message;
this.unread_count = unread_count;
this.peerNotifySettings = peerNotifySettings;
}
@ -5984,10 +5997,11 @@ namespace TLSharp.Core.MTProto
public override void Write(BinaryWriter writer)
{
writer.Write(0x214a8cdf);
writer.Write(0xab3a99ac);
this.peer.Write(writer);
writer.Write(this.top_message);
writer.Write(this.unread_count);
this.peerNotifySettings.Write(writer);
}
public override void Read(BinaryReader reader)
@ -5995,6 +6009,7 @@ namespace TLSharp.Core.MTProto
this.peer = TL.Parse<Peer>(reader);
this.top_message = reader.ReadInt32();
this.unread_count = reader.ReadInt32();
this.peerNotifySettings = TL.Parse<PeerNotifySettings>(reader);
}
public override string ToString()

View file

@ -295,11 +295,18 @@ namespace TLSharp.Core.Network
{
// gzip_packed
byte[] packedData = Serializers.Bytes.read(messageReader);
using (var packedStream = new MemoryStream(packedData, false))
using (var zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
using (var compressedReader = new BinaryReader(zipStream))
using (var ms = new MemoryStream())
{
request.OnResponse(compressedReader);
using (var packedStream = new MemoryStream(packedData, false))
using (var zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
{
zipStream.CopyTo(ms);
ms.Position = 0;
}
using (var compressedReader = new BinaryReader(ms))
{
request.OnResponse(compressedReader);
}
}
}
catch (ZlibException ex)

View file

@ -11,6 +11,7 @@ namespace TLSharp.Core.Requests
int _max_id;
int _limit;
public int count;
public List<Dialog> dialogs;
public List<Message> messages;
public List<Chat> chats;
@ -35,7 +36,7 @@ namespace TLSharp.Core.Requests
{
bool dialogsSlice = reader.ReadUInt32() == 0x71e094f3; // else dialogs#15ba6c40
if (dialogsSlice) reader.ReadInt32(); // count
if (dialogsSlice) count = reader.ReadInt32(); // count
// dialogs
var result = reader.ReadUInt32(); // vector#1cb5c415
@ -48,7 +49,7 @@ namespace TLSharp.Core.Requests
dialogs.Add(dialog_element);
}
// messages
var count = reader.ReadInt32();
result = reader.ReadUInt32(); // vector#1cb5c415
int messages_len = reader.ReadInt32();
messages = new List<Message>(messages_len);
for (int message_index = 0; message_index < messages_len; message_index++)
@ -58,7 +59,7 @@ namespace TLSharp.Core.Requests
messages.Add(messages_element);
}
// chats
count = reader.ReadInt32();
result = reader.ReadUInt32(); // vector#1cb5c415
int chats_len = reader.ReadInt32();
chats = new List<Chat>(chats_len);
for (int chat_index = 0; chat_index < chats_len; chat_index++)
@ -68,7 +69,7 @@ namespace TLSharp.Core.Requests
chats.Add(chats_element);
}
// users
count = reader.ReadInt32();
result = reader.ReadUInt32(); // vector#1cb5c415
int users_len = reader.ReadInt32();
users = new List<User>(users_len);
for (int users_index = 0; users_index < users_len; users_index++)

View file

@ -23,6 +23,8 @@ namespace TLSharp.Core
private Session _session;
private List<DcOption> dcOptions;
public enum sms_type { numeric_code_via_sms = 0, numeric_code_via_telegram = 5 }
public TelegramClient(ISessionStore store, string sessionUserId, int apiId, string apiHash)
{
_apiHash = apiHash;
@ -92,7 +94,7 @@ namespace TLSharp.Core
return authCheckPhoneRequest._phoneRegistered;
}
public async Task<string> SendCodeRequest(string phoneNumber)
public async Task<string> SendCodeRequest(string phoneNumber, sms_type tokenDestination = sms_type.numeric_code_via_telegram)
{
var completed = false;
@ -100,7 +102,7 @@ namespace TLSharp.Core
while (!completed)
{
request = new AuthSendCodeRequest(phoneNumber, 5, _apiId, _apiHash, "en");
request = new AuthSendCodeRequest(phoneNumber, (int)tokenDestination, _apiId, _apiHash, "en");
try
{
@ -239,8 +241,8 @@ namespace TLSharp.Core
await _sender.Recieve(request);
return request.messages;
}
}
public async Task<Tuple<storage_FileType, byte[]>> GetFile(long volume_id, int local_id, long secret, int offset, int limit)
{
var request = new GetFileRequest(new InputFileLocationConstructor(volume_id, local_id, secret), offset, limit);
@ -248,15 +250,21 @@ namespace TLSharp.Core
await _sender.Recieve(request);
return Tuple.Create(request.type, request.bytes);
}
public async Task<List<Dialog>> GetDialogs(int offset, int limit, int max_id = -1)
}
public async Task<MessageDialogs> GetDialogs(int offset, int limit, int max_id = 0)
{
var request = new GetDialogsRequest(offset, max_id, limit);
await _sender.Send(request);
await _sender.Recieve(request);
return request.dialogs;
return new MessageDialogs
{
Dialogs = request.dialogs,
Messages = request.messages,
Chats = request.chats,
Users = request.users,
};
}
public async Task<UserFull> GetUserFull(int user_id)