use of net.dv8tion.jda.api.entities.ThreadChannel in project JDA by DV8FromTheWorld.
the class ThreadListSyncHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
long guildId = content.getLong("guild_id");
if (api.getGuildSetupController().isLocked(guildId))
return guildId;
EntityBuilder entityBuilder = api.getEntityBuilder();
DataArray threadsArrayJson = content.getArray("threads");
for (int i = 0; i < threadsArrayJson.length(); i++) {
DataObject threadJson = threadsArrayJson.getObject(i);
ThreadChannel thread = entityBuilder.createThreadChannel(threadJson, guildId);
api.handleEvent(new ThreadRevealedEvent(api, responseNumber, thread));
}
return null;
}
use of net.dv8tion.jda.api.entities.ThreadChannel in project JDA by DV8FromTheWorld.
the class ThreadDeleteHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
long guildId = content.getLong("guild_id");
if (getJDA().getGuildSetupController().isLocked(guildId))
return guildId;
GuildImpl guild = (GuildImpl) getJDA().getGuildById(guildId);
final long threadId = content.getLong("id");
ThreadChannel thread = getJDA().getThreadChannelsView().remove(threadId);
if (thread == null || guild == null) {
WebSocketClient.LOG.debug("THREAD_DELETE attempted to delete a thread that is not yet cached. JSON: {}", content);
return null;
}
guild.getThreadChannelsView().remove(threadId);
getJDA().handleEvent(new ChannelDeleteEvent(getJDA(), responseNumber, thread));
getJDA().getEventCache().clear(EventCache.Type.CHANNEL, threadId);
return null;
}
use of net.dv8tion.jda.api.entities.ThreadChannel in project JDA by DV8FromTheWorld.
the class ThreadChannelPaginationActionImpl method handleSuccess.
@Override
protected void handleSuccess(Response response, Request<List<ThreadChannel>> request) {
DataObject obj = response.getObject();
DataArray selfThreadMembers = obj.getArray("members");
DataArray threads = obj.getArray("threads");
List<ThreadChannel> list = new ArrayList<>(threads.length());
EntityBuilder builder = api.getEntityBuilder();
TLongObjectMap<DataObject> selfThreadMemberMap = new TLongObjectHashMap<>();
for (int i = 0; i < selfThreadMembers.length(); i++) {
DataObject selfThreadMember = selfThreadMembers.getObject(i);
// Store the thread member based on the "id" which is the _thread's_ id, not the member's id (which would be our id)
selfThreadMemberMap.put(selfThreadMember.getLong("id"), selfThreadMember);
}
for (int i = 0; i < threads.length(); i++) {
try {
DataObject threadObj = threads.getObject(i);
DataObject selfThreadMemberObj = selfThreadMemberMap.get(threadObj.getLong("id", 0));
if (selfThreadMemberObj != null) {
// Combine the thread and self thread-member into a single object to model what we get from
// thread payloads (like from Gateway, etc)
threadObj.put("member", selfThreadMemberObj);
}
ThreadChannel thread = builder.createThreadChannel(threadObj, getGuild().getIdLong());
list.add(thread);
if (this.useCache)
this.cached.add(thread);
this.last = thread;
this.lastKey = last.getIdLong();
} catch (ParsingException | NullPointerException e) {
LOG.warn("Encountered exception in ThreadChannelPagination", e);
}
}
request.onSuccess(list);
}
use of net.dv8tion.jda.api.entities.ThreadChannel in project JDA by DV8FromTheWorld.
the class ThreadCreateHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
long guildId = content.getLong("guild_id");
if (api.getGuildSetupController().isLocked(guildId))
return guildId;
ThreadChannel thread = api.getEntityBuilder().createThreadChannel(content, guildId);
api.handleEvent(new ChannelCreateEvent(api, responseNumber, thread));
return null;
}
use of net.dv8tion.jda.api.entities.ThreadChannel in project JDA by DV8FromTheWorld.
the class ThreadUpdateHandler method handleInternally.
@Override
protected Long handleInternally(DataObject content) {
long guildId = content.getLong("guild_id");
if (api.getGuildSetupController().isLocked(guildId))
return guildId;
final long threadId = content.getLong("id");
ThreadChannelImpl thread = (ThreadChannelImpl) getJDA().getThreadChannelById(threadId);
// Refer to the documentation for more info: https://discord.com/developers/docs/topics/threads#unarchiving-a-thread
if (thread == null) {
// Technically, when the ThreadChannel is unarchived the archive_timestamp (getTimeArchiveInfoLastModified) changes
// as well, but we don't have the original value because we didn't have the thread in memory, so we can't
// provide an entirely accurate ChannelUpdateArchiveTimestampEvent. Not sure how much that'll matter.
thread = (ThreadChannelImpl) api.getEntityBuilder().createThreadChannel(content, guildId);
api.handleEvent(new ChannelUpdateArchivedEvent(api, responseNumber, thread, true, false));
return null;
}
final DataObject threadMetadata = content.getObject("thread_metadata");
final String name = content.getString("name");
final ThreadChannel.AutoArchiveDuration autoArchiveDuration = ThreadChannel.AutoArchiveDuration.fromKey(threadMetadata.getInt("auto_archive_duration"));
final boolean locked = threadMetadata.getBoolean("locked");
final boolean archived = threadMetadata.getBoolean("archived");
final boolean invitable = threadMetadata.getBoolean("invitable");
final long archiveTimestamp = Helpers.toTimestamp(threadMetadata.getString("archive_timestamp"));
final int slowmode = content.getInt("rate_limit_per_user", 0);
final String oldName = thread.getName();
final ThreadChannel.AutoArchiveDuration oldAutoArchiveDuration = thread.getAutoArchiveDuration();
final boolean oldLocked = thread.isLocked();
final boolean oldArchived = thread.isArchived();
final boolean oldInvitable = !thread.isPublic() && thread.isInvitable();
final long oldArchiveTimestamp = thread.getArchiveTimestamp();
final int oldSlowmode = thread.getSlowmode();
// TODO should these be Thread specific events?
if (!Objects.equals(oldName, name)) {
thread.setName(name);
api.handleEvent(new ChannelUpdateNameEvent(getJDA(), responseNumber, thread, oldName, name));
}
if (oldSlowmode != slowmode) {
thread.setSlowmode(slowmode);
api.handleEvent(new ChannelUpdateSlowmodeEvent(api, responseNumber, thread, oldSlowmode, slowmode));
}
if (oldAutoArchiveDuration != autoArchiveDuration) {
thread.setAutoArchiveDuration(autoArchiveDuration);
api.handleEvent(new ChannelUpdateAutoArchiveDurationEvent(api, responseNumber, thread, oldAutoArchiveDuration, autoArchiveDuration));
}
if (oldLocked != locked) {
thread.setLocked(locked);
api.handleEvent(new ChannelUpdateLockedEvent(api, responseNumber, thread, oldLocked, locked));
}
if (oldArchived != archived) {
thread.setArchived(archived);
api.handleEvent(new ChannelUpdateArchivedEvent(api, responseNumber, thread, oldArchived, archived));
}
if (oldArchiveTimestamp != archiveTimestamp) {
thread.setArchiveTimestamp(archiveTimestamp);
api.handleEvent(new ChannelUpdateArchiveTimestampEvent(api, responseNumber, thread, oldArchiveTimestamp, archiveTimestamp));
}
if (oldInvitable != invitable) {
thread.setInvitable(invitable);
api.handleEvent(new ChannelUpdateInvitableEvent(api, responseNumber, thread, oldInvitable, invitable));
}
return null;
}
Aggregations