mirror of https://github.com/procxx/kepka.git
				
				
				
			Fixed display of scheduled until online message dates.
This commit is contained in:
		
							parent
							
								
									c3b01d8573
								
							
						
					
					
						commit
						8ebbeb5274
					
				|  | @ -1294,6 +1294,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| 
 | 
 | ||||||
| "lng_scheduled_messages" = "Scheduled Messages"; | "lng_scheduled_messages" = "Scheduled Messages"; | ||||||
| "lng_reminder_messages" = "Reminders"; | "lng_reminder_messages" = "Reminders"; | ||||||
|  | "lng_scheduled_date" = "Scheduled for {date}"; | ||||||
|  | "lng_scheduled_date_until_online" = "Scheduled until online"; | ||||||
| "lng_scheduled_send_now" = "Send message now?"; | "lng_scheduled_send_now" = "Send message now?"; | ||||||
| "lng_scheduled_send_now_many#one" = "Send {count} message now?"; | "lng_scheduled_send_now_many#one" = "Send {count} message now?"; | ||||||
| "lng_scheduled_send_now_many#other" = "Send {count} messages now?"; | "lng_scheduled_send_now_many#other" = "Send {count} messages now?"; | ||||||
|  |  | ||||||
|  | @ -43,6 +43,8 @@ public: | ||||||
| 	[[nodiscard]] rpl::producer<> updates(not_null<History*> history); | 	[[nodiscard]] rpl::producer<> updates(not_null<History*> history); | ||||||
| 	[[nodiscard]] Data::MessagesSlice list(not_null<History*> history); | 	[[nodiscard]] Data::MessagesSlice list(not_null<History*> history); | ||||||
| 
 | 
 | ||||||
|  | 	static constexpr auto kScheduledUntilOnlineTimestamp = TimeId(0x7FFFFFFE); | ||||||
|  | 
 | ||||||
| private: | private: | ||||||
| 	using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>; | 	using OwnedItem = std::unique_ptr<HistoryItem, HistoryItem::Destroyer>; | ||||||
| 	struct List { | 	struct List { | ||||||
|  |  | ||||||
|  | @ -149,6 +149,8 @@ historyReceivedIcon: icon {{ "history_received", historyOutIconFg, point(2px, 4p | ||||||
| historyReceivedSelectedIcon: icon {{ "history_received", historyOutIconFgSelected, point(2px, 4px) }}; | historyReceivedSelectedIcon: icon {{ "history_received", historyOutIconFgSelected, point(2px, 4px) }}; | ||||||
| historyReceivedInvertedIcon: icon {{ "history_received", historyIconFgInverted, point(2px, 4px) }}; | historyReceivedInvertedIcon: icon {{ "history_received", historyIconFgInverted, point(2px, 4px) }}; | ||||||
| 
 | 
 | ||||||
|  | historyScheduledUntilOnlineStateSpace: 17px; | ||||||
|  | 
 | ||||||
| historyViewsSpace: 11px; | historyViewsSpace: 11px; | ||||||
| historyViewsWidth: 20px; | historyViewsWidth: 20px; | ||||||
| historyViewsTop: -15px; | historyViewsTop: -15px; | ||||||
|  |  | ||||||
|  | @ -33,6 +33,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include "window/window_session_controller.h" | #include "window/window_session_controller.h" | ||||||
| #include "core/crash_reports.h" | #include "core/crash_reports.h" | ||||||
| #include "base/unixtime.h" | #include "base/unixtime.h" | ||||||
|  | #include "data/data_scheduled_messages.h" // kScheduledUntilOnlineTimestamp
 | ||||||
| #include "data/data_session.h" | #include "data/data_session.h" | ||||||
| #include "data/data_messages.h" | #include "data/data_messages.h" | ||||||
| #include "data/data_media_types.h" | #include "data/data_media_types.h" | ||||||
|  | @ -862,6 +863,21 @@ QDateTime ItemDateTime(not_null<const HistoryItem*> item) { | ||||||
| 	return base::unixtime::parse(item->date()); | 	return base::unixtime::parse(item->date()); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | QString ItemDateText(not_null<const HistoryItem*> item, bool isUntilOnline) { | ||||||
|  | 	const auto dateText = langDayOfMonthFull(ItemDateTime(item).date()); | ||||||
|  | 	return !item->isScheduled() | ||||||
|  | 		? dateText | ||||||
|  | 		: isUntilOnline | ||||||
|  | 			? tr::lng_scheduled_date_until_online(tr::now) | ||||||
|  | 			: tr::lng_scheduled_date(tr::now, lt_date, dateText); | ||||||
|  | } | ||||||
|  | 
 | ||||||
|  | bool IsItemScheduledUntilOnline(not_null<const HistoryItem*> item) { | ||||||
|  | 	return item->isScheduled() | ||||||
|  | 		&& (item->date() == | ||||||
|  | 			Data::ScheduledMessages::kScheduledUntilOnlineTimestamp); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| ClickHandlerPtr goToMessageClickHandler( | ClickHandlerPtr goToMessageClickHandler( | ||||||
| 		not_null<HistoryItem*> item, | 		not_null<HistoryItem*> item, | ||||||
| 		FullMsgId returnToId) { | 		FullMsgId returnToId) { | ||||||
|  |  | ||||||
|  | @ -374,6 +374,8 @@ private: | ||||||
| }; | }; | ||||||
| 
 | 
 | ||||||
| QDateTime ItemDateTime(not_null<const HistoryItem*> item); | QDateTime ItemDateTime(not_null<const HistoryItem*> item); | ||||||
|  | QString ItemDateText(not_null<const HistoryItem*> item, bool isUntilOnline); | ||||||
|  | bool IsItemScheduledUntilOnline(not_null<const HistoryItem*> item); | ||||||
| 
 | 
 | ||||||
| ClickHandlerPtr goToMessageClickHandler( | ClickHandlerPtr goToMessageClickHandler( | ||||||
| 	not_null<PeerData*> peer, | 	not_null<PeerData*> peer, | ||||||
|  |  | ||||||
|  | @ -185,8 +185,8 @@ void UnreadBar::paint(Painter &p, int y, int w) const { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| 
 | 
 | ||||||
| void DateBadge::init(const QDateTime &date) { | void DateBadge::init(const QString &date) { | ||||||
| 	text = langDayOfMonthFull(date.date()); | 	text = date; | ||||||
| 	width = st::msgServiceFont->width(text); | 	width = st::msgServiceFont->width(text); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | @ -207,7 +207,8 @@ Element::Element( | ||||||
| 	not_null<HistoryItem*> data) | 	not_null<HistoryItem*> data) | ||||||
| : _delegate(delegate) | : _delegate(delegate) | ||||||
| , _data(data) | , _data(data) | ||||||
| , _dateTime(ItemDateTime(data)) | , _isScheduledUntilOnline(IsItemScheduledUntilOnline(data)) | ||||||
|  | , _dateTime(_isScheduledUntilOnline ? QDateTime() : ItemDateTime(data)) | ||||||
| , _context(delegate->elementContext()) { | , _context(delegate->elementContext()) { | ||||||
| 	history()->owner().registerItemView(this); | 	history()->owner().registerItemView(this); | ||||||
| 	refreshMedia(); | 	refreshMedia(); | ||||||
|  | @ -505,7 +506,7 @@ void Element::setDisplayDate(bool displayDate) { | ||||||
| 	const auto item = data(); | 	const auto item = data(); | ||||||
| 	if (displayDate && !Has<DateBadge>()) { | 	if (displayDate && !Has<DateBadge>()) { | ||||||
| 		AddComponents(DateBadge::Bit()); | 		AddComponents(DateBadge::Bit()); | ||||||
| 		Get<DateBadge>()->init(dateTime()); | 		Get<DateBadge>()->init(ItemDateText(item, _isScheduledUntilOnline)); | ||||||
| 		setPendingResize(); | 		setPendingResize(); | ||||||
| 	} else if (!displayDate && Has<DateBadge>()) { | 	} else if (!displayDate && Has<DateBadge>()) { | ||||||
| 		RemoveComponents(DateBadge::Bit()); | 		RemoveComponents(DateBadge::Bit()); | ||||||
|  |  | ||||||
|  | @ -122,7 +122,7 @@ struct UnreadBar : public RuntimeComponent<UnreadBar, Element> { | ||||||
| // Any HistoryView::Element can have this Component for
 | // Any HistoryView::Element can have this Component for
 | ||||||
| // displaying the day mark above the message.
 | // displaying the day mark above the message.
 | ||||||
| struct DateBadge : public RuntimeComponent<DateBadge, Element> { | struct DateBadge : public RuntimeComponent<DateBadge, Element> { | ||||||
| 	void init(const QDateTime &date); | 	void init(const QString &date); | ||||||
| 
 | 
 | ||||||
| 	int height() const; | 	int height() const; | ||||||
| 	void paint(Painter &p, int y, int w) const; | 	void paint(Painter &p, int y, int w) const; | ||||||
|  | @ -310,6 +310,7 @@ private: | ||||||
| 	const not_null<ElementDelegate*> _delegate; | 	const not_null<ElementDelegate*> _delegate; | ||||||
| 	const not_null<HistoryItem*> _data; | 	const not_null<HistoryItem*> _data; | ||||||
| 	std::unique_ptr<Media> _media; | 	std::unique_ptr<Media> _media; | ||||||
|  | 	bool _isScheduledUntilOnline = false; | ||||||
| 	const QDateTime _dateTime; | 	const QDateTime _dateTime; | ||||||
| 
 | 
 | ||||||
| 	int _y = 0; | 	int _y = 0; | ||||||
|  |  | ||||||
|  | @ -1391,7 +1391,7 @@ void ListWidget::paintEvent(QPaintEvent *e) { | ||||||
| 					} else { | 					} else { | ||||||
| 						ServiceMessagePainter::paintDate( | 						ServiceMessagePainter::paintDate( | ||||||
| 							p, | 							p, | ||||||
| 							view->dateTime(), | 							ItemDateText(view->data(), IsItemScheduledUntilOnline(view->data())), | ||||||
| 							dateY, | 							dateY, | ||||||
| 							width); | 							width); | ||||||
| 					} | 					} | ||||||
|  |  | ||||||
|  | @ -1269,7 +1269,12 @@ int Message::infoWidth() const { | ||||||
| 			result += st::historySendStateSpace; | 			result += st::historySendStateSpace; | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	if (hasOutLayout()) { | 
 | ||||||
|  | 	// When message is scheduled until online, time is not displayed,
 | ||||||
|  | 	// so message should have less space.
 | ||||||
|  | 	if (!item->_timeWidth) { | ||||||
|  | 		result += st::historyScheduledUntilOnlineStateSpace; | ||||||
|  | 	} else if (hasOutLayout()) { | ||||||
| 		result += st::historySendStateSpace; | 		result += st::historySendStateSpace; | ||||||
| 	} | 	} | ||||||
| 	return result; | 	return result; | ||||||
|  |  | ||||||
|  | @ -199,6 +199,10 @@ void ServiceMessagePainter::paintDate(Painter &p, const QDateTime &date, int y, | ||||||
| 	paintPreparedDate(p, dateText, dateTextWidth, y, w); | 	paintPreparedDate(p, dateText, dateTextWidth, y, w); | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
|  | void ServiceMessagePainter::paintDate(Painter &p, const QString &dateText, int y, int w) { | ||||||
|  | 	paintPreparedDate(p, dateText, st::msgServiceFont->width(dateText), y, w); | ||||||
|  | } | ||||||
|  | 
 | ||||||
| void ServiceMessagePainter::paintDate(Painter &p, const QString &dateText, int dateTextWidth, int y, int w) { | void ServiceMessagePainter::paintDate(Painter &p, const QString &dateText, int dateTextWidth, int y, int w) { | ||||||
| 	paintPreparedDate(p, dateText, dateTextWidth, y, w); | 	paintPreparedDate(p, dateText, dateTextWidth, y, w); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -63,6 +63,7 @@ struct PaintContext { | ||||||
| class ServiceMessagePainter { | class ServiceMessagePainter { | ||||||
| public: | public: | ||||||
| 	static void paintDate(Painter &p, const QDateTime &date, int y, int w); | 	static void paintDate(Painter &p, const QDateTime &date, int y, int w); | ||||||
|  | 	static void paintDate(Painter &p, const QString &dateText, int y, int w); | ||||||
| 	static void paintDate(Painter &p, const QString &dateText, int dateTextWidth, int y, int w); | 	static void paintDate(Painter &p, const QString &dateText, int dateTextWidth, int y, int w); | ||||||
| 
 | 
 | ||||||
| 	static void paintBubble(Painter &p, int x, int y, int w, int h); | 	static void paintBubble(Painter &p, int x, int y, int w, int h); | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue