-
Notifications
You must be signed in to change notification settings - Fork 145
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add threads support #418
base: master
Are you sure you want to change the base?
Add threads support #418
Conversation
ThreadMember: add ThreadMember.user ThreadMember: implement :remove and .threadId GuildThreadChannel: add documentation GuildThreadChannel: implement permission methods ThreadMember: more documentation GuildChannel: add setDefaultAutoArchiveDuration & some missing getters Message & GuildChannel: add documentation
I think I am mostly satisfied with this. I still need to do more testing before it becomes ready for merge, but should be good for a technical review. One thing I am really not sure if I should keep are the permissions methods.
Also to note, notice the naming scheme for |
- moves threadTypes into constants.lua for a single definition -
- make get.invitable return true on public threads instead of nil.
This should be everything we need to get Thread channels going on. Still some things to work out, mainly design related.
Here is an overview of the changes:
Added 2 new classes:
Hide details:
GuildThreadChannel: Represents a Thread channel, inherits from TextChannel.
ThreadMember: Wraps a Guild Member in a context of a specific Thread channel. This contains things like thread join time, etc.
Modified classes:
Show details:
Cache._hash
, this allows us to prioritize using a specific field instead ofdata.id
.This is needed because Discord sends
id
in the ThreadMember data... but instead of that ID being the member ID, it is actually the thread's ID. Discordia will always use the fieldid
as a hash when inserting into a cache, so we had to have a way to tell Discordia to usedata._user_id
instead ofdata.id
.SecondaryCache:_delete(k)
, allowing us to delete an object by key, instead of being forced to use_remove
for when we don't have the data, only the key.This is needed to clear stale threads from cache when Discord sends
THREAD_LIST_SYNC
event, which only provides the ID of the thread to be removed.:_insert
.A thread channel parent is the text channel it is created under, yet Discord will send the thread channels on GUILD_READY as
guild.threads
, this means threads needs to be cached inGuild
and the text channels needs to hold a reference to this.Therefor the thread channels cache is located and initialized at
Guild._thread_channels
, and each GuildChannel holds a SecondaryCache to that. A direct consequence of this is all thread channels will share the same parent instance (:_insert
defaults to a single parent object provided at initialization). With this change it becomes possible to provide a different parent with each:_insert
call.New API calls:
Show details:
getThreadMember
.getThreadMembers
.addThreadMember
.removeThreadMember
.getCurrentThreadMember
.joinThread
.leaveThread
.startThreadWithMessage
.startThreadWithoutMessaeg
.listArchivedPublicThreads
.listArchivedPrivateThreads
.listJoinedArchivedPrivateThreads
.Those are supposed to be auto-generated... but we don't have the API generator available in the repo it seems? I vaguely remember a Discord docs scraper.
New resolvers
Show details:
Resolver.channelFlag
: similar to howmessageFlag
is handled.Resolver.isoTimestamp
: utilize the Date class into timestamp inputs useful forgetArchivedPublicThreads(..., before)
, which is an ISO timestamp input; acceptsDate
,Date.fromTable
,Date.fromSeconds
.Also been thinking into integrating everything that accepts Time objects for duration as a resolver, we already make use of Time objects for
Member.timeoutFor
, and now Time is also used for things likeGuildThreadChannel:setAutoArchiveDuration(duration)
.New events:
Show details:
threadCreate
: fired when a new thread channel is created.threadUpdate
: fired when a thread channel is updated.threadDelete
: fired when a thread channel is deleted and is in cache.threadDeleteUncached
: fired when a thread channel is deleted and is not in cache.threadListSync
: fired when the client gains/loses access to threads (e.x. gains permissions) and should sync cache.threadMemberUpdate
: when a thread member is updated (e.x. left/joined).threadMembersUpdate
: multiple thread members updates.