Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
kirsan31 committed Dec 23, 2018
2 parents 6ebc0f8 + 4e692e2 commit ca0f62d
Show file tree
Hide file tree
Showing 107 changed files with 9,553 additions and 6,704 deletions.
13 changes: 0 additions & 13 deletions Telegram/Resources/basic.style
Original file line number Diff line number Diff line change
Expand Up @@ -258,19 +258,6 @@ videoIcon: icon {
};
locationSize: size(320px, 240px);

webPageLeft: 10px;
webPageBar: 2px;
webPageTitleFont: semiboldFont;
webPageTitleStyle: semiboldTextStyle;
webPageTitleOutFg: historyTextOutFg;
webPageTitleInFg: historyTextInFg;
webPageDescriptionOutFg: historyTextOutFg;
webPageDescriptionInFg: historyTextInFg;
webPageDescriptionFont: normalFont;
webPageDescriptionStyle: defaultTextStyle;
webPagePhotoSize: 100px;
webPagePhotoDelta: 8px;

mediaPlayerSuppressDuration: 150;

botDescSkip: 8px;
Expand Down
3 changes: 2 additions & 1 deletion Telegram/Resources/export_html/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,8 @@ div.selected {
background-position: 12px 12px;
background-size: 24px 24px;
}
.default .media .title {
.default .media .title,
.default .media_poll .question {
padding-top: 4px;
font-size: 14px;
}
Expand Down
21 changes: 21 additions & 0 deletions Telegram/Resources/langs/lang.strings
Original file line number Diff line number Diff line change
Expand Up @@ -1066,6 +1066,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_in_dlg_file" = "File";
"lng_in_dlg_sticker" = "Sticker";
"lng_in_dlg_sticker_emoji" = "{emoji} Sticker";
"lng_in_dlg_poll" = "Poll";

"lng_ban_user" = "Ban User";
"lng_delete_all_from" = "Delete all from this user";
Expand Down Expand Up @@ -1829,6 +1830,26 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_launch_exe_sure" = "Run";
"lng_launch_exe_dont_ask" = "Don't ask me again";

"lng_polls_anonymous" = "Anonymous Poll";
"lng_polls_closed" = "Final results";
"lng_polls_votes_count#one" = "{count} vote";
"lng_polls_votes_count#other" = "{count} votes";
"lng_polls_votes_none" = "No votes";
"lng_polls_retract" = "Retract vote";
"lng_polls_stop" = "Stop poll";
"lng_polls_stop_warning" = "If you stop this poll now, nobody will be able to vote in it anymore. This action cannot be undone.";
"lng_polls_stop_sure" = "Stop";
"lng_polls_create" = "Create poll";
"lng_polls_create_title" = "New poll";
"lng_polls_create_question" = "Question";
"lng_polls_create_question_placeholder" = "Ask a question";
"lng_polls_create_options" = "Poll options";
"lng_polls_create_option_add" = "Add an option...";
"lng_polls_create_limit#one" = "You can add {count} more option.";
"lng_polls_create_limit#other" = "You can add {count} more options.";
"lng_polls_create_maximum" = "You have added the maximum number of options.";
"lng_polls_create_button" = "Create";

// Wnd specific

"lng_wnd_choose_program_menu" = "Choose Default Program...";
Expand Down
65 changes: 48 additions & 17 deletions Telegram/Resources/scheme.tl

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion Telegram/Resources/uwp/AppX/AppxManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Identity Name="TelegramMessengerLLP.TelegramDesktop"
ProcessorArchitecture="ARCHITECTURE"
Publisher="CN=536BC709-8EE1-4478-AF22-F0F0F26FF64A"
Version="1.5.2.0" />
Version="1.5.3.0" />
<Properties>
<DisplayName>Telegram Desktop</DisplayName>
<PublisherDisplayName>Telegram Messenger LLP</PublisherDisplayName>
Expand Down
8 changes: 4 additions & 4 deletions Telegram/Resources/winrc/Telegram.rc
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ IDI_ICON1 ICON "..\\art\\icon256.ico"
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,5,2,0
PRODUCTVERSION 1,5,2,0
FILEVERSION 1,5,3,0
PRODUCTVERSION 1,5,3,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -52,10 +52,10 @@ BEGIN
BEGIN
VALUE "CompanyName", "Telegram Messenger LLP"
VALUE "FileDescription", "Telegram Desktop"
VALUE "FileVersion", "1.5.2.0"
VALUE "FileVersion", "1.5.3.0"
VALUE "LegalCopyright", "Copyright (C) 2014-2018"
VALUE "ProductName", "Telegram Desktop"
VALUE "ProductVersion", "1.5.2.0"
VALUE "ProductVersion", "1.5.3.0"
END
END
BLOCK "VarFileInfo"
Expand Down
8 changes: 4 additions & 4 deletions Telegram/Resources/winrc/Updater.rc
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ LANGUAGE LANG_ENGLISH, SUBLANG_ENGLISH_US
//

VS_VERSION_INFO VERSIONINFO
FILEVERSION 1,5,2,0
PRODUCTVERSION 1,5,2,0
FILEVERSION 1,5,3,0
PRODUCTVERSION 1,5,3,0
FILEFLAGSMASK 0x3fL
#ifdef _DEBUG
FILEFLAGS 0x1L
Expand All @@ -43,10 +43,10 @@ BEGIN
BEGIN
VALUE "CompanyName", "Telegram Messenger LLP"
VALUE "FileDescription", "Telegram Desktop Updater"
VALUE "FileVersion", "1.5.2.0"
VALUE "FileVersion", "1.5.3.0"
VALUE "LegalCopyright", "Copyright (C) 2014-2018"
VALUE "ProductName", "Telegram Desktop"
VALUE "ProductVersion", "1.5.2.0"
VALUE "ProductVersion", "1.5.3.0"
END
END
BLOCK "VarFileInfo"
Expand Down
134 changes: 128 additions & 6 deletions Telegram/SourceFiles/apiwrap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ For license and copyright information please follow this link:
#include "data/data_drafts.h"
#include "data/data_photo.h"
#include "data/data_web_page.h"
#include "data/data_poll.h"
#include "data/data_feed.h"
#include "data/data_media_types.h"
#include "data/data_sparse_ids.h"
Expand All @@ -30,7 +31,6 @@ For license and copyright information please follow this link:
#include "boxes/add_contact_box.h"
#include "history/history.h"
#include "history/history_message.h"
#include "history/history_media_types.h"
#include "history/history_item_components.h"
#include "history/feed/history_feed_section.h"
#include "storage/localstorage.h"
Expand Down Expand Up @@ -2773,7 +2773,7 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs

auto indices = base::flat_map<uint64, int>(); // copied from feedMsgs
for (auto i = 0, l = v->size(); i != l; ++i) {
const auto msgId = idFromMessage(v->at(i));
const auto msgId = IdFromMessage(v->at(i));
indices.emplace((uint64(uint32(msgId)) << 32) | uint64(i), i);
}

Expand All @@ -2797,7 +2797,7 @@ void ApiWrap::gotWebPages(ChannelData *channel, const MTPmessages_Messages &msgs
++i;
}
}
_session->data().sendWebPageGameNotifications();
_session->data().sendWebPageGamePollNotifications();
}

void ApiWrap::stickersSaveOrder() {
Expand Down Expand Up @@ -3434,8 +3434,8 @@ void ApiWrap::requestMessageAfterDate(
if (auto list = getMessagesList()) {
App::feedMsgs(*list, NewMessageExisting);
for (auto &message : *list) {
if (dateFromMessage(message) >= offsetDate) {
callback(idFromMessage(message));
if (DateFromMessage(message) >= offsetDate) {
callback(IdFromMessage(message));
return;
}
}
Expand Down Expand Up @@ -4302,7 +4302,14 @@ void ApiWrap::sendFiles(
TextWithTags &&caption,
std::shared_ptr<SendingAlbum> album,
const SendOptions &options) {
if (list.files.size() > 1 && !caption.text.isEmpty()) {
const auto isSticker = [&] {
if (list.files.empty() || type != SendMediaType::File) {
return false;
}
return list.files.front().mime == qstr("image/webp");
};
if ((list.files.size() > 1 || isSticker())
&& !caption.text.isEmpty()) {
auto message = MessageToSend(options.history);
message.textWithTags = std::move(caption);
message.replyTo = options.replyTo;
Expand Down Expand Up @@ -5329,6 +5336,121 @@ void ApiWrap::setSelfDestructDays(int days) {
_selfDestructChanges.fire_copy(days);
}

void ApiWrap::createPoll(
const PollData &data,
const SendOptions &options,
FnMut<void()> done,
FnMut<void(const RPCError &error)> fail) {
sendAction(options);

const auto history = options.history;
const auto peer = history->peer;
auto sendFlags = MTPmessages_SendMedia::Flags(0);
if (options.replyTo) {
sendFlags |= MTPmessages_SendMedia::Flag::f_reply_to_msg_id;
}
const auto channelPost = peer->isChannel() && !peer->isMegagroup();
const auto silentPost = channelPost
&& _session->data().notifySilentPosts(peer);
if (silentPost) {
sendFlags |= MTPmessages_SendMedia::Flag::f_silent;
}

const auto replyTo = options.replyTo;
history->sendRequestId = request(MTPmessages_SendMedia(
MTP_flags(sendFlags),
peer->input,
MTP_int(replyTo),
MTP_inputMediaPoll(PollDataToMTP(&data)),
MTP_string(QString()),
MTP_long(rand_value<uint64>()),
MTPReplyMarkup(),
MTPVector<MTPMessageEntity>()
)).done([=, done = std::move(done)](const MTPUpdates &result) mutable {
applyUpdates(result);
done();
}).fail([=, fail = std::move(fail)](const RPCError &error) mutable {
fail(error);
}).afterRequest(history->sendRequestId
).send();
}

void ApiWrap::sendPollVotes(
FullMsgId itemId,
const std::vector<QByteArray> &options) {
if (_pollVotesRequestIds.contains(itemId)) {
return;
}
const auto item = App::histItemById(itemId);
const auto media = item ? item->media() : nullptr;
const auto poll = media ? media->poll() : nullptr;
if (!item) {
return;
}

const auto showSending = poll && !options.empty();
const auto hideSending = [=] {
if (showSending) {
if (const auto item = App::histItemById(itemId)) {
poll->sendingVote = QByteArray();
_session->data().requestItemRepaint(item);
}
}
};
if (showSending) {
poll->sendingVote = options.front();
_session->data().requestItemRepaint(item);
}

auto prepared = QVector<MTPbytes>();
prepared.reserve(options.size());
ranges::transform(
options,
ranges::back_inserter(prepared),
[](const QByteArray &option) { return MTP_bytes(option); });
const auto requestId = request(MTPmessages_SendVote(
item->history()->peer->input,
MTP_int(item->id),
MTP_vector<MTPbytes>(prepared)
)).done([=](const MTPUpdates &result) {
_pollVotesRequestIds.erase(itemId);
hideSending();
applyUpdates(result);
}).fail([=](const RPCError &error) {
_pollVotesRequestIds.erase(itemId);
hideSending();
}).send();
_pollVotesRequestIds.emplace(itemId, requestId);
}

void ApiWrap::closePoll(FullMsgId itemId) {
if (_pollCloseRequestIds.contains(itemId)) {
return;
}
const auto item = App::histItemById(itemId);
const auto media = item ? item->media() : nullptr;
const auto poll = media ? media->poll() : nullptr;
if (!poll) {
return;
}

const auto requestId = request(MTPmessages_EditMessage(
MTP_flags(MTPmessages_EditMessage::Flag::f_media),
item->history()->peer->input,
MTP_int(item->id),
MTPstring(),
MTP_inputMediaPoll(PollDataToMTP(poll)),
MTPReplyMarkup(),
MTPVector<MTPMessageEntity>()
)).done([=](const MTPUpdates &result) {
_pollCloseRequestIds.erase(itemId);
applyUpdates(result);
}).fail([=](const RPCError &error) {
_pollCloseRequestIds.erase(itemId);
}).send();
_pollCloseRequestIds.emplace(itemId, requestId);
}

void ApiWrap::readServerHistory(not_null<History*> history) {
if (history->unreadCount()) {
readServerHistoryForce(history);
Expand Down
13 changes: 13 additions & 0 deletions Telegram/SourceFiles/apiwrap.h
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,16 @@ class ApiWrap : private MTP::Sender, private base::Subscriber {
rpl::producer<int> selfDestructValue() const;
void saveSelfDestruct(int days);

void createPoll(
const PollData &data,
const SendOptions &options,
FnMut<void()> done,
FnMut<void(const RPCError &error)> fail);
void sendPollVotes(
FullMsgId itemId,
const std::vector<QByteArray> &options);
void closePoll(FullMsgId itemId);

~ApiWrap();

private:
Expand Down Expand Up @@ -744,4 +754,7 @@ class ApiWrap : private MTP::Sender, private base::Subscriber {
std::optional<int> _selfDestructDays;
rpl::event_stream<int> _selfDestructChanges;

base::flat_map<FullMsgId, mtpRequestId> _pollVotesRequestIds;
base::flat_map<FullMsgId, mtpRequestId> _pollCloseRequestIds;

};
Loading

0 comments on commit ca0f62d

Please sign in to comment.