'Notify that a user\'s device(s) has changed. Pokes the notifier, and
remote servers if the user is local.'

@measure_func('notify_device_update')
@defer.inlineCallbacks
def notify_device_update(self, user_id, device_ids):

    users_who_share_room = (yield self.store.get_users_who_share_room_with_user(user_id))
    hosts = set()
    if self.hs.is_mine_id(user_id):
        hosts.update((get_domain_from_id(u) for u in users_who_share_room))
        hosts.discard(self.server_name)
    position = (yield self.store.add_device_change_to_streams(user_id, device_ids, list(hosts)))
    room_ids = (yield self.store.get_rooms_for_user(user_id))
    (yield self.notifier.on_new_event('device_list_key', position, rooms=room_ids))
    if hosts:
        logger.info('Sending    device    list    update    notif    to:    %r', hosts)
        for host in hosts:
            self.federation_sender.send_device_messages(host)
