Skip to content

Commit

Permalink
version 0.6.7: invokeAfter, long messages split, protocol implementat…
Browse files Browse the repository at this point in the history
…ion improvements
  • Loading branch information
john-preston committed Nov 5, 2014
1 parent cdff625 commit e0ef1d4
Show file tree
Hide file tree
Showing 40 changed files with 898 additions and 362 deletions.
4 changes: 2 additions & 2 deletions Telegram/DeployLinux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.6
AppVersion=6006
AppVersionStr=0.6.7
AppVersion=6007

if [ ! -f "./../Linux/Release/deploy/$AppVersionStr/tlinuxupd$AppVersion" ]; then
echo "tlinuxupd$AppVersion not found!";
Expand Down
4 changes: 2 additions & 2 deletions Telegram/DeployLinux32.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.6
AppVersion=6006
AppVersionStr=0.6.7
AppVersion=6007

if [ ! -f "./../Linux/Release/deploy/$AppVersionStr/tlinux32upd$AppVersion" ]; then
echo "tlinux32upd$AppVersion not found!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/DeployMacWin.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.6
AppVersion=6006
AppVersionStr=0.6.7
AppVersion=6007

if [ ! -f "./../Mac/Release/deploy/$AppVersionStr/tmacupd$AppVersion" ]; then
echo "tmacupd$AppVersion not found!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/DeployWin.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.6
AppVersion=6006
AppVersionStr=0.6.7
AppVersion=6007

if [ ! -f "./../Win32/Deploy/deploy/$AppVersionStr/tupdate$AppVersion" ]; then
echo "tupdate$AppVersion not found!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/PrepareLinux.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.6
AppVersion=6006
AppVersionStr=0.6.7
AppVersion=6007

if [ -d "./../Linux/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/PrepareLinux32.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.6
AppVersion=6006
AppVersionStr=0.6.7
AppVersion=6007

if [ -d "./../Linux/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
4 changes: 2 additions & 2 deletions Telegram/PrepareMac.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
AppVersionStr=0.6.6
AppVersion=6006
AppVersionStr=0.6.7
AppVersion=6007

if [ -d "./../Mac/Release/deploy/$AppVersionStr" ]; then
echo "Deploy folder for version $AppVersionStr already exists!"
Expand Down
6 changes: 3 additions & 3 deletions Telegram/PrepareWin.bat
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cd ..\Win32\Deploy
call ..\..\..\TelegramPrivate\Sign.bat tsetup.0.6.6.exe
call ..\..\..\TelegramPrivate\Sign.bat tsetup.0.6.7.exe
call Prepare.exe -path Telegram.exe -path Updater.exe
mkdir deploy\0.6.6\Telegram
move deploy\0.6.6\Telegram.exe deploy\0.6.6\Telegram\
mkdir deploy\0.6.7\Telegram
move deploy\0.6.7\Telegram.exe deploy\0.6.7\Telegram\
cd ..\..\Telegram
6 changes: 3 additions & 3 deletions Telegram/Setup.iss
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@

#define MyAppShortName "Telegram"
#define MyAppName "Telegram Desktop"
#define MyAppVersion "0.6.6"
#define MyAppVersionZero "0.6.6"
#define MyAppFullVersion "0.6.6.0"
#define MyAppVersion "0.6.7"
#define MyAppVersionZero "0.6.7"
#define MyAppFullVersion "0.6.7.0"
#define MyAppPublisher "Telegram Messenger LLP"
#define MyAppURL "https://tdesktop.com"
#define MyAppExeName "Telegram.exe"
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -574,7 +574,7 @@ namespace App {
const QVector<MTPcontacts_Link> &v(links.c_vector().v);
for (QVector<MTPcontacts_Link>::const_iterator i = v.cbegin(), e = v.cend(); i != e; ++i) {
const MTPDcontacts_link &dv(i->c_contacts_link());
feedUsers(MTP_vector<MTPUser>(QVector<MTPUser>(1, dv.vuser)));
feedUsers(MTP_vector<MTPUser>(1, dv.vuser));
MTPint userId(MTP_int(0));
switch (dv.vuser.type()) {
case mtpc_userEmpty: userId = dv.vuser.c_userEmpty().vid; break;
Expand Down
9 changes: 5 additions & 4 deletions Telegram/SourceFiles/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,10 +331,10 @@ void Application::writeUserConfigIn(uint64 ms) {

void Application::killDownloadSessionsStart(int32 dc) {
if (killDownloadSessionTimes.constFind(dc) == killDownloadSessionTimes.cend()) {
killDownloadSessionTimes.insert(dc, getms() + MTPKillFileSessionTimeout);
killDownloadSessionTimes.insert(dc, getms() + MTPAckSendWaiting + MTPKillFileSessionTimeout);
}
if (!killDownloadSessionsTimer.isActive()) {
killDownloadSessionsTimer.start(MTPKillFileSessionTimeout + 5);
killDownloadSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout + 5);
}
}

Expand All @@ -350,7 +350,7 @@ void Application::onWriteUserConfig() {
}

void Application::killDownloadSessions() {
uint64 ms = getms(), left = MTPKillFileSessionTimeout;
uint64 ms = getms(), left = MTPAckSendWaiting + MTPKillFileSessionTimeout;
for (QMap<int32, uint64>::iterator i = killDownloadSessionTimes.begin(); i != killDownloadSessionTimes.end(); ) {
if (i.value() <= ms) {
for (int j = 1; j < MTPDownloadSessionsCount; ++j) {
Expand Down Expand Up @@ -378,7 +378,8 @@ void Application::photoUpdated(MsgId msgId, const MTPInputFile &file) {
if (peer == App::self()->id) {
MTP::send(MTPphotos_UploadProfilePhoto(file, MTP_string(""), MTP_inputGeoPointEmpty(), MTP_inputPhotoCrop(MTP_double(0), MTP_double(0), MTP_double(100))), rpcDone(&Application::selfPhotoDone), rpcFail(&Application::peerPhotoFail, peer));
} else {
MTP::send(MTPmessages_EditChatPhoto(MTP_int(peer & 0xFFFFFFFF), MTP_inputChatUploadedPhoto(file, MTP_inputPhotoCrop(MTP_double(0), MTP_double(0), MTP_double(100)))), rpcDone(&Application::chatPhotoDone, peer), rpcFail(&Application::peerPhotoFail, peer));
History *hist = App::history(peer);
hist->sendRequestId = MTP::send(MTPmessages_EditChatPhoto(MTP_int(peer & 0xFFFFFFFF), MTP_inputChatUploadedPhoto(file, MTP_inputPhotoCrop(MTP_double(0), MTP_double(0), MTP_double(100)))), rpcDone(&Application::chatPhotoDone, peer), rpcFail(&Application::peerPhotoFail, peer), 0, 0, hist->sendRequestId);
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/boxes/addcontactbox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void AddContactBox::onSend() {
}

void AddContactBox::onSaveSelfDone(const MTPUser &user) {
App::feedUsers(MTP_vector<MTPUser>(QVector<MTPUser>(1, user)));
App::feedUsers(MTP_vector<MTPUser>(1, user));
emit closed();
}

Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/boxes/usernamebox.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ void UsernameBox::onChanged() {
}

void UsernameBox::onUpdateDone(const MTPUser &user) {
App::feedUsers(MTP_vector<MTPUser>(QVector<MTPUser>(1, user)));
App::feedUsers(MTP_vector<MTPUser>(1, user));
emit closed();
}

Expand Down
8 changes: 6 additions & 2 deletions Telegram/SourceFiles/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ Copyright (c) 2014 John Preston, https://tdesktop.com
*/
#pragma once

static const int32 AppVersion = 6006;
static const wchar_t *AppVersionStr = L"0.6.6";
static const int32 AppVersion = 6007;
static const wchar_t *AppVersionStr = L"0.6.7";

static const wchar_t *AppNameOld = L"Telegram Win (Unofficial)";
static const wchar_t *AppName = L"Telegram Desktop";
Expand All @@ -34,6 +34,7 @@ enum {
MTPIdsBufferSize = 400, // received msgIds and wereAcked msgIds count stored
MTPCheckResendTimeout = 10000, // how much time passed from send till we resend request or check it's state, in ms
MTPCheckResendWaiting = 1000, // how much time to wait for some more requests, when resending request or checking it's state, in ms
MTPAckSendWaiting = 10000, // how much time to wait for some more requests, when sending msg acks
MTPResendThreshold = 1, // how much ints should message contain for us not to resend, but to check it's state
MTPContainerLives = 600, // container lives 10 minutes in haveSent map
MTPMaxReceiveDelay = 64000, // 64 seconds
Expand Down Expand Up @@ -97,6 +98,8 @@ enum {
MinUsernameLength = 5,
MaxUsernameLength = 32,
UsernameCheckTimeout = 200,

MaxMessageSize = 4096,
};

#ifdef Q_OS_WIN
Expand Down Expand Up @@ -232,6 +235,7 @@ enum {

MaxPhotosInMemory = 50, // try to clear some memory after 50 photos are created
NoUpdatesTimeout = 180 * 1000, // if nothing is received in 3 min we reconnect
WaitForSeqTimeout = 1000, // 1s wait for skipped seq in updates

MemoryForImageCache = 64 * 1024 * 1024, // after 64mb of unpacked images we try to clear some memory
NotifyWindowsCount = 3, // 3 desktop notifies at the same time
Expand Down
2 changes: 1 addition & 1 deletion Telegram/SourceFiles/fileuploader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ void FileUploader::sendNext() {
bool killing = killSessionsTimer.isActive();
if (queue.isEmpty()) {
if (!killing) {
killSessionsTimer.start(MTPKillFileSessionTimeout);
killSessionsTimer.start(MTPAckSendWaiting + MTPKillFileSessionTimeout);
}
return;
}
Expand Down
90 changes: 90 additions & 0 deletions Telegram/SourceFiles/gui/text.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,28 @@ namespace {
}
return false;
}
inline bool chIsSentenceEnd(QChar ch) {
switch (ch.unicode()) {
case '.':
case '?':
case '!':
return true;
default:
break;
}
return false;
}
inline bool chIsSentencePartEnd(QChar ch) {
switch (ch.unicode()) {
case ',':
case ':':
case ';':
return true;
default:
break;
}
return false;
}
inline bool chIsParagraphSeparator(QChar ch) {
switch (ch.unicode()) {
case QChar::LineFeed:
Expand Down Expand Up @@ -3978,6 +4000,74 @@ QString textSearchKey(const QString &text) {
return textAccentFold(text.trimmed().toLower());
}

bool textSplit(QString &sendingText, QString &leftText, int32 limit) {
if (leftText.isEmpty() || !limit) return false;

LinkRanges lnkRanges = textParseLinks(leftText);
int32 currentLink = 0, lnkCount = lnkRanges.size();

int32 s = 0, half = limit / 2, goodLevel = 0;
for (const QChar *start = leftText.constData(), *ch = start, *end = leftText.constEnd(), *good = ch; ch != end; ++ch, ++s) {
while (currentLink < lnkCount && ch >= lnkRanges[currentLink].from + lnkRanges[currentLink].len) {
++currentLink;
}

bool inLink = (currentLink < lnkCount) && (ch > lnkRanges[currentLink].from) && (ch < lnkRanges[currentLink].from + lnkRanges[currentLink].len);
if (s > half) {
if (inLink) {
if (!goodLevel) good = ch;
} else {
if (chIsNewline(*ch)) {
if (ch + 1 < end && chIsNewline(*(ch + 1)) && goodLevel <= 7) {
goodLevel = 7;
good = ch;
} else if (goodLevel <= 6) {
goodLevel = 6;
good = ch;
}
} else if (chIsSpace(*ch)) {
if (chIsSentenceEnd(*(ch - 1)) && goodLevel <= 5) {
goodLevel = 5;
good = ch;
} else if (chIsSentencePartEnd(*(ch - 1)) && goodLevel <= 4) {
goodLevel = 4;
good = ch;
} else if (goodLevel <= 3) {
goodLevel = 3;
good = ch;
}
} else if (chIsWordSeparator(*(ch - 1)) && goodLevel <= 2) {
goodLevel = 2;
good = ch;
} else if (goodLevel <= 1) {
goodLevel = 1;
good = ch;
}
}
}
if (ch->isHighSurrogate()) {
if (ch + 1 < end && (ch + 1)->isLowSurrogate()) {
++ch;
}
} else {
if (ch + 1 < end && ((((ch->unicode() >= 48 && ch->unicode() < 58) || ch->unicode() == 35) && (ch + 1)->unicode() == 0x20E3) || (ch + 1)->unicode() == 0xFE0F)) {
if (getEmoji((ch->unicode() << 16) | (ch + 1)->unicode())) {
++ch;
++s;
}
}
}
if (s >= limit) {
sendingText = leftText.mid(0, good - start);
leftText = leftText.mid(good - start);
return true;
}
}
sendingText = leftText;
leftText = QString();
return true;
}

LinkRanges textParseLinks(const QString &text, bool rich) {
LinkRanges lnkRanges;

Expand Down
1 change: 1 addition & 0 deletions Telegram/SourceFiles/gui/text.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ QString textRichPrepare(const QString &text);
QString textOneLine(const QString &text, bool trim = true, bool rich = false);
QString textAccentFold(const QString &text);
QString textSearchKey(const QString &text);
bool textSplit(QString &sendingText, QString &leftText, int32 limit);

struct LinkRange {
LinkRange() : from(0), len(0) {
Expand Down
16 changes: 8 additions & 8 deletions Telegram/SourceFiles/history.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -874,6 +874,7 @@ History::History(const PeerId &peerId) : width(0), height(0)
, lastWidth(0)
, lastScrollTop(History::ScrollMax)
, mute(isNotifyMuted(peer->notify))
, sendRequestId(0)
, textCachedFor(0)
, lastItemTextCache(st::dlgRichMinWidth)
, posInDialogs(0)
Expand Down Expand Up @@ -1337,7 +1338,6 @@ void History::newItemAdded(HistoryItem *item) {
unregTyping(item->from());
}
if (item->out()) {
// inboxRead(false);
if (unreadBar) unreadBar->destroy();
} else if (item->unread()) {
notifies.push_back(item);
Expand Down Expand Up @@ -1529,13 +1529,13 @@ void History::addToBack(const QVector<MTPMessage> &slice) {
}
}

void History::inboxRead(bool byThisInstance) {
void History::inboxRead(HistoryItem *wasRead) {
if (unreadCount) {
if (!byThisInstance && loadedAtBottom()) App::main()->historyToDown(this);
if (wasRead && loadedAtBottom()) App::main()->historyToDown(this);
setUnreadCount(0);
}
if (!isEmpty()) {
int32 till = back()->back()->id;
int32 till = (wasRead ? wasRead : back()->back())->id;
if (inboxReadTill < till) inboxReadTill = till;
}
if (!dialogs.isEmpty()) {
Expand All @@ -1545,9 +1545,9 @@ void History::inboxRead(bool byThisInstance) {
clearNotifications();
}

void History::outboxRead() {
void History::outboxRead(HistoryItem *wasRead) {
if (!isEmpty()) {
int32 till = back()->back()->id;
int32 till = wasRead->id;
if (outboxReadTill < till) outboxReadTill = till;
}
}
Expand Down Expand Up @@ -1978,9 +1978,9 @@ HistoryItem::HistoryItem(History *history, HistoryBlock *block, MsgId msgId, boo
void HistoryItem::markRead() {
if (_unread) {
if (_out) {
_history->outboxRead();
_history->outboxRead(this);
} else {
_history->inboxRead();
_history->inboxRead(this);
}
App::main()->msgUpdated(_history->peer->id, this);
_unread = false;
Expand Down
6 changes: 4 additions & 2 deletions Telegram/SourceFiles/history.h
Original file line number Diff line number Diff line change
Expand Up @@ -657,8 +657,8 @@ struct History : public QList<HistoryBlock*> {
void newItemAdded(HistoryItem *item);
void unregTyping(UserData *from);

void inboxRead(bool byThisInstance = false);
void outboxRead();
void inboxRead(HistoryItem *wasRead);
void outboxRead(HistoryItem *wasRead);

void setUnreadCount(int32 newUnreadCount, bool psUpdate = true);
void setMsgCount(int32 newMsgCount);
Expand Down Expand Up @@ -732,6 +732,8 @@ struct History : public QList<HistoryBlock*> {
int32 lastWidth, lastScrollTop;
bool mute;

mtpRequestId sendRequestId;

// for dialog drawing
Text nameText;
void updateNameText();
Expand Down
Loading

0 comments on commit e0ef1d4

Please sign in to comment.