mirror of
https://codeberg.org/steam-vent/chat.git
synced 2026-11-30 20:50:52 +01:00
apply fixes
This commit is contained in:
parent
5710d6858e
commit
ff9a62d860
5 changed files with 1001 additions and 693 deletions
1689
Cargo.lock
generated
1689
Cargo.lock
generated
File diff suppressed because it is too large
Load diff
15
Cargo.toml
15
Cargo.toml
|
|
@ -1,17 +1,18 @@
|
|||
[package]
|
||||
name = "steam-vent-chat"
|
||||
version = "0.4.0"
|
||||
name = "aurelia-steam-vent-chat"
|
||||
version = "0.5.0"
|
||||
authors = ["Robin Appelman <robin@icewind.nl>"]
|
||||
edition = "2024"
|
||||
description = "Steam chat client library"
|
||||
description = "Steam chat client library (Aurelia fork of steam-vent-chat, ported to steam-vent 0.5)"
|
||||
license = "MIT"
|
||||
repository = "https://codeberg.org/steam-vent/chat"
|
||||
repository = "https://codeberg.org/Drackrath/aurelia-steam-vent-chat"
|
||||
rust-version = "1.85.0"
|
||||
|
||||
[dependencies]
|
||||
steam-vent = "0.4.0"
|
||||
steamid-ng = "2.0.0"
|
||||
tokio-stream = "0.1.17"
|
||||
steam-vent = "0.5"
|
||||
steam-vent-proto = "=0.5.2"
|
||||
steamid-ng = { version = "3", features = ["serde"] }
|
||||
tokio-stream = "0.1"
|
||||
|
||||
[dev-dependencies]
|
||||
tokio = { version = "1.47.1", features = ["macros", "rt-multi-thread"] }
|
||||
|
|
|
|||
15
README.md
15
README.md
|
|
@ -1,4 +1,4 @@
|
|||
# steam-vent-chat
|
||||
# aurelia-steam-vent-chat
|
||||
|
||||
Steam chat client library.
|
||||
|
||||
|
|
@ -6,6 +6,19 @@ A high-level companion library for
|
|||
[steam-vent](https://codeberg.org/steam-vent/steam-vent) for sending and
|
||||
receiving steam chat messages.
|
||||
|
||||
This is the [Aurelia](https://github.com/Drackrath/Aurelia) fork of
|
||||
[steam-vent-chat](https://codeberg.org/steam-vent/chat). It differs from
|
||||
upstream in these ways:
|
||||
|
||||
- Ported to steam-vent 0.5 and steamid-ng 3. Protos now come from
|
||||
`steam-vent-proto`, because steam-vent no longer re-exports them.
|
||||
- `ChatClient::listen` borrows the client instead of returning a `'static`
|
||||
stream.
|
||||
- Notifications with an invalid friend Steam ID are dropped, because steamid-ng
|
||||
3 has no default `SteamID` to fall back to.
|
||||
- Incoming messages are delivered. Upstream checks `local_echo()` on both arms,
|
||||
so it drops every message from a friend.
|
||||
|
||||
## Usage
|
||||
|
||||
```rust
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use steam_vent::auth::{
|
|||
FileGuardDataStore, SharedSecretAuthConfirmationHandler,
|
||||
};
|
||||
use steam_vent::{Connection, ServerList};
|
||||
use steam_vent_chat::{ChatClient, ChatEvent};
|
||||
use aurelia_steam_vent_chat::{ChatClient, ChatEvent};
|
||||
use steamid_ng::SteamID;
|
||||
use tokio::spawn;
|
||||
use tokio_stream::StreamExt;
|
||||
|
|
@ -56,7 +56,8 @@ async fn main() -> Result<(), Box<dyn Error>> {
|
|||
}
|
||||
};
|
||||
|
||||
let chat = ChatClient::new(connection);
|
||||
// listen() borrows; spawn needs 'static.
|
||||
let chat: &'static ChatClient = Box::leak(Box::new(ChatClient::new(connection)));
|
||||
|
||||
let mut events = chat.listen();
|
||||
spawn(async move {
|
||||
|
|
|
|||
18
src/lib.rs
18
src/lib.rs
|
|
@ -1,4 +1,6 @@
|
|||
use steam_vent::proto::steammessages_friendmessages_steamclient::{CFriendMessages_IncomingMessage_Notification, CFriendMessages_SendMessage_Request};
|
||||
use steam_vent_proto::steammessages_friendmessages_steamclient::{
|
||||
CFriendMessages_IncomingMessage_Notification, CFriendMessages_SendMessage_Request,
|
||||
};
|
||||
use steam_vent::{Connection, ConnectionTrait, NetworkError};
|
||||
use steamid_ng::SteamID;
|
||||
use tokio_stream::{Stream, StreamExt};
|
||||
|
|
@ -15,7 +17,7 @@ impl ChatClient {
|
|||
}
|
||||
|
||||
/// Listen for incoming events
|
||||
pub fn listen(&self) -> impl Stream<Item = Result<ChatEvent, NetworkError>> + 'static {
|
||||
pub fn listen(&self) -> impl Stream<Item = Result<ChatEvent, NetworkError>> + '_ {
|
||||
self.connection
|
||||
.on_notification::<CFriendMessages_IncomingMessage_Notification>()
|
||||
.filter_map(|notification| {
|
||||
|
|
@ -59,17 +61,23 @@ impl TryFrom<CFriendMessages_IncomingMessage_Notification> for ChatEvent {
|
|||
fn try_from(
|
||||
notification: CFriendMessages_IncomingMessage_Notification,
|
||||
) -> Result<Self, Self::Error> {
|
||||
let source = SteamID::try_from(notification.steamid_friend()).unwrap_or_default();
|
||||
// steamid-ng 3.x dropped `Default` for `SteamID`, so an unparseable id can
|
||||
// no longer fall back to a zero id — drop the event instead.
|
||||
let source = SteamID::try_from(notification.steamid_friend()).map_err(|_| ())?;
|
||||
let message_type =
|
||||
MessageType::try_from(notification.chat_entry_type()).unwrap_or_default();
|
||||
Ok(match message_type {
|
||||
MessageType::Chat if notification.local_echo() => ChatEvent::Message(MessageEvent {
|
||||
// A message from the friend (not a local echo of our own send). The
|
||||
// upstream code guarded both arms on `local_echo()`, which made the
|
||||
// echo arm unreachable and silently dropped every genuine incoming
|
||||
// message; the real distinction is whether `local_echo` is set.
|
||||
MessageType::Chat if !notification.local_echo() => ChatEvent::Message(MessageEvent {
|
||||
source,
|
||||
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
||||
message: notification.message.unwrap_or_default(),
|
||||
message_no_bbcode: notification.message_no_bbcode,
|
||||
}),
|
||||
MessageType::Chat if notification.local_echo() => ChatEvent::EchoMessage(MessageEvent {
|
||||
MessageType::Chat => ChatEvent::EchoMessage(MessageEvent {
|
||||
source,
|
||||
server_timestamp: notification.rtime32_server_timestamp() as u64,
|
||||
message: notification.message.unwrap_or_default(),
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue