| 345 | } |
| 346 | |
| 347 | bool SendDice(MessageToSend &message) { |
| 348 | const auto full = QStringView(message.textWithTags.text).trimmed(); |
| 349 | auto length = 0; |
| 350 | if (!Ui::Emoji::Find(full.data(), full.data() + full.size(), &length) |
| 351 | || length != full.size() |
| 352 | || !message.textWithTags.tags.isEmpty()) { |
| 353 | return false; |
| 354 | } |
| 355 | auto &config = message.action.history->session().appConfig(); |
| 356 | static const auto hardcoded = std::vector<QString>{ |
| 357 | Stickers::DicePacks::kDiceString, |
| 358 | Stickers::DicePacks::kDartString, |
| 359 | Stickers::DicePacks::kSlotString, |
| 360 | Stickers::DicePacks::kFballString, |
| 361 | Stickers::DicePacks::kFballString + QChar(0xFE0F), |
| 362 | Stickers::DicePacks::kBballString, |
| 363 | }; |
| 364 | const auto list = config.get<std::vector<QString>>( |
| 365 | "emojies_send_dice", |
| 366 | hardcoded); |
| 367 | const auto emoji = full.toString(); |
| 368 | if (!ranges::contains(list, emoji)) { |
| 369 | return false; |
| 370 | } |
| 371 | const auto history = message.action.history; |
| 372 | const auto peer = history->peer; |
| 373 | const auto session = &history->session(); |
| 374 | const auto api = &session->api(); |
| 375 | |
| 376 | message.textWithTags = TextWithTags(); |
| 377 | message.action.clearDraft = false; |
| 378 | message.action.generateLocal = true; |
| 379 | |
| 380 | auto &action = message.action; |
| 381 | api->sendAction(action); |
| 382 | |
| 383 | const auto newId = FullMsgId( |
| 384 | peer->id, |
| 385 | session->data().nextLocalMessageId()); |
| 386 | const auto randomId = base::RandomValue<uint64>(); |
| 387 | |
| 388 | auto &histories = history->owner().histories(); |
| 389 | auto flags = NewMessageFlags(peer); |
| 390 | auto sendFlags = MTPmessages_SendMedia::Flags(0); |
| 391 | if (action.replyTo) { |
| 392 | flags |= MessageFlag::HasReplyInfo; |
| 393 | sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to; |
| 394 | } |
| 395 | const auto silentPost = ShouldSendSilent(peer, action.options); |
| 396 | InnerFillMessagePostFlags(action.options, peer, flags); |
| 397 | if (silentPost) { |
| 398 | sendFlags |= MTPmessages_SendMedia::Flag::f_silent; |
| 399 | } |
| 400 | const auto sendAs = action.options.sendAs; |
| 401 | if (sendAs) { |
| 402 | sendFlags |= MTPmessages_SendMedia::Flag::f_send_as; |
| 403 | } |
| 404 | if (action.options.scheduled) { |
no test coverage detected