While David was focusing on Bathsheba, Joab was fighting the King’s battles at Rabbah. He was nothing if not loyal: giving David the opportunity to march in and take the victory:
2 Samuel 12:27-28 Joab sent messengers to tell David: I have fought against Rabbah and captured its water supply. Now bring the rest of the army and capture the city. Otherwise, I will capture it and get credit for the victory.
David obliged and took the crown from the King of Rabbah.
Did Joab know what had been happening back at court? The text doesn’t tell us, but Joab was complicit in the death of Uriah the Hittite, and he must have at least wondered what was going on. He was also was close enough to David to engineer Absalom’s returned from exile:
2 Samuel 14:1-3 Joab realised how much the king longed to see Absalom. So he sent for a woman from Tekoa who had a reputation for great wisdom [and told her to] ‘go to the king and tell him the story I am about to tell you’.
When she did, David’s first words were to ask whether Joab put her up to it. She admitted he had, and David relented and allowed Absalom’s return (on condition that Absalom not see David).
It was Joab who later reconciled Absalom to his father, but it took some effort from Absalom:
2 Samuel 14:29 Then Absalom sent for Joab to ask him to intercede for him, but Joab refused to come. Absalom sent for him a second time, but again Joab refused to come.
In the end, Absalom had to set fire to Joab’s barley field to force a meeting. It worked: when Joab took Absalom’s case to David, he listened and the two were reunited.
2 Samuel 14:33 So Joab told the king what Absalom had said. Then at last David summoned Absalom, who came and bowed low before the king, and the king kissed him.
We can’t be certain how much of this was based on loyalty and friendship, and how much Joab aligning himself with the power of the day. David knew Joab was too powerful to control (see 2 Samuel 3:38-39) and possibly couldn’t afford to lose him.