31 Thread::Thread(Value jsonData) {
32 std::unique_ptr<Channel> channel{ std::make_unique<Channel>(jsonData) };
33 *
this = *
static_cast<Thread*
>(channel.get());
36 StartThreadWithMessageData::operator Serializer() {
38 data[
"auto_archive_duration"] = this->autoArchiveDuration;
39 data[
"rate_limit_per_user"] = this->rateLimitPerUser;
40 data[
"name"] = this->threadName;
44 StartThreadWithoutMessageData::operator Serializer() {
46 data[
"auto_archive_duration"] = this->autoArchiveDuration;
47 data[
"rate_limit_per_user"] = this->rateLimitPerUser;
48 data[
"invitable"] = this->invitable;
49 data[
"name"] = this->threadName;
50 data[
"type"] = this->type;
54 StartThreadInForumChannelData::operator Serializer() {
56 if (this->message.allowedMentions.parse.size() > 0 || this->message.allowedMentions.roles.size() > 0 ||
57 this->message.allowedMentions.users.size() > 0) {
58 data[
"message"][
"allowed_mentions"] = this->message.allowedMentions.operator Serializer();
60 for (
auto& value: this->message.attachments) {
61 data[
"message"][
"attachments"].emplaceBack(value.operator Serializer());
63 if (this->message.components.size() == 0) {
64 data[
"message"][
"components"].emplaceBack(ActionRowData{});
65 data[
"message"][
"components"].getValue<Jsonifier::Serializer::ArrayType>().clear();
67 for (
auto& value: this->message.components) {
68 data[
"message"][
"components"].emplaceBack(value.operator Serializer());
71 for (
auto& value: this->message.stickerIds) {
72 data[
"message"][
"sticker_ids"].emplaceBack(value);
74 if (this->message.embeds.size() == 0) {
75 data[
"message"][
"embeds"].emplaceBack(EmbedData{});
76 data[
"message"][
"embeds"].getValue<Jsonifier::Serializer::ArrayType>().clear();
78 for (
auto& value: this->message.embeds) {
79 data[
"message"][
"embeds"].emplaceBack(value.operator Serializer());
82 if (this->message.content !=
"") {
83 data[
"message"][
"content"] = this->message.content;
85 data[
"message"][
"flags"] = this->message.flags;
86 data[
"name"] = this->name;
87 data[
"auto_archive_duration"] = this->autoArchiveDuration;
88 data[
"rate_limit_per_user"] = this->rateLimitPerUser;
92 void Threads::initialize(DiscordCoreInternal::HttpsClient* client) {
93 Threads::httpsClient = client;
97 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Thread_With_Message };
98 co_await NewThreadAwaitable<Thread>();
99 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
100 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/messages/" + dataPackage.
messageId +
"/threads";
101 auto serializer = dataPackage.operator Serializer();
102 serializer.refreshString(JsonifierSerializeType::Json);
103 workload.content = serializer.operator std::string();
104 workload.callStack =
"Threads::startThreadWithMessageAsync()";
105 if (dataPackage.
reason !=
"") {
106 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
109 co_return Threads::httpsClient->submitWorkloadAndGetResult<
Thread>(workload, &returnValue);
113 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Thread_Without_Message };
114 co_await NewThreadAwaitable<Thread>();
115 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
116 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/threads";
117 auto serializer = dataPackage.operator Serializer();
118 serializer.refreshString(JsonifierSerializeType::Json);
119 workload.content = serializer.operator std::string();
120 workload.callStack =
"Threads::startThreadWithoutMessageAsync()";
121 if (dataPackage.
reason !=
"") {
122 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
125 co_return Threads::httpsClient->submitWorkloadAndGetResult<
Thread>(workload, &returnValue);
129 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Post_Thread_In_Forum_Channel };
130 co_await NewThreadAwaitable<Thread>();
131 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Post;
132 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/threads";
133 auto serializer = dataPackage.operator Serializer();
134 serializer.refreshString(JsonifierSerializeType::Json);
135 workload.content = serializer.operator std::string();
136 workload.callStack =
"Threads::startThreadInForumChannelAsync()";
137 if (dataPackage.
reason !=
"") {
138 workload.headersToInsert[
"X-Audit-Log-Reason"] = dataPackage.
reason;
141 co_return Threads::httpsClient->submitWorkloadAndGetResult<
Thread>(workload, &returnValue);
145 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Put_Self_In_Thread };
146 co_await NewThreadAwaitable<void>();
147 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Put;
148 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/thread-members/@me";
149 workload.callStack =
"Threads::joinThreadAsync()";
150 co_return Threads::httpsClient->submitWorkloadAndGetResult<
void>(workload);
154 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Put_Thread_Member };
155 co_await NewThreadAwaitable<void>();
156 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Put;
157 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/thread-members/" + dataPackage.
userId;
158 workload.callStack =
"Threads::addThreadMemberAsync()";
159 co_return Threads::httpsClient->submitWorkloadAndGetResult<
void>(workload);
163 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Self_From_Thread };
164 co_await NewThreadAwaitable<void>();
165 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
166 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/thread-members/@me";
167 workload.callStack =
"Threads::leaveThreadAsync()";
168 co_return Threads::httpsClient->submitWorkloadAndGetResult<
void>(workload);
172 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Delete_Thread_Member };
173 co_await NewThreadAwaitable<void>();
174 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Delete;
175 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/thread-members/" + dataPackage.
userId;
176 workload.callStack =
"Threads::removeThreadMemberAsync()";
177 co_return Threads::httpsClient->submitWorkloadAndGetResult<
void>(workload);
181 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Thread_Member };
182 co_await NewThreadAwaitable<ThreadMemberData>();
183 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
184 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/thread-members/" + dataPackage.
userId;
185 workload.callStack =
"Threads::getThreadMemberAsync()";
187 co_return Threads::httpsClient->submitWorkloadAndGetResult<
ThreadMemberData>(workload, &returnValue);
191 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Thread_Members };
192 co_await NewThreadAwaitable<std::vector<ThreadMemberData>>();
193 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
194 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/thread-members";
195 workload.callStack =
"Threads::getThreadMembersAsync()";
196 ThreadMemberDataVector returnValue{};
197 co_return Threads::httpsClient->submitWorkloadAndGetResult<ThreadMemberDataVector>(workload, &returnValue);
201 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Active_Threads };
202 co_await NewThreadAwaitable<ActiveThreadsData>();
203 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
204 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/threads/active";
205 workload.callStack =
"Threads::getActiveThreadsAsync()";
207 co_return Threads::httpsClient->submitWorkloadAndGetResult<
ActiveThreadsData>(workload, &returnValue);
211 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Public_Archived_Threads };
212 co_await NewThreadAwaitable<ArchivedThreadsData>();
213 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
214 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/threads/archived/public";
215 if (dataPackage.
before !=
"") {
216 workload.relativePath +=
"?before=" + dataPackage.
before;
217 if (dataPackage.
limit != 0) {
218 workload.relativePath +=
"&limit=" + std::to_string(dataPackage.
limit);
220 }
else if (dataPackage.
limit != 0) {
221 workload.relativePath +=
"?limit=" + std::to_string(dataPackage.
limit);
223 workload.callStack =
"Threads::getPublicArchivedThreadsAsync()";
225 co_return Threads::httpsClient->submitWorkloadAndGetResult<
ArchivedThreadsData>(workload, &returnValue);
229 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Private_Archived_Threads };
230 co_await NewThreadAwaitable<ArchivedThreadsData>();
231 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
232 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/threads/archived/private";
233 if (dataPackage.
before !=
"") {
234 workload.relativePath +=
"?before=" + dataPackage.
before;
235 if (dataPackage.
limit != 0) {
236 workload.relativePath +=
"&limit=" + std::to_string(dataPackage.
limit);
238 }
else if (dataPackage.
limit != 0) {
239 workload.relativePath +=
"?limit=" + std::to_string(dataPackage.
limit);
241 workload.callStack =
"Threads::getPrivateArchivedThreadsAsync()";
243 co_return Threads::httpsClient->submitWorkloadAndGetResult<
ArchivedThreadsData>(workload, &returnValue);
247 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Joined_Private_Archived_Threads };
248 co_await NewThreadAwaitable<ArchivedThreadsData>();
249 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
250 workload.relativePath =
"/channels/" + dataPackage.
channelId +
"/users/@me/threads/archived/private";
251 if (dataPackage.
before !=
"") {
252 workload.relativePath +=
"?before=" + dataPackage.
before;
253 if (dataPackage.
limit != 0) {
254 workload.relativePath +=
"&limit=" + std::to_string(dataPackage.
limit);
256 }
else if (dataPackage.
limit != 0) {
257 workload.relativePath +=
"?limit=" + std::to_string(dataPackage.
limit);
259 workload.callStack =
"Threads::getJoinedPrivateArchivedThreadsAsync()";
261 co_return Threads::httpsClient->submitWorkloadAndGetResult<
ArchivedThreadsData>(workload, &returnValue);
265 DiscordCoreInternal::HttpsWorkloadData workload{ DiscordCoreInternal::HttpsWorkloadType::Get_Guild_Active_Threads };
266 co_await NewThreadAwaitable<ActiveThreadsData>();
267 workload.workloadClass = DiscordCoreInternal::HttpsWorkloadClass::Get;
268 workload.relativePath =
"/guilds/" + dataPackage.
guildId +
"/threads/active";
269 workload.callStack =
"Threads::listActiveThreadsAsync()";
271 co_return Threads::httpsClient->submitWorkloadAndGetResult<
ActiveThreadsData>(workload, &returnValue);
273 DiscordCoreInternal::HttpsClient* Threads::httpsClient{
nullptr };
The main namespace for this library.
A CoRoutine - representing a potentially asynchronous operation/function.
Data for a single member of a Thread.
Data representing an active Thread.
Data representing an archived Thread.
For starting a Thread, based on a Message.
Snowflake channelId
The Channel to start the Thread in.
Snowflake messageId
The Message Id to base the Thread off of.
std::string reason
Reason for starting the Thread.
For starting a Thread, not based on a Message.
std::string reason
Reason for starting the Thread.
Snowflake channelId
The Channel to start the Thread in.
For starting a Thread, in a forum channel.
std::string reason
Reason for starting the Thread.
Snowflake channelId
The id of the channel.
Snowflake channelId
The id of the Thread to join.
For adding a chosen User to a chosen Thread.
Snowflake userId
The id of the User to add to the Thread.
Snowflake channelId
The id of the Thread to join.
Snowflake channelId
The id of the Thread to leave.
For removing a chosen User from a Thread.
Snowflake channelId
The id of the Thread to remove them from.
Snowflake userId
The id of the User to remove from the Thread.
For collecting a ThreadMember responseData structure for a given ThreadMember.
Snowflake userId
The id of the User to collect from the Thread.
Snowflake channelId
The id of the Thread to collect them from.
For collecting the list of ThreadMembers from a Thread.
Snowflake channelId
The id of the Thread to collect them from.
For collecting the list of active Threads.
Snowflake channelId
The id of the Channel to collect the Threads from.
For collecting puiblic archived Threads from a given Channel.
std::string before
Returns threads before this timeStamp.
int32_t limit
Maximum number of threads to return.
Snowflake channelId
The Channel to acquire the Threads from.
For collecting private archived Threads from a given Channel.
std::string before
Returns threads before this timeStamp.
int32_t limit
Maximum number of threads to return.
Snowflake channelId
The Channel to acquire the Threads from.
For collecting joined private archived Threads from a given Channel.
int32_t limit
Maximum number of threads to return.
std::string before
Returns threads before this timeStamp.
Snowflake channelId
The Channel to acquire the Threads from.
For listing the active Threads in a chosen Guild.
Snowflake guildId
The Guild from which to list the Threads from.
Represents a single Thread.
static CoRoutine< ThreadMemberData > getThreadMemberAsync(GetThreadMemberData dataPackage)
Collects a ThreadMember if they exist.
static CoRoutine< ActiveThreadsData > getActiveThreadsAsync(GetActiveThreadsData dataPackage)
Collects a list of Threads from a given Channel.
static CoRoutine< ArchivedThreadsData > getJoinedPrivateArchivedThreadsAsync(GetJoinedPrivateArchivedThreadsData dataPackage)
Collects a list of joined private archived Threads from a given Channel.
static CoRoutine< Thread > startThreadWithMessageAsync(StartThreadWithMessageData dataPackage)
Starts a Thread, based on a starting Message.
static CoRoutine< ArchivedThreadsData > getPrivateArchivedThreadsAsync(GetPrivateArchivedThreadsData dataPackage)
Collects a list of private archived Threads from a given Channel.
static CoRoutine< Thread > startThreadWithoutMessageAsync(StartThreadWithoutMessageData dataPackage)
Starts a Thread, not based on a starting Message.
static CoRoutine< ArchivedThreadsData > getPublicArchivedThreadsAsync(GetPublicArchivedThreadsData dataPackage)
Collects a list of public archived Threads from a given Channel.
static CoRoutine< ActiveThreadsData > getActiveGuildThreadsAsync(GetActiveGuildThreadsData dataPackage)
Lists all of the active Threads of a chosen Guild.
static CoRoutine< void > addThreadMemberAsync(AddThreadMemberData dataPackage)
Adds a new User to a chosen Thread.
static CoRoutine< void > leaveThreadAsync(LeaveThreadData dataPackage)
Leaves a Thread.
static CoRoutine< void > removeThreadMemberAsync(RemoveThreadMemberData dataPackage)
Removes a User from a chosen Thread.
static CoRoutine< Thread > startThreadInForumChannelAsync(StartThreadInForumChannelData dataPackage)
Starts a Thread, in a forum channel.
static CoRoutine< std::vector< ThreadMemberData > > getThreadMembersAsync(GetThreadMembersData dataPackage)
Collects a list of ThreadMembers if they exist.
static CoRoutine< void > joinThreadAsync(JoinThreadData dataPackage)
Joins a Thread.