2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 06:35:14 +00:00

added forwarded and from names in files / audios / videos / contacts display, grouped notification for many forwarded messages, fix of getDifference() for new_session_created

This commit is contained in:
John Preston
2015-04-23 18:50:11 +03:00
parent 0df1952a04
commit 61d1574023
20 changed files with 384 additions and 196 deletions

View File

@@ -68,7 +68,7 @@ void ConnectingWidget::onReconnect() {
MTP::restart();
}
NotifyWindow::NotifyWindow(HistoryItem *msg, int32 x, int32 y) : history(msg->history()), item(msg)
NotifyWindow::NotifyWindow(HistoryItem *msg, int32 x, int32 y, int32 fwdCount) : history(msg->history()), item(msg), fwdCount(fwdCount)
#ifdef Q_OS_WIN
, started(GetTickCount())
#endif
@@ -192,8 +192,21 @@ void NotifyWindow::updateNotifyDisplay() {
if (!App::passcoded() && cNotifyView() <= dbinvShowPreview) {
const HistoryItem *textCachedFor = 0;
Text itemTextCache(itemWidth);
bool active = false;
item->drawInDialog(p, QRect(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyItemTop + st::msgNameFont->height, itemWidth, 2 * st::dlgFont->height), active, textCachedFor, itemTextCache);
QRect r(st::notifyPhotoPos.x() + st::notifyPhotoSize + st::notifyTextLeft, st::notifyItemTop + st::msgNameFont->height, itemWidth, 2 * st::dlgFont->height);
if (fwdCount < 2) {
bool active = false;
item->drawInDialog(p, r, active, textCachedFor, itemTextCache);
} else {
p.setFont(st::dlgHistFont->f);
if (history->peer->chat) {
itemTextCache.setText(st::dlgHistFont, item->from()->name);
p.setPen(st::dlgSystemColor->p);
itemTextCache.drawElided(p, r.left(), r.top(), r.width(), st::dlgHistFont->height);
r.setTop(r.top() + st::dlgHistFont->height);
}
p.setPen(st::dlgTextColor->p);
p.drawText(r.left(), r.top() + st::dlgHistFont->ascent, lng_forward_messages(lt_count, fwdCount));
}
} else {
static QString notifyText = st::dlgHistFont->m.elidedText(lang(lng_notification_preview), Qt::ElideRight, itemWidth);
p.setPen(st::dlgSystemColor->p);
@@ -1237,7 +1250,8 @@ void Window::notifySchedule(History *history, HistoryItem *item) {
App::wnd()->getNotifySetting(MTP_inputNotifyPeer(history->peer->input));
}
int delay = 100, t = unixtime();
HistoryForwarded *fwd = item->toHistoryForwarded();
int delay = fwd ? 500 : 100, t = unixtime();
uint64 ms = getms(true);
bool isOnline = main->lastWasOnline(), otherNotOld = ((cOtherOnline() * uint64(1000)) + cOnlineCloudTimeout() > t * uint64(1000));
bool otherLaterThanMe = (cOtherOnline() * uint64(1000) + (ms - main->lastSetOnline()) > t * uint64(1000));
@@ -1354,7 +1368,9 @@ void Window::notifyShowNext(NotifyWindow *remove) {
for (NotifyWhenAlerts::iterator i = notifyWhenAlerts.begin(); i != notifyWhenAlerts.end();) {
while (!i.value().isEmpty() && i.value().begin().key() <= ms) {
NotifySettingsPtr n = i.key()->peer->notify, f = i.value().begin().value() ? i.value().begin().value()->notify : UnknownNotifySettings;
i.value().erase(i.value().begin());
while (!i.value().isEmpty() && i.value().begin().key() <= ms + 500) { // not more than one sound in 500ms from one peer - grouping
i.value().erase(i.value().begin());
}
if (n == EmptyNotifySettings || (n != UnknownNotifySettings && n->mute <= now)) {
alert = true;
} else if (f == EmptyNotifySettings || (f != UnknownNotifySettings && f->mute <= now)) { // notify by from()
@@ -1435,40 +1451,64 @@ void Window::notifyShowNext(NotifyWindow *remove) {
notifyWaitTimer.start(next - ms);
break;
} else {
if (cCustomNotifies()) {
NotifyWindow *notify = new NotifyWindow(notifyItem, x, y);
notifyWindows.push_back(notify);
psNotifyShown(notify);
--count;
} else {
psPlatformNotify(notifyItem);
}
HistoryForwarded *fwd = notifyItem->toHistoryForwarded(); // forwarded notify grouping
int32 fwdCount = 1;
uint64 ms = getms(true);
History *history = notifyItem->history();
history->skipNotification();
NotifyWhenMaps::iterator j = notifyWhenMaps.find(history);
if (j == notifyWhenMaps.end() || !history->currentNotification()) {
if (j == notifyWhenMaps.end()) {
history->clearNotifications();
} else {
HistoryItem *nextNotify = 0;
do {
history->skipNotification();
if (!history->hasNotification()) {
break;
}
j.value().remove((fwd ? fwd : notifyItem)->id);
do {
NotifyWhenMap::const_iterator k = j.value().constFind(history->currentNotification()->id);
if (k != j.value().cend()) {
nextNotify = history->currentNotification();
notifyWaiter.value().msg = k.key();
notifyWaiter.value().when = k.value();
break;
}
history->skipNotification();
} while (history->hasNotification());
if (nextNotify) {
if (fwd) {
HistoryForwarded *nextFwd = nextNotify->toHistoryForwarded();
if (nextFwd && fwd->from() == nextFwd->from() && qAbs(int64(nextFwd->date.toTime_t()) - int64(fwd->date.toTime_t())) < 2) {
fwd = nextFwd;
++fwdCount;
} else {
nextNotify = 0;
}
} else {
nextNotify = 0;
}
}
} while (nextNotify);
}
if (cCustomNotifies()) {
NotifyWindow *notify = new NotifyWindow(notifyItem, x, y, fwdCount);
notifyWindows.push_back(notify);
psNotifyShown(notify);
--count;
} else {
psPlatformNotify(notifyItem, fwdCount);
}
if (!history->hasNotification()) {
notifyWaiters.erase(notifyWaiter);
if (j != notifyWhenMaps.end()) notifyWhenMaps.erase(j);
continue;
}
j.value().remove(notifyItem->id);
do {
NotifyWhenMap::const_iterator k = j.value().constFind(history->currentNotification()->id);
if (k != j.value().cend()) {
notifyWaiter.value().msg = k.key();
notifyWaiter.value().when = k.value();
break;
}
history->skipNotification();
} while (history->currentNotification());
if (!history->currentNotification()) {
notifyWaiters.erase(notifyWaiter);
notifyWhenMaps.erase(j);
continue;
}
}
} else {
break;