def handle_update_frame(self, frame):
        """
        Persist the frame, publish the update out to connected
        frames (the frame and all mirroring) and admins
        """
        frame = Frames.update_by_id(frame['_id'], frame)

        # if the mirroring frame was mirroring a different frame,
        # update the previous frame's mirror count
        previous_mirroring_id = None
        if 'mirroring' in frame and frame['mirroring'] is not None:
            previous_mirroring_id = frame['mirroring']

        # set the current content for updating frame
        doc = {
            'current_content': frame['current_content']
        }

        # kick off the recursive content updates down the mirror graph
        self.update_mirroring_frames(frame, doc, root=True)

        # if the frame was mirroring a different frame,
        # update the previous frame's mirroring count
        if previous_mirroring_id:
            Frames.update_mirroring_count(previous_mirroring_id)
            self.pubsub.publish(
                'frame:frame_updated', frame_id=previous_mirroring_id)
    def handle_mirror_frame(self, frame_id, mirrored_frame_id):
        """
        Set a frame to mirror another frame.

        Returns the from which is mirroring the other.
        """

        # if the mirroring frame was mirroring a different frame,
        # update the previous frame's mirror count
        previous_mirroring_id = None
        frame = Frames.get_by_id(frame_id)
        if 'mirroring' in frame and frame['mirroring'] is not None:
            previous_mirroring_id = frame['mirroring']

        mirrored_frame = Frames.get_by_id(mirrored_frame_id)
        content = mirrored_frame['current_content']

        doc = {
            'mirroring': mirrored_frame_id,
            'mirror_meta': {
                'name': mirrored_frame['name'],
                'owner': mirrored_frame['owner']
            },
            'current_content': content
        }

        # update this frame to mirror mirrored_frame_id
        frame = Frames.update_by_id(frame_id, doc)

        # if set, update the previously mirrored frame
        if previous_mirroring_id:
            Frames.update_mirroring_count(previous_mirroring_id)
            self.pubsub.publish(
                'frame:frame_updated', frame_id=previous_mirroring_id)

        # update the mirroring_count on the newly mirrored frame
        Frames.update_mirroring_count(mirrored_frame_id)
        self.pubsub.publish(
            'frame:frame_updated', frame_id=mirrored_frame_id)

        # kick off the recursive content updates down the mirror graph
        self.update_mirroring_frames(frame, doc)