The mosque remained unaltered during the reign of the first Rashidun caliph Abu Bakr. Abu Bakr was confirmed as the first caliph. He kept a friendly relationship with the Mamluk Sultan and his shadow Caliph in Cairo. He declared himself shah and demanded formal recognition from the Abbasid caliph Al-Nasir. This continued with the Abbasid caliph Al-Mahdi. The last Hammudid caliph reigned until 1027. The first Abbasid caliph of Cairo was Al-Mustansir. Sunnis view Ali as the fourth caliph. Mu'awiya was among the Arab troops that entered Jerusalem with Caliph Umar in 637. Abu Yaqub al-Mustansir Yusuf II Caliph of Maghreb from 1213 until his death. Uthman reigned for twelve years as a caliph. In Najaf, he visited the mausoleum of Ali, the Fourth Caliph. This decision infuriated the Shi'ite caliph Al-Mustansir Billah. The Buwayhids then attacked Baghdad, and Abu Ja'far fled into hiding with the Caliph. Following this, the matter was raised to a body of jurists assembled by the Caliph.