mirror of
https://github.com/sochix/TLSharp.git
synced 2025-12-06 08:02:00 +01:00
Fix issues with GetDialogs
Default value of max_id = 0 returns all dialogs Should return a class with lists of dialog, messages, chats and users. Add UserForeignConstructor to list of constructors Add missing detail to DialogConstructor (PeerNotifySettings) Unpack datastream completely to avoid issue with Ionic exception causing problems in userForeign parsing Use more recent code for Dialog construction
This commit is contained in:
parent
b869a4f617
commit
8026bd79dc
|
|
@ -537,6 +537,9 @@ namespace TLSharp.Core.MTProto
|
||||||
{0x427425e7, typeof (AudioConstructor)},
|
{0x427425e7, typeof (AudioConstructor)},
|
||||||
{0x36f8c871, typeof (DocumentEmptyConstructor)},
|
{0x36f8c871, typeof (DocumentEmptyConstructor)},
|
||||||
{0xf9a39f4f, typeof (DocumentConstructor)},
|
{0xf9a39f4f, typeof (DocumentConstructor)},
|
||||||
|
{0xab3a99ac, typeof (DialogConstructor)},
|
||||||
|
{0xd9ccc4ef, typeof (UserRequestConstructor)},
|
||||||
|
{0x075cf7a8, typeof (UserForeignConstructor)},
|
||||||
};
|
};
|
||||||
|
|
||||||
public static TLObject Parse(BinaryReader reader, uint code)
|
public static TLObject Parse(BinaryReader reader, uint code)
|
||||||
|
|
@ -1035,9 +1038,9 @@ namespace TLSharp.Core.MTProto
|
||||||
return new MessageActionChatDeleteUserConstructor(user_id);
|
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)
|
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 class DialogConstructor : Dialog
|
||||||
{
|
{
|
||||||
public Peer peer;
|
public Peer peer;
|
||||||
public int top_message;
|
public int top_message;
|
||||||
public int unread_count;
|
public int unread_count;
|
||||||
|
public PeerNotifySettings peerNotifySettings;
|
||||||
|
|
||||||
public DialogConstructor()
|
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.peer = peer;
|
||||||
this.top_message = top_message;
|
this.top_message = top_message;
|
||||||
this.unread_count = unread_count;
|
this.unread_count = unread_count;
|
||||||
|
this.peerNotifySettings = peerNotifySettings;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -5984,10 +5997,11 @@ namespace TLSharp.Core.MTProto
|
||||||
|
|
||||||
public override void Write(BinaryWriter writer)
|
public override void Write(BinaryWriter writer)
|
||||||
{
|
{
|
||||||
writer.Write(0x214a8cdf);
|
writer.Write(0xab3a99ac);
|
||||||
this.peer.Write(writer);
|
this.peer.Write(writer);
|
||||||
writer.Write(this.top_message);
|
writer.Write(this.top_message);
|
||||||
writer.Write(this.unread_count);
|
writer.Write(this.unread_count);
|
||||||
|
this.peerNotifySettings.Write(writer);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override void Read(BinaryReader reader)
|
public override void Read(BinaryReader reader)
|
||||||
|
|
@ -5995,6 +6009,7 @@ namespace TLSharp.Core.MTProto
|
||||||
this.peer = TL.Parse<Peer>(reader);
|
this.peer = TL.Parse<Peer>(reader);
|
||||||
this.top_message = reader.ReadInt32();
|
this.top_message = reader.ReadInt32();
|
||||||
this.unread_count = reader.ReadInt32();
|
this.unread_count = reader.ReadInt32();
|
||||||
|
this.peerNotifySettings = TL.Parse<PeerNotifySettings>(reader);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override string ToString()
|
public override string ToString()
|
||||||
|
|
|
||||||
|
|
@ -295,13 +295,20 @@ namespace TLSharp.Core.Network
|
||||||
{
|
{
|
||||||
// gzip_packed
|
// gzip_packed
|
||||||
byte[] packedData = Serializers.Bytes.read(messageReader);
|
byte[] packedData = Serializers.Bytes.read(messageReader);
|
||||||
|
using (var ms = new MemoryStream())
|
||||||
|
{
|
||||||
using (var packedStream = new MemoryStream(packedData, false))
|
using (var packedStream = new MemoryStream(packedData, false))
|
||||||
using (var zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
|
using (var zipStream = new GZipStream(packedStream, CompressionMode.Decompress))
|
||||||
using (var compressedReader = new BinaryReader(zipStream))
|
{
|
||||||
|
zipStream.CopyTo(ms);
|
||||||
|
ms.Position = 0;
|
||||||
|
}
|
||||||
|
using (var compressedReader = new BinaryReader(ms))
|
||||||
{
|
{
|
||||||
request.OnResponse(compressedReader);
|
request.OnResponse(compressedReader);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
catch (ZlibException ex)
|
catch (ZlibException ex)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -11,6 +11,7 @@ namespace TLSharp.Core.Requests
|
||||||
int _max_id;
|
int _max_id;
|
||||||
int _limit;
|
int _limit;
|
||||||
|
|
||||||
|
public int count;
|
||||||
public List<Dialog> dialogs;
|
public List<Dialog> dialogs;
|
||||||
public List<Message> messages;
|
public List<Message> messages;
|
||||||
public List<Chat> chats;
|
public List<Chat> chats;
|
||||||
|
|
@ -35,7 +36,7 @@ namespace TLSharp.Core.Requests
|
||||||
{
|
{
|
||||||
bool dialogsSlice = reader.ReadUInt32() == 0x71e094f3; // else dialogs#15ba6c40
|
bool dialogsSlice = reader.ReadUInt32() == 0x71e094f3; // else dialogs#15ba6c40
|
||||||
|
|
||||||
if (dialogsSlice) reader.ReadInt32(); // count
|
if (dialogsSlice) count = reader.ReadInt32(); // count
|
||||||
|
|
||||||
// dialogs
|
// dialogs
|
||||||
var result = reader.ReadUInt32(); // vector#1cb5c415
|
var result = reader.ReadUInt32(); // vector#1cb5c415
|
||||||
|
|
@ -48,7 +49,7 @@ namespace TLSharp.Core.Requests
|
||||||
dialogs.Add(dialog_element);
|
dialogs.Add(dialog_element);
|
||||||
}
|
}
|
||||||
// messages
|
// messages
|
||||||
var count = reader.ReadInt32();
|
result = reader.ReadUInt32(); // vector#1cb5c415
|
||||||
int messages_len = reader.ReadInt32();
|
int messages_len = reader.ReadInt32();
|
||||||
messages = new List<Message>(messages_len);
|
messages = new List<Message>(messages_len);
|
||||||
for (int message_index = 0; message_index < messages_len; message_index++)
|
for (int message_index = 0; message_index < messages_len; message_index++)
|
||||||
|
|
@ -58,7 +59,7 @@ namespace TLSharp.Core.Requests
|
||||||
messages.Add(messages_element);
|
messages.Add(messages_element);
|
||||||
}
|
}
|
||||||
// chats
|
// chats
|
||||||
count = reader.ReadInt32();
|
result = reader.ReadUInt32(); // vector#1cb5c415
|
||||||
int chats_len = reader.ReadInt32();
|
int chats_len = reader.ReadInt32();
|
||||||
chats = new List<Chat>(chats_len);
|
chats = new List<Chat>(chats_len);
|
||||||
for (int chat_index = 0; chat_index < chats_len; chat_index++)
|
for (int chat_index = 0; chat_index < chats_len; chat_index++)
|
||||||
|
|
@ -68,7 +69,7 @@ namespace TLSharp.Core.Requests
|
||||||
chats.Add(chats_element);
|
chats.Add(chats_element);
|
||||||
}
|
}
|
||||||
// users
|
// users
|
||||||
count = reader.ReadInt32();
|
result = reader.ReadUInt32(); // vector#1cb5c415
|
||||||
int users_len = reader.ReadInt32();
|
int users_len = reader.ReadInt32();
|
||||||
users = new List<User>(users_len);
|
users = new List<User>(users_len);
|
||||||
for (int users_index = 0; users_index < users_len; users_index++)
|
for (int users_index = 0; users_index < users_len; users_index++)
|
||||||
|
|
|
||||||
|
|
@ -250,13 +250,19 @@ namespace TLSharp.Core
|
||||||
return Tuple.Create(request.type, request.bytes);
|
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);
|
var request = new GetDialogsRequest(offset, max_id, limit);
|
||||||
await _sender.Send(request);
|
await _sender.Send(request);
|
||||||
await _sender.Recieve(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)
|
public async Task<UserFull> GetUserFull(int user_id)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue