'Called when we receive a `m.presence` EDU from a remote server.'

@defer.inlineCallbacks
def incoming_presence(self, origin, content):

    now = self.clock.time_msec()
    updates = []
    for push in content.get('push', []):
        user_id = push.get('user_id', None)
        if (not user_id):
            logger.info("Got    presence    update    from    %r    with    no    'user_id':    %r", origin, push)
            continue
        if (get_domain_from_id(user_id) != origin):
            logger.info("Got    presence    update    from    %r    with    bad    'user_id':    %r", origin, user_id)
            continue
        presence_state = push.get('presence', None)
        if (not presence_state):
            logger.info("Got    presence    update    from    %r    with    no    'presence_state':    %r", origin, push)
            continue
        new_fields = {'state': presence_state, 'last_federation_update_ts': now}
        last_active_ago = push.get('last_active_ago', None)
        if (last_active_ago is not None):
            new_fields['last_active_ts'] = (now - last_active_ago)
        new_fields['status_msg'] = push.get('status_msg', None)
        new_fields['currently_active'] = push.get('currently_active', False)
        prev_state = (yield self.current_state_for_user(user_id))
        updates.append(prev_state.copy_and_replace(**new_fields))
    if updates:
        federation_presence_counter.inc_by(len(updates))
        (yield self._update_states(updates))
