예제 #1
0
 def process_replication(self, result):
     stream = result.get("presence", {"rows": []})
     for row in stream["rows"]:
         (position, user_id, state, last_active_ts,
          last_federation_update_ts, last_user_sync_ts, status_msg,
          currently_active) = row
         self.user_to_current_state[user_id] = UserPresenceState(
             user_id, state, last_active_ts, last_federation_update_ts,
             last_user_sync_ts, status_msg, currently_active)
예제 #2
0
    def process_replication_rows(self, token, rows):
        states = [UserPresenceState(
            row.user_id, row.state, row.last_active_ts,
            row.last_federation_update_ts, row.last_user_sync_ts, row.status_msg,
            row.currently_active
        ) for row in rows]

        for state in states:
            self.user_to_current_state[row.user_id] = state

        stream_id = token
        yield self.notify_from_replication(states, stream_id)
예제 #3
0
    def process_replication(self, result):
        stream = result.get("presence", {"rows": []})
        states = []
        for row in stream["rows"]:
            (position, user_id, state, last_active_ts,
             last_federation_update_ts, last_user_sync_ts, status_msg,
             currently_active) = row
            state = UserPresenceState(user_id, state, last_active_ts,
                                      last_federation_update_ts,
                                      last_user_sync_ts, status_msg,
                                      currently_active)
            self.user_to_current_state[user_id] = state
            states.append(state)

        if states and "position" in stream:
            stream_id = int(stream["position"])
            yield self.notify_from_replication(states, stream_id)
예제 #4
0
    def get_presence_for_users(self, user_ids):
        rows = yield self.db_pool.simple_select_many_batch(
            table="presence_stream",
            column="user_id",
            iterable=user_ids,
            keyvalues={},
            retcols=(
                "user_id",
                "state",
                "last_active_ts",
                "last_federation_update_ts",
                "last_user_sync_ts",
                "status_msg",
                "currently_active",
            ),
            desc="get_presence_for_users",
        )

        for row in rows:
            row["currently_active"] = bool(row["currently_active"])

        return {row["user_id"]: UserPresenceState(**row) for row in rows}