当前位置: 首页>>代码示例>>Python>>正文


Python StreamChangeCache.get_all_entities_changed方法代码示例

本文整理汇总了Python中synapse.util.caches.stream_change_cache.StreamChangeCache.get_all_entities_changed方法的典型用法代码示例。如果您正苦于以下问题:Python StreamChangeCache.get_all_entities_changed方法的具体用法?Python StreamChangeCache.get_all_entities_changed怎么用?Python StreamChangeCache.get_all_entities_changed使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在synapse.util.caches.stream_change_cache.StreamChangeCache的用法示例。


在下文中一共展示了StreamChangeCache.get_all_entities_changed方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_get_all_entities_changed

# 需要导入模块: from synapse.util.caches.stream_change_cache import StreamChangeCache [as 别名]
# 或者: from synapse.util.caches.stream_change_cache.StreamChangeCache import get_all_entities_changed [as 别名]
    def test_get_all_entities_changed(self):
        """
        StreamChangeCache.get_all_entities_changed will return all changed
        entities since the given position.  If the position is before the start
        of the known stream, it returns None instead.
        """
        cache = StreamChangeCache("#test", 1)

        cache.entity_has_changed("[email protected]", 2)
        cache.entity_has_changed("[email protected]", 3)
        cache.entity_has_changed("[email protected]", 4)

        self.assertEqual(
            cache.get_all_entities_changed(1),
            ["[email protected]", "[email protected]", "[email protected]"],
        )
        self.assertEqual(
            cache.get_all_entities_changed(2), ["[email protected]", "[email protected]"]
        )
        self.assertEqual(cache.get_all_entities_changed(3), ["[email protected]"])
        self.assertEqual(cache.get_all_entities_changed(0), None)
开发者ID:DoubleMalt,项目名称:synapse,代码行数:23,代码来源:test_stream_change_cache.py

示例2: TypingHandler

# 需要导入模块: from synapse.util.caches.stream_change_cache import StreamChangeCache [as 别名]
# 或者: from synapse.util.caches.stream_change_cache.StreamChangeCache import get_all_entities_changed [as 别名]

#.........这里部分代码省略.........
        try:
            users = yield self.state.get_current_user_in_room(member.room_id)
            self._member_last_federation_poke[member] = self.clock.time_msec()

            now = self.clock.time_msec()
            self.wheel_timer.insert(
                now=now,
                obj=member,
                then=now + FEDERATION_PING_INTERVAL,
            )

            for domain in set(get_domain_from_id(u) for u in users):
                if domain != self.server_name:
                    logger.debug("sending typing update to %s", domain)
                    self.federation.send_edu(
                        destination=domain,
                        edu_type="m.typing",
                        content={
                            "room_id": member.room_id,
                            "user_id": member.user_id,
                            "typing": typing,
                        },
                        key=member,
                    )
        except Exception:
            logger.exception("Error pushing typing notif to remotes")

    @defer.inlineCallbacks
    def _recv_edu(self, origin, content):
        room_id = content["room_id"]
        user_id = content["user_id"]

        member = RoomMember(user_id=user_id, room_id=room_id)

        # Check that the string is a valid user id
        user = UserID.from_string(user_id)

        if user.domain != origin:
            logger.info(
                "Got typing update from %r with bad 'user_id': %r",
                origin, user_id,
            )
            return

        users = yield self.state.get_current_user_in_room(room_id)
        domains = set(get_domain_from_id(u) for u in users)

        if self.server_name in domains:
            logger.info("Got typing update from %s: %r", user_id, content)
            now = self.clock.time_msec()
            self._member_typing_until[member] = now + FEDERATION_TIMEOUT
            self.wheel_timer.insert(
                now=now,
                obj=member,
                then=now + FEDERATION_TIMEOUT,
            )
            self._push_update_local(
                member=member,
                typing=content["typing"]
            )

    def _push_update_local(self, member, typing):
        room_set = self._room_typing.setdefault(member.room_id, set())
        if typing:
            room_set.add(member.user_id)
        else:
            room_set.discard(member.user_id)

        self._latest_room_serial += 1
        self._room_serials[member.room_id] = self._latest_room_serial
        self._typing_stream_change_cache.entity_has_changed(
            member.room_id, self._latest_room_serial,
        )

        self.notifier.on_new_event(
            "typing_key", self._latest_room_serial, rooms=[member.room_id]
        )

    def get_all_typing_updates(self, last_id, current_id):
        if last_id == current_id:
            return []

        changed_rooms = self._typing_stream_change_cache.get_all_entities_changed(
            last_id,
        )

        if changed_rooms is None:
            changed_rooms = self._room_serials

        rows = []
        for room_id in changed_rooms:
            serial = self._room_serials[room_id]
            if last_id < serial <= current_id:
                typing = self._room_typing[room_id]
                rows.append((serial, room_id, list(typing)))
        rows.sort()
        return rows

    def get_current_token(self):
        return self._latest_room_serial
开发者ID:DoubleMalt,项目名称:synapse,代码行数:104,代码来源:typing.py


注:本文中的synapse.util.caches.stream_change_cache.StreamChangeCache.get_all_entities_changed方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。