Search in sources :

Example 1 with ThreadMemberJoinEvent

use of net.dv8tion.jda.api.events.thread.member.ThreadMemberJoinEvent in project JDA by DV8FromTheWorld.

the class ThreadMembersUpdateHandler method handleAddedThreadMembers.

private void handleAddedThreadMembers(ThreadChannelImpl thread, DataArray addedMembersJson) {
    EntityBuilder entityBuilder = api.getEntityBuilder();
    CacheView.SimpleCacheView<ThreadMember> view = thread.getThreadMemberView();
    List<ThreadMember> addedThreadMembers = new ArrayList<>();
    for (int i = 0; i < addedMembersJson.length(); i++) {
        DataObject threadMemberJson = addedMembersJson.getObject(i);
        ThreadMember threadMember = entityBuilder.createThreadMember((GuildImpl) thread.getGuild(), thread, threadMemberJson);
        addedThreadMembers.add(threadMember);
    }
    // want to cache ThreadMembers if the Members they're based on aren't being cached.
    try (UnlockHook lock = view.writeLock()) {
        for (ThreadMember threadMember : addedThreadMembers) {
            view.getMap().put(threadMember.getIdLong(), threadMember);
        }
    }
    // Emit the events from outside the writeLock
    for (ThreadMember threadMember : addedThreadMembers) {
        api.handleEvent(new ThreadMemberJoinEvent(api, responseNumber, thread, threadMember));
    }
}
Also used : DataObject(net.dv8tion.jda.api.utils.data.DataObject) CacheView(net.dv8tion.jda.api.utils.cache.CacheView) UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook) ArrayList(java.util.ArrayList) EntityBuilder(net.dv8tion.jda.internal.entities.EntityBuilder) ThreadMember(net.dv8tion.jda.api.entities.ThreadMember) ThreadMemberJoinEvent(net.dv8tion.jda.api.events.thread.member.ThreadMemberJoinEvent)

Aggregations

ArrayList (java.util.ArrayList)1 ThreadMember (net.dv8tion.jda.api.entities.ThreadMember)1 ThreadMemberJoinEvent (net.dv8tion.jda.api.events.thread.member.ThreadMemberJoinEvent)1 CacheView (net.dv8tion.jda.api.utils.cache.CacheView)1 DataObject (net.dv8tion.jda.api.utils.data.DataObject)1 EntityBuilder (net.dv8tion.jda.internal.entities.EntityBuilder)1 UnlockHook (net.dv8tion.jda.internal.utils.UnlockHook)1