2
0
mirror of https://github.com/telegramdesktop/tdesktop synced 2025-08-31 06:26:18 +00:00

version 0.8.8.dev - audio listened status, photo caption display, map places name-address display, gray muted badges, invite links support, some fixes

This commit is contained in:
John Preston
2015-04-30 16:53:36 +03:00
parent aeb2ec68ef
commit fb32c5bcd1
29 changed files with 2076 additions and 477 deletions

View File

@@ -376,6 +376,7 @@ _failDifferenceTimeout(1), _lastUpdateTime(0), _cachedX(0), _cachedY(0), _backgr
connect(audioVoice(), SIGNAL(updated(AudioData*)), this, SLOT(audioPlayProgress(AudioData*)));
connect(audioVoice(), SIGNAL(stopped(AudioData*)), this, SLOT(audioPlayProgress(AudioData*)));
}
connect(&_updateMutedTimer, SIGNAL(timeout()), this, SLOT(onUpdateMuted()));
_webPageUpdater.setSingleShot(true);
connect(&_webPageUpdater, SIGNAL(timeout()), this, SLOT(webPagesUpdate()));
@@ -525,6 +526,9 @@ void MainWidget::webPageUpdated(WebPageData *data) {
}
void MainWidget::webPagesUpdate() {
if (_webPagesUpdated.isEmpty()) return;
_webPageUpdater.stop();
const WebPageItems &items(App::webPageItems());
for (QMap<WebPageId, bool>::const_iterator i = _webPagesUpdated.cbegin(), e = _webPagesUpdated.cend(); i != e; ++i) {
WebPageItems::const_iterator j = items.constFind(App::webPage(i.key()));
@@ -538,6 +542,17 @@ void MainWidget::webPagesUpdate() {
_webPagesUpdated.clear();
}
void MainWidget::updateMutedIn(int32 seconds) {
if (seconds > 86400) seconds = 86400;
int32 ms = seconds * 1000;
if (_updateMutedTimer.isActive() && _updateMutedTimer.remainingTime() <= ms) return;
_updateMutedTimer.start(ms);
}
void MainWidget::onUpdateMuted() {
App::updateMuted();
}
void MainWidget::onShareContact(const PeerId &peer, UserData *contact) {
history.onShareContact(peer, contact);
}
@@ -705,7 +720,7 @@ void MainWidget::deleteHistoryPart(PeerData *peer, const MTPmessages_AffectedHis
}
void MainWidget::deleteMessages(const QVector<MTPint> &ids) {
MTP::send(MTPmessages_DeleteMessages(MTP_vector<MTPint>(ids)), rpcDone(&MainWidget::msgsWereDeleted));
MTP::send(MTPmessages_DeleteMessages(MTP_vector<MTPint>(ids)), rpcDone(&MainWidget::messagesAffected));
}
void MainWidget::deletedContact(UserData *user, const MTPcontacts_Link &result) {
@@ -1277,7 +1292,7 @@ void MainWidget::partWasRead(PeerData *peer, const MTPmessages_AffectedHistory &
}
}
void MainWidget::msgsWereDeleted(const MTPmessages_AffectedMessages &result) {
void MainWidget::messagesAffected(const MTPmessages_AffectedMessages &result) {
const MTPDmessages_affectedMessages &d(result.c_messages_affectedMessages());
updPtsUpdated(d.vpts.v, d.vpts_count.v);
}
@@ -1449,6 +1464,38 @@ void MainWidget::documentLoadRetry() {
if (document) document->save(failedFileName);
}
void MainWidget::audioMarkRead(AudioData *data) {
const AudioItems &items(App::audioItems());
AudioItems::const_iterator i = items.constFind(data);
if (i != items.cend()) {
mediaMarkRead(i.value());
}
}
void MainWidget::videoMarkRead(VideoData *data) {
const VideoItems &items(App::videoItems());
VideoItems::const_iterator i = items.constFind(data);
if (i != items.cend()) {
mediaMarkRead(i.value());
}
}
void MainWidget::mediaMarkRead(const HistoryItemsMap &items) {
QVector<MTPint> markedIds;
markedIds.reserve(items.size());
for (HistoryItemsMap::const_iterator j = items.cbegin(), e = items.cend(); j != e; ++j) {
if (!j.key()->out() && j.key()->isMediaUnread()) {
j.key()->markMediaRead();
if (j.key()->id > 0) {
markedIds.push_back(MTP_int(j.key()->id));
}
}
}
if (!markedIds.isEmpty()) {
MTP::send(MTPmessages_ReadMessageContents(MTP_vector<MTPint>(markedIds)), rpcDone(&MainWidget::messagesAffected));
}
}
void MainWidget::onParentResize(const QSize &newSize) {
resize(newSize);
}
@@ -2300,7 +2347,7 @@ void MainWidget::gotDifference(const MTPupdates_Difference &diff) {
updInited = true;
MTP_LOG(0, ("getDifference { good - after a slice of difference was received }"));
MTP_LOG(0, ("getDifference { good - after a slice of difference was received }%1").arg(cTestMode() ? " TESTMODE" : ""));
getDifference();
} break;
case mtpc_updates_difference: {
@@ -2378,7 +2425,7 @@ bool MainWidget::failDifference(const RPCError &error) {
void MainWidget::getDifferenceForce() {
if (MTP::authedId()) {
updInited = true;
MTP_LOG(0, ("getDifference { force - after get difference failed }"));
MTP_LOG(0, ("getDifference { force - after get difference failed }%1").arg(cTestMode() ? " TESTMODE" : ""));
getDifference();
}
}
@@ -2444,6 +2491,7 @@ void MainWidget::openLocalUrl(const QString &url) {
} else if (u.startsWith(QLatin1String("tg://join"), Qt::CaseInsensitive)) {
QRegularExpressionMatch m = QRegularExpression(qsl("^tg://join/?\\?invite=([a-zA-Z0-9\\.\\_]+)$"), QRegularExpression::CaseInsensitiveOption).match(u);
if (m.hasMatch()) {
joinGroupByHash(m.captured(1));
}
}
}
@@ -2461,6 +2509,10 @@ void MainWidget::openUserByName(const QString &username, bool toProfile) {
}
}
void MainWidget::joinGroupByHash(const QString &hash) {
MTP::send(MTPmessages_CheckChatInvite(MTP_string(hash)), rpcDone(&MainWidget::inviteCheckDone, hash), rpcFail(&MainWidget::inviteCheckFail));
}
void MainWidget::usernameResolveDone(bool toProfile, const MTPUser &user) {
App::wnd()->hideLayer();
UserData *u = App::feedUsers(MTP_vector<MTPUser>(1, user));
@@ -2480,6 +2532,83 @@ bool MainWidget::usernameResolveFail(QString name, const RPCError &error) {
return true;
}
void MainWidget::inviteCheckDone(QString hash, const MTPChatInvite &invite) {
switch (invite.type()) {
case mtpc_chatInvite: {
const MTPDchatInvite &d(invite.c_chatInvite());
ConfirmBox *box = new ConfirmBox(lng_group_invite_want_join(lt_title, qs(d.vtitle)), lang(lng_group_invite_join));
_inviteHash = hash;
connect(box, SIGNAL(confirmed()), this, SLOT(onInviteImport()));
App::wnd()->showLayer(box);
} break;
case mtpc_chatInviteAlready: {
const MTPDchatInviteAlready &d(invite.c_chatInviteAlready());
ChatData *chat = App::feedChats(MTP_vector<MTPChat>(1, d.vchat));
if (chat) {
if (chat->left) {
ConfirmBox *box = new ConfirmBox(lng_group_invite_want_join(lt_title, chat->name), lang(lng_group_invite_join));
_inviteHash = '/' + QString::number(chat->id);
connect(box, SIGNAL(confirmed()), this, SLOT(onInviteImport()));
App::wnd()->showLayer(box);
} else {
showPeer(chat->id, 0, false, true);
}
}
} break;
}
}
bool MainWidget::inviteCheckFail(const RPCError &error) {
if (error.type().startsWith(qsl("FLOOD_WAIT_"))) return false;
if (error.code() == 400) {
App::wnd()->showLayer(new ConfirmBox(lang(lng_group_invite_bad_link), true));
}
return true;
}
void MainWidget::onInviteImport() {
if (_inviteHash.isEmpty()) return;
if (_inviteHash.at(0) == '/') {
PeerId peer = _inviteHash.midRef(1).toULongLong();
MTP::send(MTPmessages_AddChatUser(MTP_int(peer & 0xFFFFFFFF), App::self()->inputUser, MTP_int(ForwardOnAdd)), rpcDone(&MainWidget::inviteImportDone), rpcFail(&MainWidget::inviteImportFail), 0, 5);
} else {
MTP::send(MTPmessages_ImportChatInvite(MTP_string(_inviteHash)), rpcDone(&MainWidget::inviteImportDone), rpcFail(&MainWidget::inviteImportFail));
}
}
void MainWidget::inviteImportDone(const MTPUpdates &updates) {
App::main()->sentUpdatesReceived(updates);
App::wnd()->hideLayer();
const QVector<MTPChat> *v = 0;
switch (updates.type()) {
case mtpc_updates: v = &updates.c_updates().vchats.c_vector().v; break;
case mtpc_updatesCombined: v = &updates.c_updatesCombined().vchats.c_vector().v; break;
case mtpc_updateShort: {
} break;
case mtpc_updateShortMessage: {
} break;
case mtpc_updateShortChatMessage: {
} break;
case mtpc_updatesTooLong: {
} break;
}
if (v && !v->isEmpty() && v->front().type() == mtpc_chat) {
App::main()->showPeer(App::peerFromChat(v->front().c_chat().vid.v));
}
}
bool MainWidget::inviteImportFail(const RPCError &error) {
if (error.type().startsWith(qsl("FLOOD_WAIT_"))) return false;
if (error.code() == 400) {
App::wnd()->showLayer(new ConfirmBox(lang(error.type() == qsl("USERS_TOO_MUCH") ? lng_group_invite_no_room : lng_group_invite_bad_link), true), App::wnd()->layerShown());
}
return true;
}
void MainWidget::startFull(const MTPVector<MTPUser> &users) {
const QVector<MTPUser> &v(users.c_vector().v);
if (v.isEmpty() || v[0].type() != mtpc_userSelf) { // wtf?..
@@ -2502,7 +2631,9 @@ void MainWidget::applyNotifySetting(const MTPNotifyPeer &peer, const MTPPeerNoti
delete data->notify;
}
data->notify = EmptyNotifySettings;
App::history(data->id)->setMute(false);
App::unregMuted(data);
History *h = App::history(data->id);
h->setMute(false);
}
} break;
}
@@ -2510,16 +2641,15 @@ void MainWidget::applyNotifySetting(const MTPNotifyPeer &peer, const MTPPeerNoti
case mtpc_peerNotifySettings: {
const MTPDpeerNotifySettings &d(settings.c_peerNotifySettings());
NotifySettingsPtr setTo = UnknownNotifySettings;
PeerId peerId = 0;
PeerData *data = 0;
switch (peer.type()) {
case mtpc_notifyAll: setTo = globalNotifyAllPtr = &globalNotifyAll; break;
case mtpc_notifyUsers: setTo = globalNotifyUsersPtr = &globalNotifyUsers; break;
case mtpc_notifyChats: setTo = globalNotifyChatsPtr = &globalNotifyChats; break;
case mtpc_notifyPeer: {
PeerData *data = App::peerLoaded(App::peerFromMTP(peer.c_notifyPeer().vpeer));
data = App::peerLoaded(App::peerFromMTP(peer.c_notifyPeer().vpeer));
if (!data) break;
peerId = data->id;
if (data->notify == UnknownNotifySettings || data->notify == EmptyNotifySettings) {
data->notify = new NotifySettings();
}
@@ -2532,11 +2662,13 @@ void MainWidget::applyNotifySetting(const MTPNotifyPeer &peer, const MTPPeerNoti
setTo->sound = d.vsound.c_string().v;
setTo->previews = d.vshow_previews.v;
setTo->events = d.vevents_mask.v;
if (peerId) {
if (!history) history = App::history(peerId);
if (isNotifyMuted(setTo)) {
if (data) {
if (!history) history = App::history(data->id);
int32 changeIn = 0;
if (isNotifyMuted(setTo, &changeIn)) {
App::wnd()->notifyClear(history);
history->setMute(true);
App::regMuted(data, changeIn);
} else {
history->setMute(false);
}
@@ -2577,18 +2709,24 @@ bool MainWidget::failNotifySetting(MTPInputNotifyPeer peer, const RPCError &erro
void MainWidget::updateNotifySetting(PeerData *peer, bool enabled) {
updateNotifySettingPeers.insert(peer);
int32 muteFor = 86400 * 365;
if (peer->notify == EmptyNotifySettings) {
if (!enabled) {
peer->notify = new NotifySettings();
peer->notify->sound = "";
peer->notify->mute = unixtime() + 86400 * 365;
peer->notify->mute = unixtime() + muteFor;
}
} else {
if (peer->notify == UnknownNotifySettings) {
peer->notify = new NotifySettings();
}
peer->notify->sound = enabled ? "default" : "";
peer->notify->mute = enabled ? 0 : (unixtime() + 86400 * 365);
peer->notify->mute = enabled ? 0 : (unixtime() + muteFor);
}
if (!enabled) {
App::regMuted(peer, muteFor + 1);
} else {
App::unregMuted(peer);
}
App::history(peer->id)->setMute(!enabled);
updateNotifySettingTimer.start(NotifySettingSaveTimeout);
@@ -2760,7 +2898,7 @@ void MainWidget::updateReceived(const mtpPrime *from, const mtpPrime *end) {
if (mtpTypeId(*from) == mtpc_new_session_created) {
MTPNewSession newSession(from, end);
updSeq = 0;
MTP_LOG(0, ("getDifference { after new_session_created }"));
MTP_LOG(0, ("getDifference { after new_session_created }%1").arg(cTestMode() ? " TESTMODE" : ""));
return getDifference();
} else {
try {
@@ -2823,7 +2961,7 @@ void MainWidget::handleUpdates(const MTPUpdates &updates) {
case mtpc_updateShortMessage: {
const MTPDupdateShortMessage &d(updates.c_updateShortMessage());
if (!App::userLoaded(d.vuser_id.v) || (d.has_fwd_from_id() && !App::userLoaded(d.vfwd_from_id.v))) {
MTP_LOG(0, ("getDifference { good - getting user for updateShortMessage }"));
MTP_LOG(0, ("getDifference { good - getting user for updateShortMessage }%1").arg(cTestMode() ? " TESTMODE" : ""));
return getDifference();
}
if (!updPtsUpdated(d.vpts.v, d.vpts_count.v)) {
@@ -2842,7 +2980,7 @@ void MainWidget::handleUpdates(const MTPUpdates &updates) {
case mtpc_updateShortChatMessage: {
const MTPDupdateShortChatMessage &d(updates.c_updateShortChatMessage());
if (!App::chatLoaded(d.vchat_id.v) || !App::userLoaded(d.vfrom_id.v) || (d.has_fwd_from_id() && !App::userLoaded(d.vfwd_from_id.v))) {
MTP_LOG(0, ("getDifference { good - getting user for updateShortChatMessage }"));
MTP_LOG(0, ("getDifference { good - getting user for updateShortChatMessage }%1").arg(cTestMode() ? " TESTMODE" : ""));
return getDifference();
}
if (!updPtsUpdated(d.vpts.v, d.vpts_count.v)) {
@@ -2858,7 +2996,7 @@ void MainWidget::handleUpdates(const MTPUpdates &updates) {
} break;
case mtpc_updatesTooLong: {
MTP_LOG(0, ("getDifference { good - updatesTooLong received }"));
MTP_LOG(0, ("getDifference { good - updatesTooLong received }%1").arg(cTestMode() ? " TESTMODE" : ""));
return getDifference();
} break;
}
@@ -2916,13 +3054,21 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
}
} break;
case mtpc_updateReadMessages: {
const MTPDupdateReadMessages &d(update.c_updateReadMessages());
case mtpc_updateReadMessagesContents: {
const MTPDupdateReadMessagesContents &d(update.c_updateReadMessagesContents());
if (!updPtsUpdated(d.vpts.v, d.vpts_count.v)) {
_byPtsUpdate.insert(ptsKey(SkippedUpdate), update);
return;
}
App::feedWereRead(d.vmessages.c_vector().v);
const QVector<MTPint> &v(d.vmessages.c_vector().v);
for (int32 i = 0, l = v.size(); i < l; ++i) {
if (HistoryItem *item = App::histItemById(v.at(i).v)) {
if (item->isMediaUnread()) {
item->markMediaRead();
msgUpdated(item->history()->peer->id, item);
}
}
}
} break;
case mtpc_updateReadHistoryInbox: {
@@ -2949,6 +3095,7 @@ void MainWidget::feedUpdate(const MTPUpdate &update) {
const MTPDupdateWebPage &d(update.c_updateWebPage());
App::feedWebPage(d.vwebpage);
history.updatePreview();
webPagesUpdate();
} break;
case mtpc_updateDeleteMessages: {