def update_last_read_message(self, requesting_user_id, sms):
        domain = self.domain
        contact_id = self.contact_id

        key = 'update-last-read-message-%s-%s-%s' % (domain, requesting_user_id, contact_id)
        with CriticalSection([key]):
            try:
                entry = SQLLastReadMessage.objects.get(
                    domain=domain,
                    read_by=requesting_user_id,
                    contact_id=contact_id
                )
            except SQLLastReadMessage.DoesNotExist:
                entry = SQLLastReadMessage(
                    domain=domain,
                    read_by=requesting_user_id,
                    contact_id=contact_id
                )
            if not entry.message_timestamp or entry.message_timestamp < sms.date:
                entry.message_id = sms.couch_id
                entry.message_timestamp = sms.date
                entry.save()
dataset/ETHPy150Open dimagi/commcare-hq/corehq/apps/sms/views.py/ChatMessageHistory.update_last_read_message/original