pub struct Service {
services: Arc<OnceServices>,
db: Data,
}Expand description
Stores and queries global and room-scoped account data.
Updates commit the secondary pointer and new event blob in one transaction while retaining monotonic counters for sync. Typed accessors deserialize the complete account data event envelope.
Fields§
§services: Arc<OnceServices>§db: DataImplementations§
Source§impl Service
impl Service
Sourcepub async fn direct_rooms(&self, user_id: &UserId) -> BTreeSet<OwnedRoomId>
pub async fn direct_rooms(&self, user_id: &UserId) -> BTreeSet<OwnedRoomId>
The rooms the user’s m.direct names, whoever the counterparty is.
The map is keyed by counterparty rather than by room, so answering for one
room means flattening all of it. A user with no m.direct at all has no
direct rooms.
Source§impl Service
impl Service
Sourcepub async fn mark_direct(
&self,
user_id: &UserId,
target: &UserId,
room_id: &RoomId,
) -> Result
pub async fn mark_direct( &self, user_id: &UserId, target: &UserId, room_id: &RoomId, ) -> Result
Record a room as a direct chat with target in the user’s m.direct.
The room joins the counterparty’s list, which is created when this is their first direct room. A list already naming the room is left alone, so repeated calls settle on one entry.
§Panics
Panics when storing a changed mapping requires a global sequence number that cannot be allocated or persisted.
Source§impl Service
impl Service
Sourceasync fn direct_content(&self, user_id: &UserId) -> Result<DirectEventContent>
async fn direct_content(&self, user_id: &UserId) -> Result<DirectEventContent>
The user’s m.direct content, absent when they have never had one.
Account data is stored as the whole event rather than as its content, so the record deserializes as an event and the content comes off it.
Source§impl Service
impl Service
Sourcepub async fn copy_room_push_rule(
&self,
user_id: &UserId,
from_room: &RoomId,
to_room: &RoomId,
) -> Result
pub async fn copy_room_push_rule( &self, user_id: &UserId, from_room: &RoomId, to_room: &RoomId, ) -> Result
Copies a room’s push rule to a successor room.
The source rule’s enabled state travels with it, so a rule the user had switched off does not come back on in the successor. A destination rule that already exists keeps its own enabled state and takes only the actions.
§Panics
Panics when dispatching the global sequence number for the changed ruleset fails.
Source§impl Service
impl Service
Sourcepub async fn set_room_tag(
&self,
user_id: &UserId,
room_id: &RoomId,
tag: TagName,
info: Option<TagInfo>,
) -> Result
pub async fn set_room_tag( &self, user_id: &UserId, room_id: &RoomId, tag: TagName, info: Option<TagInfo>, ) -> Result
Add a tag to the room in the user’s account data.
The whole tag set is rewritten on every call. A readable stored set is merged with the new tag, while a read failure starts from an empty set. A tag already present is replaced.
§Panics
Panics when dispatching the global sequence number for the changed tag set fails.
Source§impl Service
impl Service
The tags the user has placed on the room, absent when there are none.
Account data is stored as the whole event rather than as its content, so a read naming the content type here fails on every record.
Source§impl Service
impl Service
Sourcepub async fn update(
&self,
room_id: Option<&RoomId>,
user_id: &UserId,
event_type: RoomAccountDataEventType,
data: &Value,
) -> Result
pub async fn update( &self, room_id: Option<&RoomId>, user_id: &UserId, event_type: RoomAccountDataEventType, data: &Value, ) -> Result
Stores an account data event and replaces its previous revision.
The input must contain complete type and content fields. A new global counter value keys the
event blob, secondary pointer, and removal of the superseded blob in one transaction.
§Panics
Panics when dispatching the global sequence number fails.
Source§impl Service
impl Service
Sourcepub async fn delete(
&self,
room_id: Option<&RoomId>,
user_id: &UserId,
event_type: RoomAccountDataEventType,
) -> Result
pub async fn delete( &self, room_id: Option<&RoomId>, user_id: &UserId, event_type: RoomAccountDataEventType, ) -> Result
Replaces an account data event with an MSC3391 tombstone.
Delta sync surfaces the empty content so clients can apply the deletion. Zero-token V3 and V5 sync responses and client account-data GET routes treat the tombstone as absent.
§Panics
Panics when dispatching the global sequence number fails.
Source§impl Service
impl Service
Sourcepub async fn get_global<T>(
&self,
user_id: &UserId,
kind: GlobalAccountDataEventType,
) -> Result<T>where
T: for<'de> Deserialize<'de>,
pub async fn get_global<T>(
&self,
user_id: &UserId,
kind: GlobalAccountDataEventType,
) -> Result<T>where
T: for<'de> Deserialize<'de>,
Searches the global account data for a specific kind.
Global data is stored under no room, so one kind can be held once globally
and once in every room without collision. The record is the whole
{type, content} event, so T names the event rather than its content.
Source§impl Service
impl Service
Sourcepub async fn get_room<T>(
&self,
room_id: &RoomId,
user_id: &UserId,
kind: RoomAccountDataEventType,
) -> Result<T>where
T: for<'de> Deserialize<'de>,
pub async fn get_room<T>(
&self,
room_id: &RoomId,
user_id: &UserId,
kind: RoomAccountDataEventType,
) -> Result<T>where
T: for<'de> Deserialize<'de>,
Searches the room account data for a specific kind.
The room scopes the lookup, so one kind may hold different data in each of
them. The record is the whole {type, content} event, so T names the
event rather than its content.
Source§impl Service
impl Service
Sourcepub async fn get_raw(
&self,
room_id: Option<&RoomId>,
user_id: &UserId,
kind: &str,
) -> Result<Handle<'_>>
pub async fn get_raw( &self, room_id: Option<&RoomId>, user_id: &UserId, kind: &str, ) -> Result<Handle<'_>>
Loads a stored account data event without deserializing it.
The optional room ID selects room-scoped or global account data. The lookup resolves the current secondary index entry before borrowing the raw event from storage.
Source§impl Service
impl Service
Sourcepub fn changes_since<'a>(
&'a self,
room_id: Option<&'a RoomId>,
user_id: &'a UserId,
since: u64,
to: Option<u64>,
) -> impl Stream<Item = AnyRawAccountDataEvent> + Send + 'a
pub fn changes_since<'a>( &'a self, room_id: Option<&'a RoomId>, user_id: &'a UserId, since: u64, to: Option<u64>, ) -> impl Stream<Item = AnyRawAccountDataEvent> + Send + 'a
Streams account data changes after a counter value.
The optional upper bound is inclusive. Cursor and decoding failures are logged and omitted from this convenience stream.
Source§impl Service
impl Service
Sourcepub fn changes_since_fallible<'a>(
&'a self,
room_id: Option<&'a RoomId>,
user_id: &'a UserId,
since: u64,
to: Option<u64>,
) -> impl Stream<Item = Result<AnyRawAccountDataEvent>> + Send + 'a
pub fn changes_since_fallible<'a>( &'a self, room_id: Option<&'a RoomId>, user_id: &'a UserId, since: u64, to: Option<u64>, ) -> impl Stream<Item = Result<AnyRawAccountDataEvent>> + Send + 'a
Returns bounded account-data changes without suppressing failures.
The lower bound is exclusive and the optional upper bound is inclusive. Cursor, decode, and deserialization failures remain in the stream for an atomic caller to handle.
Source§impl Service
impl Service
Sourcepub async fn erase_user(&self, user_id: &UserId, room_id: Option<&RoomId>)
pub async fn erase_user(&self, user_id: &UserId, room_id: Option<&RoomId>)
Erases a user’s account data within one MSC4025 namespace.
An absent room selects global data, while a room selects only that room’s data. Rows yielded successfully from both prefix scans are deleted together; scan errors are skipped.
Source§impl Service
impl Service
Sourcepub async fn last_count<'a>(
&'a self,
room_id: Option<&'a RoomId>,
user_id: &'a UserId,
upper: Option<u64>,
) -> Result<u64>
pub async fn last_count<'a>( &'a self, room_id: Option<&'a RoomId>, user_id: &'a UserId, upper: Option<u64>, ) -> Result<u64>
Returns the latest account data counter at or below an optional bound.
The lookup is scoped to one user and either global data or a single room. An empty scope produces a not-found request error.
Trait Implementations§
Source§impl Service for Service
impl Service for Service
Source§fn build(args: &Args<'_>) -> Result<Arc<Self>>
fn build(args: &Args<'_>) -> Result<Arc<Self>>
Source§fn name(&self) -> &str
fn name(&self) -> &str
crate::service::make_name(std::module_path!())Source§fn worker<'async_trait>(
self: Arc<Self>,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
fn worker<'async_trait>(
self: Arc<Self>,
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
Source§fn interrupt<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn interrupt<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn clear_cache<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
fn clear_cache<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
Source§fn memory_usage<'life0, 'life1, 'async_trait>(
&'life0 self,
_out: &'life1 mut (dyn Write + Send),
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn memory_usage<'life0, 'life1, 'async_trait>(
&'life0 self,
_out: &'life1 mut (dyn Write + Send),
) -> Pin<Box<dyn Future<Output = Result> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn unconstrained(&self) -> bool
fn unconstrained(&self) -> bool
Auto Trait Implementations§
impl !RefUnwindSafe for Service
impl !UnwindSafe for Service
impl Freeze for Service
impl Send for Service
impl Sync for Service
impl Unpin for Service
impl UnsafeUnpin for Service
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> ExpectInto for T
impl<T> ExpectInto for T
Source§impl<T> Expected for T
impl<T> Expected for T
Source§fn expected_add(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedAdd,
fn expected_add(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedAdd,
rhs with an expectation that the operation is valid. Read moreSource§fn expected_sub(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedSub,
fn expected_sub(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedSub,
rhs with an expectation that the operation is valid. Read moreSource§fn expected_mul(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedMul,
fn expected_mul(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedMul,
rhs with an expectation that the operation is valid. Read moreSource§fn expected_div(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedDiv,
fn expected_div(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedDiv,
rhs with an expectation that the operation is valid. Read moreSource§fn expected_rem(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedRem,
fn expected_rem(self, rhs: Self) -> Selfwhere
Self: Sized + CheckedRem,
§impl<T> Identity for Twhere
T: ?Sized,
impl<T> Identity for Twhere
T: ?Sized,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreimpl<T> JsonCastable<CanonicalJsonValue> for T
impl<T> JsonCastable<Value> for T
§impl<T> Paint for Twhere
T: ?Sized,
impl<T> Paint for Twhere
T: ?Sized,
§fn fg(&self, value: Color) -> Painted<&T>
fn fg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the foreground set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like red() and
green(), which have the same functionality but are
pithier.
§Example
Set foreground color to white using fg():
use yansi::{Paint, Color};
painted.fg(Color::White);Set foreground color to white using white().
use yansi::Paint;
painted.white();§fn bright_black(&self) -> Painted<&T>
fn bright_black(&self) -> Painted<&T>
§fn bright_red(&self) -> Painted<&T>
fn bright_red(&self) -> Painted<&T>
§fn bright_green(&self) -> Painted<&T>
fn bright_green(&self) -> Painted<&T>
§fn bright_yellow(&self) -> Painted<&T>
fn bright_yellow(&self) -> Painted<&T>
§fn bright_blue(&self) -> Painted<&T>
fn bright_blue(&self) -> Painted<&T>
§fn bright_magenta(&self) -> Painted<&T>
fn bright_magenta(&self) -> Painted<&T>
§fn bright_cyan(&self) -> Painted<&T>
fn bright_cyan(&self) -> Painted<&T>
§fn bright_white(&self) -> Painted<&T>
fn bright_white(&self) -> Painted<&T>
§fn bg(&self, value: Color) -> Painted<&T>
fn bg(&self, value: Color) -> Painted<&T>
Returns a styled value derived from self with the background set to
value.
This method should be used rarely. Instead, prefer to use color-specific
builder methods like on_red() and
on_green(), which have the same functionality but
are pithier.
§Example
Set background color to red using fg():
use yansi::{Paint, Color};
painted.bg(Color::Red);Set background color to red using on_red().
use yansi::Paint;
painted.on_red();§fn on_primary(&self) -> Painted<&T>
fn on_primary(&self) -> Painted<&T>
§fn on_magenta(&self) -> Painted<&T>
fn on_magenta(&self) -> Painted<&T>
§fn on_bright_black(&self) -> Painted<&T>
fn on_bright_black(&self) -> Painted<&T>
§fn on_bright_red(&self) -> Painted<&T>
fn on_bright_red(&self) -> Painted<&T>
§fn on_bright_green(&self) -> Painted<&T>
fn on_bright_green(&self) -> Painted<&T>
§fn on_bright_yellow(&self) -> Painted<&T>
fn on_bright_yellow(&self) -> Painted<&T>
§fn on_bright_blue(&self) -> Painted<&T>
fn on_bright_blue(&self) -> Painted<&T>
§fn on_bright_magenta(&self) -> Painted<&T>
fn on_bright_magenta(&self) -> Painted<&T>
§fn on_bright_cyan(&self) -> Painted<&T>
fn on_bright_cyan(&self) -> Painted<&T>
§fn on_bright_white(&self) -> Painted<&T>
fn on_bright_white(&self) -> Painted<&T>
§fn attr(&self, value: Attribute) -> Painted<&T>
fn attr(&self, value: Attribute) -> Painted<&T>
Enables the styling [Attribute] value.
This method should be used rarely. Instead, prefer to use
attribute-specific builder methods like bold() and
underline(), which have the same functionality
but are pithier.
§Example
Make text bold using attr():
use yansi::{Paint, Attribute};
painted.attr(Attribute::Bold);Make text bold using using bold().
use yansi::Paint;
painted.bold();§fn rapid_blink(&self) -> Painted<&T>
fn rapid_blink(&self) -> Painted<&T>
§fn quirk(&self, value: Quirk) -> Painted<&T>
fn quirk(&self, value: Quirk) -> Painted<&T>
Enables the yansi [Quirk] value.
This method should be used rarely. Instead, prefer to use quirk-specific
builder methods like mask() and
wrap(), which have the same functionality but are
pithier.
§Example
Enable wrapping using .quirk():
use yansi::{Paint, Quirk};
painted.quirk(Quirk::Wrap);Enable wrapping using wrap().
use yansi::Paint;
painted.wrap();§fn clear(&self) -> Painted<&T>
👎Deprecated since 1.0.1: renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
fn clear(&self) -> Painted<&T>
renamed to resetting() due to conflicts with Vec::clear().
The clear() method will be removed in a future release.
§fn whenever(&self, value: Condition) -> Painted<&T>
fn whenever(&self, value: Condition) -> Painted<&T>
Conditionally enable styling based on whether the [Condition] value
applies. Replaces any previous condition.
See the crate level docs for more details.
§Example
Enable styling painted only when both stdout and stderr are TTYs:
use yansi::{Paint, Condition};
painted.red().on_yellow().whenever(Condition::STDOUTERR_ARE_TTY);§impl<T> Pointable for T
impl<T> Pointable for T
§impl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
§impl<T> ServiceExt for T
impl<T> ServiceExt for T
§fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
Self: Sized,
fn add_extension<T>(self, value: T) -> AddExtension<Self, T>where
Self: Sized,
§fn compression(self) -> Compression<Self>where
Self: Sized,
fn compression(self) -> Compression<Self>where
Self: Sized,
§fn decompression(self) -> Decompression<Self>where
Self: Sized,
fn decompression(self) -> Decompression<Self>where
Self: Sized,
§fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
fn trace_for_http(self) -> Trace<Self, SharedClassifier<ServerErrorsAsFailures>>where
Self: Sized,
§fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
fn trace_for_grpc(self) -> Trace<Self, SharedClassifier<GrpcErrorsAsFailures>>where
Self: Sized,
§fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
fn follow_redirects(self) -> FollowRedirect<Self>where
Self: Sized,
§fn sensitive_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
Self: Sized,
fn sensitive_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<SetSensitiveResponseHeaders<Self>>where
Self: Sized,
§fn sensitive_request_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
Self: Sized,
fn sensitive_request_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveRequestHeaders<Self>where
Self: Sized,
§fn sensitive_response_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
Self: Sized,
fn sensitive_response_headers(
self,
headers: impl IntoIterator<Item = HeaderName>,
) -> SetSensitiveResponseHeaders<Self>where
Self: Sized,
§fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn override_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn append_request_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
fn insert_request_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetRequestHeader<Self, M>where
Self: Sized,
§fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn override_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn append_response_header<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
fn insert_response_header_if_not_present<M>(
self,
header_name: HeaderName,
make: M,
) -> SetResponseHeader<Self, M>where
Self: Sized,
§fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
fn catch_panic(self) -> CatchPanic<Self, DefaultResponseForPanic>where
Self: Sized,
500 Internal Server responses. Read moreSource§impl<T> Tried for T
impl<T> Tried for T
Source§fn try_add(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedAdd,
fn try_add(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedAdd,
rhs with checked arithmetic. Read moreSource§fn try_sub(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedSub,
fn try_sub(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedSub,
rhs with checked arithmetic. Read moreSource§fn try_mul(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedMul,
fn try_mul(self, rhs: Self) -> Result<Self, Error>where
Self: Sized + CheckedMul,
rhs with checked arithmetic. Read more