Exemplo n.º 1
0
def remote_control_status(e: TextMessageEventObject):
    current = RemoteControlManager.get_current(e.user_model.id,
                                               e.channel_model_source.id,
                                               update_expiry=False)

    if current:
        cnl = current.target_channel
        if not cnl:
            RemoteControlManager.deactivate(e.user_model.id,
                                            e.channel_model_source.id)
            return [
                HandledMessageEventText(content=_(
                    "Target channel data not found. Terminating remote control.\n"
                    "Target Channel ID: `{}`").format(
                        current.target_channel_oid))
            ]
        else:
            return [
                HandledMessageEventText(
                    content=_("Remote control is activated.\n"
                              "Target Channel ID: `{}`\n"
                              "Target Channel Platform & Name: *{} / {}*\n"
                              "Will be deactivated at `{}`.").format(
                                  cnl.id, cnl.platform.key,
                                  cnl.get_channel_name(e.user_model.id),
                                  current.expiry_str))
            ]
    else:
        return [
            HandledMessageEventText(
                content=_("Remote control is not activated."))
        ]
Exemplo n.º 2
0
 def test_auto_deactivate(self):
     RemoteControlManager.activate(UID, CID_SRC, CID_DEST)
     self.wait_expiry_lock()
     self.assertIsNone(
         RemoteControlManager.get_current(UID, CID_SRC,
                                          update_expiry=False),
         "Entry still inside the holder.")
Exemplo n.º 3
0
def remote_control_activate(e: TextMessageEventObject,
                            target_channel: ObjectId):
    entry = RemoteControlManager.activate(
        e.user_model.id, e.channel_model_source.id, target_channel,
        e.user_model.config.get_locale_code())

    if entry.target_channel:
        return [
            HandledMessageEventText(content=_("Remote control activated."))
        ]
    else:
        RemoteControlManager.deactivate(e.user_model.id,
                                        e.channel_model_source.id)
        return [
            HandledMessageEventText(content=_(
                "Target channel not found. Failed to activate remote control.")
                                    )
        ]
Exemplo n.º 4
0
def remote_control_deactivate(e: TextMessageEventObject):
    if RemoteControlManager.deactivate(e.user_model.id,
                                       e.channel_model_source.id):
        return [
            HandledMessageEventText(content=_("Remote control deactivated."))
        ]
    else:
        if RemoteControlManager.get_current(e.user_model.id,
                                            e.channel_model_source.id,
                                            update_expiry=False):
            return [
                HandledMessageEventText(
                    content=_("Remote control failed to delete."))
            ]
        else:
            return [
                HandledMessageEventText(
                    content=_("Remote control not activated."))
            ]
Exemplo n.º 5
0
    def test_activate(self):
        # Storing the expiry timestamp before the actual one is created
        # to reduce the time offset caused ny db-app comm lag
        expiry_expected = datetime.utcnow().replace(
            tzinfo=timezone.utc) + timedelta(seconds=EXPIRY_SEC)
        entry = RemoteControlManager.activate(UID, CID_SRC, CID_DEST)

        self.assertIsNotNone(entry, "Activation returned `None`")
        self.assertEqual(CID_DEST, entry.target_channel_oid,
                         "Target channel not match.")
        self.assertTimeDifferenceLessEqual(entry.expiry, expiry_expected, 0.05)
Exemplo n.º 6
0
    def test_get_current_update_expiry(self):
        # Storing the expiry timestamp before the actual one is created
        # to reduce the time offset caused ny db-app comm lag
        expiry_unexpected = datetime.utcnow().replace(
            tzinfo=timezone.utc) + timedelta(seconds=EXPIRY_SEC)
        RemoteControlManager.activate(UID, CID_SRC, CID_DEST)

        self.sleep_lock()

        expiry_expected = datetime.utcnow().replace(
            tzinfo=timezone.utc) + timedelta(seconds=EXPIRY_SEC)
        get_current = exec_timing_result(RemoteControlManager.get_current, UID,
                                         CID_SRC)
        entry = get_current.return_

        self.assertIsNotNone(entry, "Entry not found in the holder.")
        self.assertEqual(CID_DEST, entry.target_channel_oid,
                         "Target channel not match.")
        self.assertTimeDifferenceLessEqual(expiry_expected, entry.expiry,
                                           get_current.execution_ms / 1000)
        self.assertTimeDifferenceGreaterEqual(expiry_unexpected, entry.expiry,
                                              SLEEP_SEC)
Exemplo n.º 7
0
    def __init__(
            self, raw: Any, content: Any, channel_model: ChannelModel = None,
            user_model: Optional[RootUserModel] = None,
            sys_ctype: SysChannelType = None, ch_parent_model: ChannelCollectionModel = None):
        src_ch = None

        rmc = None
        if user_model:
            rmc = RemoteControlManager.get_current(user_model.id, channel_model.id)

        if rmc:
            src_ch = channel_model
            channel_model = rmc.target_channel

        super().__init__(raw, channel_model, sys_ctype, source_channel=src_ch)
        self.content = content
        self.user_model = user_model
        self.chcoll_model = ch_parent_model