| 1 | /************************************************************************************ |
| 2 | * |
| 3 | * D++, A Lightweight C++ library for Discord |
| 4 | * |
| 5 | * SPDX-License-Identifier: Apache-2.0 |
| 6 | * Copyright 2021 Craig Edwards and D++ contributors |
| 7 | * (https://github.com/brainboxdotcc/DPP/graphs/contributors) |
| 8 | * |
| 9 | * Licensed under the Apache License, Version 2.0 (the "License"); |
| 10 | * you may not use this file except in compliance with the License. |
| 11 | * You may obtain a copy of the License at |
| 12 | * |
| 13 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 14 | * |
| 15 | * Unless required by applicable law or agreed to in writing, software |
| 16 | * distributed under the License is distributed on an "AS IS" BASIS, |
| 17 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 18 | * See the License for the specific language governing permissions and |
| 19 | * limitations under the License. |
| 20 | * |
| 21 | ************************************************************************************/ |
| 22 | #include <dpp/discordevents.h> |
| 23 | #include <dpp/cluster.h> |
| 24 | #include <dpp/channel.h> |
| 25 | #include <dpp/stringops.h> |
| 26 | #include <dpp/json.h> |
| 27 | |
| 28 | |
| 29 | |
| 30 | namespace dpp::events { |
| 31 | void thread_update::handle(discord_client* client, json& j, const std::string& raw) { |
| 32 | json& d = j["d"]; |
| 33 | |
| 34 | dpp::thread t; |
| 35 | t.fill_from_json(&d); |
| 36 | dpp::guild* g = dpp::find_guild(t.guild_id); |
| 37 | if (!client->creator->on_thread_update.empty()) { |
| 38 | dpp::thread_update_t tu(client->owner, client->shard_id, raw); |
| 39 | |
| 40 | tu.updated = t; |
| 41 | tu.updating_guild = g ? *g : guild{}; |
| 42 | tu.updating_guild.id = t.guild_id; |
| 43 | |
| 44 | client->creator->queue_work(1, [c = client->creator, tu]() { |
| 45 | c->on_thread_update.call(tu); |
| 46 | }); |
| 47 | } |
| 48 | } |
| 49 | }; |