diff --git a/Telegram/SourceFiles/calls/calls_panel.cpp b/Telegram/SourceFiles/calls/calls_panel.cpp
index 30c3c0c5e..d0a4ee271 100644
--- a/Telegram/SourceFiles/calls/calls_panel.cpp
+++ b/Telegram/SourceFiles/calls/calls_panel.cpp
@@ -478,7 +478,7 @@ void Panel::createUserpicCache(ImagePtr image) {
 		filled.setDevicePixelRatio(cRetinaFactor());
 		{
 			Painter p(&filled);
-			EmptyUserpic(_user->colorIndex(), _user->name).paintSquare(p, 0, 0, st::callWidth, st::callWidth);
+			EmptyUserpic(_user->id, _user->name).paintSquare(p, 0, 0, st::callWidth, st::callWidth);
 		}
 		Images::prepareRound(filled, ImageRoundRadius::Large, ImageRoundCorner::TopLeft | ImageRoundCorner::TopRight);
 		_userPhoto = App::pixmapFromImageInPlace(std::move(filled));
diff --git a/Telegram/SourceFiles/data/data_peer.cpp b/Telegram/SourceFiles/data/data_peer.cpp
index 86e1c684a..885d2d730 100644
--- a/Telegram/SourceFiles/data/data_peer.cpp
+++ b/Telegram/SourceFiles/data/data_peer.cpp
@@ -57,10 +57,8 @@ ImagePtr generateUserpicImage(const style::icon &icon) {
 	return ImagePtr(App::pixmapFromImageInPlace(std::move(data)), "PNG");
 }
 
-} // namespace
-
-style::color peerUserpicColor(int index) {
-	static style::color peerColors[kUserColorsCount] = {
+style::color PeerUserpicColor(PeerId peerId) {
+	const style::color colors[] = {
 		st::historyPeer1UserpicBg,
 		st::historyPeer2UserpicBg,
 		st::historyPeer3UserpicBg,
@@ -70,12 +68,25 @@ style::color peerUserpicColor(int index) {
 		st::historyPeer7UserpicBg,
 		st::historyPeer8UserpicBg,
 	};
-	return peerColors[index];
+	return colors[PeerColorIndex(peerId)];
+}
+
+} // namespace
+
+int PeerColorIndex(int32 bareId) {
+	const auto index = std::abs(bareId) % 7;
+	const int map[] = { 0, 7, 4, 1, 6, 3, 5 };
+	return map[index];
+}
+
+int PeerColorIndex(PeerId peerId) {
+	return PeerColorIndex(peerToBareInt(peerId));
 }
 
 class EmptyUserpic::Impl {
 public:
-	Impl(int index, const QString &name) : _color(peerUserpicColor(index)) {
+	Impl(PeerId peerId, const QString &name)
+	: _color(PeerUserpicColor(peerId)) {
 		fillString(name);
 	}
 
@@ -196,11 +207,16 @@ void EmptyUserpic::Impl::fillString(const QString &name) {
 
 EmptyUserpic::EmptyUserpic() = default;
 
-EmptyUserpic::EmptyUserpic(int index, const QString &name) : _impl(std::make_unique<Impl>(index, name)) {
+EmptyUserpic::EmptyUserpic(PeerId peerId, const QString &name)
+: _impl(std::make_unique<Impl>(peerId, name)) {
 }
 
-void EmptyUserpic::set(int index, const QString &name) {
-	_impl = std::make_unique<Impl>(index, name);
+EmptyUserpic::EmptyUserpic(const QString &nonce, const QString &name)
+: EmptyUserpic(qHash(nonce), name) {
+}
+
+void EmptyUserpic::set(PeerId peerId, const QString &name) {
+	_impl = std::make_unique<Impl>(peerId, name);
 }
 
 void EmptyUserpic::clear() {
@@ -269,10 +285,9 @@ void PeerClickHandler::onClick(Qt::MouseButton button) const {
 }
 
 PeerData::PeerData(const PeerId &id)
-: id(id)
-, _colorIndex(peerColorIndex(id)) {
+: id(id) {
 	nameText.setText(st::msgNameStyle, QString(), _textNameOptions);
-	_userpicEmpty.set(_colorIndex, QString());
+	_userpicEmpty.set(id, QString());
 }
 
 void PeerData::updateNameDelayed(
@@ -298,7 +313,7 @@ void PeerData::updateNameDelayed(
 	name = newName;
 	nameText.setText(st::msgNameStyle, name, _textNameOptions);
 	if (useEmptyUserpic()) {
-		_userpicEmpty.set(_colorIndex, name);
+		_userpicEmpty.set(id, name);
 	}
 
 	Notify::PeerUpdate update(this);
@@ -337,7 +352,7 @@ void PeerData::setUserpic(
 	_userpic = userpic;
 	_userpicLocation = location;
 	if (useEmptyUserpic()) {
-		_userpicEmpty.set(_colorIndex, name);
+		_userpicEmpty.set(id, name);
 	} else {
 		_userpicEmpty.clear();
 	}
diff --git a/Telegram/SourceFiles/data/data_peer.h b/Telegram/SourceFiles/data/data_peer.h
index b78accf05..cf931fc97 100644
--- a/Telegram/SourceFiles/data/data_peer.h
+++ b/Telegram/SourceFiles/data/data_peer.h
@@ -67,16 +67,16 @@ inline bool isNotifyMuted(
 	return false;
 }
 
-static constexpr int kUserColorsCount = 8;
-static constexpr int kChatColorsCount = 4;
-static constexpr int kChannelColorsCount = 4;
+int PeerColorIndex(PeerId peerId);
+int PeerColorIndex(int32 bareId);
 
 class EmptyUserpic {
 public:
 	EmptyUserpic();
-	EmptyUserpic(int index, const QString &name);
+	EmptyUserpic(PeerId peerId, const QString &name);
+	EmptyUserpic(const QString &nonce, const QString &name);
 
-	void set(int index, const QString &name);
+	void set(PeerId peerId, const QString &name);
 	void clear();
 
 	explicit operator bool() const {
@@ -222,9 +222,6 @@ public:
 	LoadedStatus loadedStatus = NotLoaded;
 	MTPinputPeer input;
 
-	int colorIndex() const {
-		return _colorIndex;
-	}
 	void setUserpic(ImagePtr userpic, StorageImageLocation location);
 	void paintUserpic(
 		Painter &p,
@@ -308,7 +305,6 @@ private:
 	NameWords _nameWords; // for filtering
 	NameFirstChars _nameFirstChars;
 
-	int _colorIndex = 0;
 	TimeMs _lastFullUpdate = 0;
 
 };
diff --git a/Telegram/SourceFiles/history/history_media_types.cpp b/Telegram/SourceFiles/history/history_media_types.cpp
index a3aa3e1b9..0364e70f7 100644
--- a/Telegram/SourceFiles/history/history_media_types.cpp
+++ b/Telegram/SourceFiles/history/history_media_types.cpp
@@ -2981,7 +2981,9 @@ void HistoryContact::initDimensions() {
 	if (_contact) {
 		_contact->loadUserpic();
 	} else {
-		_photoEmpty.set(qAbs(_userId ? _userId : _parent->id) % kUserColorsCount, _name.originalText());
+		_photoEmpty.set(
+			_userId ? _userId : _parent->id,
+			_name.originalText());
 	}
 	if (_contact && _contact->contact > 0) {
 		_linkl = sendMessageClickHandler(_contact);
diff --git a/Telegram/SourceFiles/history/history_message.cpp b/Telegram/SourceFiles/history/history_message.cpp
index 08bc93ef9..abd3ca227 100644
--- a/Telegram/SourceFiles/history/history_message.cpp
+++ b/Telegram/SourceFiles/history/history_message.cpp
@@ -50,37 +50,38 @@ inline void initTextOptions() {
 	_textDlgOptions.maxw = st::columnMaximalWidthLeft * 2;
 }
 
-style::color fromNameFg(int index) {
-	Expects(index >= 0 && index < 8);
-	style::color colors[] = {
-		st::historyPeer1NameFg,
-		st::historyPeer2NameFg,
-		st::historyPeer3NameFg,
-		st::historyPeer4NameFg,
-		st::historyPeer5NameFg,
-		st::historyPeer6NameFg,
-		st::historyPeer7NameFg,
-		st::historyPeer8NameFg,
-	};
-	return colors[index];
+style::color FromNameFg(not_null<PeerData*> peer, bool selected) {
+	if (selected) {
+		const style::color colors[] = {
+			st::historyPeer1NameFgSelected,
+			st::historyPeer2NameFgSelected,
+			st::historyPeer3NameFgSelected,
+			st::historyPeer4NameFgSelected,
+			st::historyPeer5NameFgSelected,
+			st::historyPeer6NameFgSelected,
+			st::historyPeer7NameFgSelected,
+			st::historyPeer8NameFgSelected,
+		};
+		return colors[PeerColorIndex(peer->id)];
+	} else {
+		const style::color colors[] = {
+			st::historyPeer1NameFg,
+			st::historyPeer2NameFg,
+			st::historyPeer3NameFg,
+			st::historyPeer4NameFg,
+			st::historyPeer5NameFg,
+			st::historyPeer6NameFg,
+			st::historyPeer7NameFg,
+			st::historyPeer8NameFg,
+		};
+		return colors[PeerColorIndex(peer->id)];
+	}
 }
 
-style::color fromNameFgSelected(int index) {
-	Expects(index >= 0 && index < 8);
-	style::color colors[] = {
-		st::historyPeer1NameFgSelected,
-		st::historyPeer2NameFgSelected,
-		st::historyPeer3NameFgSelected,
-		st::historyPeer4NameFgSelected,
-		st::historyPeer5NameFgSelected,
-		st::historyPeer6NameFgSelected,
-		st::historyPeer7NameFgSelected,
-		st::historyPeer8NameFgSelected,
-	};
-	return colors[index];
-}
-
-MTPDmessage::Flags NewForwardedFlags(not_null<PeerData*> peer, UserId from, not_null<HistoryMessage*> fwd) {
+MTPDmessage::Flags NewForwardedFlags(
+		not_null<PeerData*> peer,
+		UserId from,
+		not_null<HistoryMessage*> fwd) {
 	auto result = NewMessageFlags(peer) | MTPDmessage::Flag::f_fwd_from;
 	if (from) {
 		result |= MTPDmessage::Flag::f_from_id;
@@ -1777,7 +1778,7 @@ void HistoryMessage::paintFromName(Painter &p, QRect &trect, bool selected) cons
 		if (isPost()) {
 			p.setPen(selected ? st::msgInServiceFgSelected : st::msgInServiceFg);
 		} else {
-			p.setPen(selected ? fromNameFgSelected(author()->colorIndex()) : fromNameFg(author()->colorIndex()));
+			p.setPen(FromNameFg(author(), selected));
 		}
 		author()->nameText.drawElided(p, trect.left(), trect.top(), trect.width());
 
diff --git a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp
index addcc43cb..922167d64 100644
--- a/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp
+++ b/Telegram/SourceFiles/inline_bots/inline_bot_layout_item.cpp
@@ -153,7 +153,10 @@ ImagePtr ItemBase::getResultThumb() const {
 
 QPixmap ItemBase::getResultContactAvatar(int width, int height) const {
 	if (_result->_type == Result::Type::Contact) {
-		auto result = EmptyUserpic(qHash(_result->_id) % kUserColorsCount, _result->getLayoutTitle()).generate(width);
+		auto result = EmptyUserpic(
+			_result->_id,
+			_result->getLayoutTitle()
+		).generate(width);
 		if (result.height() != height * cIntRetinaFactor()) {
 			result = result.scaled(QSize(width, height) * cIntRetinaFactor(), Qt::IgnoreAspectRatio, Qt::SmoothTransformation);
 		}