Skip to content

Commit

Permalink
CollectUsersChats update user/chat fields from min info
Browse files Browse the repository at this point in the history
  • Loading branch information
wiz0u committed Mar 13, 2024
1 parent d00725e commit 659906c
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 4 deletions.
8 changes: 5 additions & 3 deletions src/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1079,6 +1079,7 @@ public async Task<User> LoginUserIfNeeded(CodeSettings settings = null, bool rel
self.phone == string.Concat((phone_number = Config("phone_number")).Where(char.IsDigit)))
{
_session.UserId = _dcSession.UserId = self.id;
RaiseUpdate(self);
return User = self;
}
var mismatch = $"Current logged user {self.id} mismatched user_id or phone_number";
Expand Down Expand Up @@ -1242,11 +1243,12 @@ public async Task<User> LoginUserIfNeeded(CodeSettings settings = null, bool rel
[EditorBrowsable(EditorBrowsableState.Never)]
public User LoginAlreadyDone(Auth_AuthorizationBase authorization)
{
if (authorization is not Auth_Authorization { user: User user })
if (authorization is not Auth_Authorization { user: User self })
throw new WTException("Failed to get Authorization: " + authorization.GetType().Name);
_session.UserId = _dcSession.UserId = user.id;
_session.UserId = _dcSession.UserId = self.id;
lock (_session) _session.Save();
return User = user;
RaiseUpdate(self);
return User = self;
}

private MsgsAck CheckMsgsToAck()
Expand Down
40 changes: 39 additions & 1 deletion src/TL.Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,51 @@ protected internal override IPeerInfo UserOrChat(Dictionary<long, User> users, D
if (user != null)
if (!user.flags.HasFlag(User.Flags.min) || !_users.TryGetValue(user.id, out var prevUser) || prevUser.flags.HasFlag(User.Flags.min))
_users[user.id] = user;
else
{
const User.Flags good_min_flags = (User.Flags)0x55A2201E;
const User.Flags2 good_min_flags2 = (User.Flags2)0x701;
prevUser.flags = (prevUser.flags & ~good_min_flags) | (user.flags & good_min_flags);
prevUser.flags2 = (prevUser.flags2 & ~good_min_flags2) | (user.flags2 & good_min_flags2);
prevUser.first_name = user.first_name;
prevUser.last_name = user.last_name;
prevUser.username = user.username;
prevUser.phone = user.phone;
if (prevUser.flags.HasFlag(User.Flags.apply_min_photo) && user.phone != null)
{
prevUser.photo = user.photo;
prevUser.flags |= User.Flags.has_photo;
}
prevUser.emoji_status = user.emoji_status;
prevUser.usernames = user.usernames;
prevUser.color = user.color;
prevUser.profile_color = user.profile_color;
_users[user.id] = prevUser;
}
if (_chats != null)
lock (_chats)
foreach (var kvp in chats)
if (kvp.Value is not Channel channel)
_chats[kvp.Key] = kvp.Value;
else if (!channel.flags.HasFlag(Channel.Flags.min) || !_chats.TryGetValue(channel.id, out var prevChat) || prevChat is not Channel prevChannel || prevChannel.flags.HasFlag(Channel.Flags.min))
else if (!channel.flags.HasFlag(Channel.Flags.min) || !_chats.TryGetValue(kvp.Key, out var prevChat) || prevChat is not Channel prevChannel || prevChannel.flags.HasFlag(Channel.Flags.min))
_chats[kvp.Key] = channel;
else
{
const Channel.Flags good_min_flags = (Channel.Flags)0x7FDC09E0;
const Channel.Flags2 good_min_flags2 = (Channel.Flags2)0x781;
prevChannel.flags = (prevChannel.flags & ~good_min_flags) | (channel.flags & good_min_flags);
prevChannel.flags2 = (prevChannel.flags2 & ~good_min_flags2) | (channel.flags2 & good_min_flags2);
prevChannel.title = channel.title;
prevChannel.username = channel.username;
prevChannel.photo = channel.photo;
prevChannel.default_banned_rights = channel.default_banned_rights;
prevChannel.usernames = channel.usernames;
prevChannel.color = channel.color;
prevChannel.profile_color = channel.profile_color;
prevChannel.emoji_status = channel.emoji_status;
prevChannel.level = channel.level;
_chats[kvp.Key] = prevChannel;
}
return null;
}
}
Expand Down

0 comments on commit 659906c

Please sign in to comment.