Search in sources :

Example 1 with ThreadMemberLeaveEvent

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

the class ThreadMembersUpdateHandler method handleRemovedThreadMembers.

private void handleRemovedThreadMembers(ThreadChannelImpl thread, List<Long> removedMemberIds) {
    CacheView.SimpleCacheView<ThreadMember> view = thread.getThreadMemberView();
    // Store the removed threads into a map so that we can provide them in the events later.
    // We don't want to dispatch the events from inside the writeLock
    TLongObjectMap<ThreadMember> removedThreadMembers = new TLongObjectHashMap<>();
    try (UnlockHook lock = view.writeLock()) {
        for (long threadMemberId : removedMemberIds) {
            ThreadMember threadMember = view.getMap().remove(threadMemberId);
            removedThreadMembers.put(threadMemberId, threadMember);
        }
    }
    for (long threadMemberId : removedMemberIds) {
        api.handleEvent(new ThreadMemberLeaveEvent(api, responseNumber, thread, threadMemberId, removedThreadMembers.remove(threadMemberId)));
    }
}
Also used : CacheView(net.dv8tion.jda.api.utils.cache.CacheView) UnlockHook(net.dv8tion.jda.internal.utils.UnlockHook) ThreadMemberLeaveEvent(net.dv8tion.jda.api.events.thread.member.ThreadMemberLeaveEvent) TLongObjectHashMap(gnu.trove.map.hash.TLongObjectHashMap) ThreadMember(net.dv8tion.jda.api.entities.ThreadMember)

Aggregations

TLongObjectHashMap (gnu.trove.map.hash.TLongObjectHashMap)1 ThreadMember (net.dv8tion.jda.api.entities.ThreadMember)1 ThreadMemberLeaveEvent (net.dv8tion.jda.api.events.thread.member.ThreadMemberLeaveEvent)1 CacheView (net.dv8tion.jda.api.utils.cache.CacheView)1 UnlockHook (net.dv8tion.jda.internal.utils.UnlockHook)1