Add td_api::setChatLocation.
GitOrigin-RevId: 1bf8060374189bd2c9435b9c57ed499723de7246
This commit is contained in:
parent
4e9ca731b2
commit
acf8afd2d6
@ -288,7 +288,7 @@ botCommand command:string description:string = BotCommand;
|
||||
botInfo description:string commands:vector<botCommand> = BotInfo;
|
||||
|
||||
|
||||
//@description Represents a location of a chat @location The location @address Location address; as defined by the chat creator
|
||||
//@description Represents a location of a chat @location The location @address Location address; 1-64 characters, as defined by the chat creator
|
||||
chatLocation location:location address:string = ChatLocation;
|
||||
|
||||
|
||||
@ -3442,12 +3442,16 @@ setChatDescription chat_id:int53 description:string = Ok;
|
||||
//-If new chat members don't have access to old messages in the supergroup, then toggleSupergroupIsAllHistoryAvailable needs to be used first to change that
|
||||
setChatDiscussionGroup chat_id:int53 discussion_chat_id:int53 = Ok;
|
||||
|
||||
//@description Changes the lcoation of a chat. Available only for location-based supergroups, see supergroupFullInfo.can_set_location @chat_id Chat identifier @location New location for the chat; must be valid and not null
|
||||
setChatLocation chat_id:int53 location:chatLocation = Ok;
|
||||
|
||||
//@description Pins a message in a chat; requires can_pin_messages rights @chat_id Identifier of the chat @message_id Identifier of the new pinned message @disable_notification True, if there should be no notification about the pinned message
|
||||
pinChatMessage chat_id:int53 message_id:int53 disable_notification:Bool = Ok;
|
||||
|
||||
//@description Removes the pinned message from a chat; requires can_pin_messages rights in the group or channel @chat_id Identifier of the chat
|
||||
unpinChatMessage chat_id:int53 = Ok;
|
||||
|
||||
|
||||
//@description Adds current user as a new member to a chat. Private and secret chats can't be joined using this method @chat_id Chat identifier
|
||||
joinChat chat_id:int53 = Ok;
|
||||
|
||||
|
Binary file not shown.
@ -1291,6 +1291,44 @@ class SetDiscussionGroupQuery : public Td::ResultHandler {
|
||||
}
|
||||
};
|
||||
|
||||
class EditLocationQuery : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
ChannelId channel_id_;
|
||||
DialogLocation location_;
|
||||
|
||||
public:
|
||||
explicit EditLocationQuery(Promise<Unit> &&promise) : promise_(std::move(promise)) {
|
||||
}
|
||||
|
||||
void send(ChannelId channel_id, const DialogLocation &location) {
|
||||
channel_id_ = channel_id;
|
||||
location_ = location;
|
||||
|
||||
auto input_channel = td->contacts_manager_->get_input_channel(channel_id);
|
||||
CHECK(input_channel != nullptr);
|
||||
|
||||
send_query(G()->net_query_creator().create(create_storer(telegram_api::channels_editLocation(
|
||||
std::move(input_channel), location_.get_input_geo_point(), location_.get_address()))));
|
||||
}
|
||||
|
||||
void on_result(uint64 id, BufferSlice packet) override {
|
||||
auto result_ptr = fetch_result<telegram_api::channels_editLocation>(packet);
|
||||
if (result_ptr.is_error()) {
|
||||
return on_error(id, result_ptr.move_as_error());
|
||||
}
|
||||
|
||||
bool result = result_ptr.move_as_ok();
|
||||
LOG_IF(INFO, !result) << "Edit chat location has failed";
|
||||
|
||||
td->contacts_manager_->on_update_channel_location(channel_id_, location_);
|
||||
promise_.set_value(Unit());
|
||||
}
|
||||
|
||||
void on_error(uint64 id, Status status) override {
|
||||
promise_.set_error(std::move(status));
|
||||
}
|
||||
};
|
||||
|
||||
class ReportChannelSpamQuery : public Td::ResultHandler {
|
||||
Promise<Unit> promise_;
|
||||
ChannelId channel_id_;
|
||||
@ -4751,6 +4789,38 @@ void ContactsManager::set_channel_discussion_group(DialogId dialog_id, DialogId
|
||||
std::move(group_input_channel));
|
||||
}
|
||||
|
||||
void ContactsManager::set_channel_location(DialogId dialog_id, const DialogLocation &location,
|
||||
Promise<Unit> &&promise) {
|
||||
if (location.empty()) {
|
||||
return promise.set_error(Status::Error(400, "Invalid chat location specified"));
|
||||
}
|
||||
|
||||
if (!dialog_id.is_valid()) {
|
||||
return promise.set_error(Status::Error(400, "Invalid chat specified"));
|
||||
}
|
||||
if (!td_->messages_manager_->have_dialog_force(dialog_id)) {
|
||||
return promise.set_error(Status::Error(400, "Chat not found"));
|
||||
}
|
||||
|
||||
if (dialog_id.get_type() != DialogType::Channel) {
|
||||
return promise.set_error(Status::Error(400, "Chat is not a supergroup"));
|
||||
}
|
||||
|
||||
auto channel_id = dialog_id.get_channel_id();
|
||||
const Channel *c = get_channel(channel_id);
|
||||
if (c == nullptr) {
|
||||
return promise.set_error(Status::Error(400, "Chat info not found"));
|
||||
}
|
||||
if (!c->is_megagroup) {
|
||||
return promise.set_error(Status::Error(400, "Chat is not a supergroup"));
|
||||
}
|
||||
if (!c->status.is_creator()) {
|
||||
return promise.set_error(Status::Error(400, "Have not enough rights in the supergroup"));
|
||||
}
|
||||
|
||||
td_->create_handler<EditLocationQuery>(std::move(promise))->send(channel_id, location);
|
||||
}
|
||||
|
||||
void ContactsManager::report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
|
||||
Promise<Unit> &&promise) {
|
||||
auto c = get_channel(channel_id);
|
||||
@ -7698,7 +7768,6 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
|
||||
if (channel_full->stickerset_ != nullptr) {
|
||||
sticker_set_id = td_->stickers_manager_->on_get_sticker_set(std::move(channel_full->stickerset_), true);
|
||||
}
|
||||
auto location = DialogLocation(std::move(channel_full->location_));
|
||||
|
||||
ChannelFull *channel = &channels_full_[channel_id];
|
||||
channel->expires_at = Time::now() + CHANNEL_FULL_EXPIRE_TIME;
|
||||
@ -7707,7 +7776,7 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
|
||||
channel->banned_count != banned_count || channel->can_get_participants != can_get_participants ||
|
||||
channel->can_set_username != can_set_username || channel->can_set_sticker_set != can_set_sticker_set ||
|
||||
channel->can_set_location != can_set_location || channel->can_view_statistics != can_view_statistics ||
|
||||
channel->sticker_set_id != sticker_set_id || channel->location != location || channel->is_all_history_available != is_all_history_available) {
|
||||
channel->sticker_set_id != sticker_set_id || channel->is_all_history_available != is_all_history_available) {
|
||||
channel->description = std::move(channel_full->about_);
|
||||
channel->participant_count = participant_count;
|
||||
channel->administrator_count = administrator_count;
|
||||
@ -7720,7 +7789,6 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
|
||||
channel->can_view_statistics = can_view_statistics;
|
||||
channel->is_all_history_available = is_all_history_available;
|
||||
channel->sticker_set_id = sticker_set_id;
|
||||
channel->location = std::move(location);
|
||||
|
||||
channel->is_changed = true;
|
||||
|
||||
@ -7782,6 +7850,8 @@ void ContactsManager::on_get_chat_full(tl_object_ptr<telegram_api::ChatFull> &&c
|
||||
}
|
||||
on_update_channel_full_linked_channel_id(channel, channel_id, linked_channel_id);
|
||||
|
||||
on_update_channel_full_location(channel, channel_id, DialogLocation(std::move(channel_full->location_)));
|
||||
|
||||
ChatId migrated_from_chat_id;
|
||||
MessageId migrated_from_max_message_id;
|
||||
|
||||
@ -8929,6 +8999,22 @@ void ContactsManager::on_update_channel_full_linked_channel_id(ChannelFull *chan
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_channel_full_location(ChannelFull *channel_full, ChannelId channel_id,
|
||||
const DialogLocation &location) {
|
||||
if (channel_full->location != location) {
|
||||
channel_full->location = location;
|
||||
channel_full->is_changed = true;
|
||||
}
|
||||
|
||||
Channel *c = get_channel(channel_id);
|
||||
CHECK(c != nullptr);
|
||||
if (location.empty() == c->has_location) {
|
||||
c->has_location = !location.empty();
|
||||
c->need_send_update = true;
|
||||
update_channel(c, channel_id);
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_get_dialog_invite_link_info(const string &invite_link,
|
||||
tl_object_ptr<telegram_api::ChatInvite> &&chat_invite_ptr) {
|
||||
auto &invite_link_info = invite_link_infos_[invite_link];
|
||||
@ -9691,6 +9777,14 @@ void ContactsManager::on_update_channel_linked_channel_id(ChannelId channel_id,
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_channel_location(ChannelId channel_id, const DialogLocation &location) {
|
||||
auto channel_full = get_channel_full_force(channel_id);
|
||||
if (channel_full != nullptr) {
|
||||
on_update_channel_full_location(channel_full, channel_id, location);
|
||||
update_channel_full(channel_full, channel_id);
|
||||
}
|
||||
}
|
||||
|
||||
void ContactsManager::on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available) {
|
||||
if (!channel_id.is_valid()) {
|
||||
LOG(ERROR) << "Receive invalid " << channel_id;
|
||||
|
@ -175,6 +175,7 @@ class ContactsManager : public Actor {
|
||||
void on_update_channel_description(ChannelId channel_id, string &&description);
|
||||
void on_update_channel_sticker_set(ChannelId channel_id, StickerSetId sticker_set_id);
|
||||
void on_update_channel_linked_channel_id(ChannelId channel_id, ChannelId group_channel_id);
|
||||
void on_update_channel_location(ChannelId channel_id, const DialogLocation &location);
|
||||
void on_update_channel_is_all_history_available(ChannelId channel_id, bool is_all_history_available);
|
||||
void on_update_channel_default_permissions(ChannelId channel_id, RestrictedRights default_permissions);
|
||||
|
||||
@ -308,6 +309,8 @@ class ContactsManager : public Actor {
|
||||
|
||||
void set_channel_discussion_group(DialogId dialog_id, DialogId discussion_dialog_id, Promise<Unit> &&promise);
|
||||
|
||||
void set_channel_location(DialogId dialog_id, const DialogLocation &location, Promise<Unit> &&promise);
|
||||
|
||||
void report_channel_spam(ChannelId channel_id, UserId user_id, const vector<MessageId> &message_ids,
|
||||
Promise<Unit> &&promise);
|
||||
|
||||
@ -1000,6 +1003,7 @@ class ContactsManager : public Actor {
|
||||
tl_object_ptr<telegram_api::ExportedChatInvite> &&invite_link_ptr);
|
||||
void on_update_channel_full_linked_channel_id(ChannelFull *channel_full, ChannelId channel_id,
|
||||
ChannelId linked_channel_id);
|
||||
void on_update_channel_full_location(ChannelFull *channel_full, ChannelId channel_id, const DialogLocation &location);
|
||||
|
||||
static bool speculative_add_count(int32 &count, int32 new_count);
|
||||
|
||||
|
@ -28,7 +28,7 @@ class DialogLocation {
|
||||
public:
|
||||
DialogLocation() = default;
|
||||
|
||||
DialogLocation(telegram_api::object_ptr<telegram_api::ChannelLocation> &&channel_location_ptr);
|
||||
explicit DialogLocation(telegram_api::object_ptr<telegram_api::ChannelLocation> &&channel_location_ptr);
|
||||
|
||||
explicit DialogLocation(td_api::object_ptr<td_api::chatLocation> &&chat_location);
|
||||
|
||||
|
@ -6057,6 +6057,13 @@ void Td::on_request(uint64 id, const td_api::setChatDiscussionGroup &request) {
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, td_api::setChatLocation &request) {
|
||||
CHECK_IS_USER();
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
contacts_manager_->set_channel_location(DialogId(request.chat_id_), DialogLocation(std::move(request.location_)),
|
||||
std::move(promise));
|
||||
}
|
||||
|
||||
void Td::on_request(uint64 id, const td_api::pinChatMessage &request) {
|
||||
CREATE_OK_REQUEST_PROMISE();
|
||||
messages_manager_->pin_dialog_message(DialogId(request.chat_id_), MessageId(request.message_id_),
|
||||
|
@ -670,6 +670,8 @@ class Td final : public NetQueryCallback {
|
||||
|
||||
void on_request(uint64 id, const td_api::setChatDiscussionGroup &request);
|
||||
|
||||
void on_request(uint64 id, td_api::setChatLocation &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::pinChatMessage &request);
|
||||
|
||||
void on_request(uint64 id, const td_api::unpinChatMessage &request);
|
||||
|
@ -3496,6 +3496,15 @@ class CliClient final : public Actor {
|
||||
|
||||
std::tie(chat_id, group_chat_id) = split(args);
|
||||
send_request(td_api::make_object<td_api::setChatDiscussionGroup>(as_chat_id(chat_id), as_chat_id(group_chat_id)));
|
||||
} else if (op == "scl") {
|
||||
string chat_id;
|
||||
string latitude;
|
||||
string longitude;
|
||||
|
||||
std::tie(chat_id, args) = split(args);
|
||||
std::tie(latitude, longitude) = split(args);
|
||||
send_request(td_api::make_object<td_api::setChatLocation>(
|
||||
as_chat_id(chat_id), td_api::make_object<td_api::chatLocation>(as_location(latitude, longitude), "address")));
|
||||
} else if (op == "pcm" || op == "pcms") {
|
||||
string chat_id;
|
||||
string message_id;
|
||||
|
Reference in New Issue
Block a user