The Messenger of Allah ﷺ said, "When one of you arrives at a gathering, let him give the greeting of peace. If he wishes to sit, let him sit. Then when he stands to leave, let him give the greeting of peace, for the first is no more deserving than the last."
حدثنا قتيبة حدثنا الليث عن ابن عجلان عن سعيد المقبري
أن رسول الله ﷺ قال إذا انتهى أحدكم إلى مجلس فليسلم فإن بدا له أن يجلس فليجلس ثم إذا قام فليسلم فليست الأولى بأحق من الآخرة
Its chain of transmission is hasan. Nasai also related it in Amal al-Yawm wal-Layla, no. 369, from Qutayba, and Abu Dawud, no. 5208, both from the hadith of Ibn Ajlan through the same route. The mention of hearing directly is made explicit in Ahmad, 2/230, and Ibn Hibban graded it sahih in al-Ihsan, no. 494. It is also documented in Musnad Humaydi, in my edition, no. 1171.