Add Chat.can_be_reported.

GitOrigin-RevId: b1cf15ee0071bbb2ab6d026121eb9d2a0735e5b4
This commit is contained in:
levlam 2018-03-04 17:14:37 +03:00
parent d67c5ada3c
commit 75371b6399
4 changed files with 25 additions and 20 deletions

View File

@ -528,6 +528,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int32 = ChatType;
//@last_message Last message in the chat; may be null
//@order Descending parameter by which chats are sorted in the main chat list. If the order number of two chats is the same, they must be sorted in descending order by ID. If 0, the position of the chat in the list is undetermined
//@is_pinned True, if the chat is pinned
//#can_be_reported True, if the chat can be reported to Telegram moderators through reportChat
//@unread_count Number of unread messages in the chat
//@last_read_inbox_message_id Identifier of the last read incoming message
//@last_read_outbox_message_id Identifier of the last read outgoing message
@ -536,7 +537,7 @@ chatTypeSecret secret_chat_id:int32 user_id:int32 = ChatType;
//@reply_markup_message_id Identifier of the message from which reply markup needs to be used; 0 if there is no default custom reply markup in the chat
//@draft_message A draft of a message in the chat; may be null
//@client_data Contains client-specific data associated with the chat. (For example, the chat position or local chat notification settings can be stored here.) Persistent if a message database is used
chat id:int53 type:ChatType title:string photo:chatPhoto last_message:message order:int64 is_pinned:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:notificationSettings reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
chat id:int53 type:ChatType title:string photo:chatPhoto last_message:message order:int64 is_pinned:Bool can_be_reported:Bool unread_count:int32 last_read_inbox_message_id:int53 last_read_outbox_message_id:int53 unread_mention_count:int32 notification_settings:notificationSettings reply_markup_message_id:int53 draft_message:draftMessage client_data:string = Chat;
//@description Represents a list of chats @chat_ids List of chat identifiers
chats chat_ids:vector<int53> = Chats;

Binary file not shown.

View File

@ -6071,6 +6071,23 @@ void MessagesManager::change_dialog_report_spam_state(DialogId dialog_id, bool i
}
}
bool MessagesManager::can_report_dialog(DialogId dialog_id) const {
switch (dialog_id.get_type()) {
case DialogType::User:
return td_->contacts_manager_->is_user_bot(dialog_id.get_user_id());
case DialogType::Chat:
return false;
case DialogType::Channel:
return !td_->contacts_manager_->get_channel_status(dialog_id.get_channel_id()).is_creator();
case DialogType::SecretChat:
return false;
case DialogType::None:
default:
UNREACHABLE();
return false;
}
}
void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptr<td_api::ChatReportReason> &reason,
const vector<MessageId> &message_ids, Promise<Unit> &&promise) {
Dialog *d = get_dialog_force(dialog_id);
@ -6086,23 +6103,8 @@ void MessagesManager::report_dialog(DialogId dialog_id, const tl_object_ptr<td_a
return promise.set_error(Status::Error(3, "Reason shouldn't be empty"));
}
switch (dialog_id.get_type()) {
case DialogType::Channel:
// can be reported
break;
case DialogType::User:
if (td_->contacts_manager_->is_user_bot(dialog_id.get_user_id())) {
// bots can be reported
break;
}
// fallthrough
case DialogType::Chat:
case DialogType::SecretChat:
return promise.set_error(Status::Error(3, "Chat can't be reported"));
case DialogType::None:
default:
UNREACHABLE();
return;
if (!can_report_dialog(dialog_id)) {
return promise.set_error(Status::Error(3, "Chat can't be reported"));
}
vector<MessageId> server_message_ids;
@ -12375,8 +12377,8 @@ tl_object_ptr<td_api::chat> MessagesManager::get_chat_object(const Dialog *d) {
get_chat_photo_object(td_->file_manager_.get(), get_dialog_photo(d->dialog_id)),
get_message_object(d->dialog_id, get_message(d, d->last_message_id)),
DialogDate(d->order, d->dialog_id) <= last_dialog_date_ ? d->order : 0, d->pinned_order != DEFAULT_ORDER,
d->server_unread_count + d->local_unread_count, d->last_read_inbox_message_id.get(),
d->last_read_outbox_message_id.get(), d->unread_mention_count,
can_report_dialog(d->dialog_id), d->server_unread_count + d->local_unread_count,
d->last_read_inbox_message_id.get(), d->last_read_outbox_message_id.get(), d->unread_mention_count,
get_notification_settings_object(&d->notification_settings), d->reply_markup_message_id.get(),
get_draft_message_object(d->draft_message), d->client_data);
}

View File

@ -1824,6 +1824,8 @@ class MessagesManager : public Actor {
bool can_edit_message(DialogId dialog_id, const Message *m, bool is_editing, bool only_reply_markup = false) const;
bool can_report_dialog(DialogId dialog_id) const;
MessageId get_persistent_message_id(const Dialog *d, MessageId message_id) const;
static MessageId get_replied_message_id(const Message *m);