Do not depend on buddy list entries when looking up the ID from the user name, by maintaining a bi-directional mapping ID <-> username. Rename functions to make them more evident as something that operatos on the lookup. Cleanup blist functions by implementating generic iterator function over account buddies.
Do not update blist buddy names, but set an alias instead to prevent breaking conversations or loosing history. Instead, keep the first print name as permanent user name
and set the alias on all buddy name changes. When interacting with purple always use the original buddy name stored in the blist instead of the print name provided by libpurple.
This allows both, meaningful names in group chats and permanent identifiers in the buddy list, while still propagating names changes to the interface.
Use print names instead of ids as usernames, to fix problems with "useless" user ids showing up for unknown users and in group chats. Remove workarounds like "Telegram Foreign" needed to temporarily store user names for alias resolution.
Load full chat info lazily, prevents useless network request and should fix issues with delays through flood errors when handling big amounts of user chats. Handle chat participant deletions and additions correctly and only touch the user list when it is actually updated, this should fix some issues with printing annoying messages in Finch and users not showing up in the buddy list in certain situations. Only add chats to buddy list that are actively joined or receive incoming message, which should help keeping the buddy list more tidy when using much chats.
Instead of using a timer, schedule writes on each new messages. This ensures that there are not too many writes on big updates and still works without a long-running timer.