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));
}
}
Aggregations