The Prophet ﷺ said, "Whoever sits in a gathering where much idle talk takes place, and before getting up says, 'Glory be to You, our Lord, and praise be to You. There is no god but You. I seek Your forgiveness and turn to You in repentance,' Allah will forgive him whatever occurred in that gathering."
حدثنا حجاج قال قال ابن جريج أخبرني موسى بن عقبة عن سهيل بن أبي صالح عن أبيه
عن النبي ﷺ قال من جلس في مجلس كثر فيه لغطه فقال قبل أن يقوم سبحانك ربنا وبحمدك لا إله إلا أنت أستغفرك ثم أتوب إليك إلا غفر الله له ما كان في مجلسه ذلك
Its isnad is sahih, and Musa bin Uqba bin Abu Ayyash is trustworthy, a jurist and an authority on the military expeditions. Tirmidhi transmitted it (5/494, no. 3433) in the Book of Supplications, chapter on what one says upon rising from a gathering, and he said, hasan gharib sahih. Ibn Hibban also transmitted it (2/354, no. 594) in the Book of Kindness, Companionship, and Sitting Together, in Al-Ihsan.