-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
176 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
# Based on https://github.com/actions-rs/meta/blob/master/recipes/quickstart.md | ||
|
||
on: | ||
push: | ||
branches: [main] | ||
pull_request: | ||
branches: [main] | ||
|
||
name: Continuous Integration | ||
|
||
jobs: | ||
check: | ||
name: Run cargo check | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
|
||
- name: Run cargo check | ||
run: cargo check --all-targets | ||
|
||
- name: Run cargo check with atlas feature | ||
run: cargo check --all-targets --features atlas | ||
|
||
- name: Run cargo check headless | ||
run: cargo check --all-targets --no-default-features | ||
|
||
docs: | ||
name: Run cargo doc | ||
env: | ||
RUSTDOCFLAGS: -D warnings | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
|
||
- name: Run cargo doc | ||
run: cargo doc --all-features --no-deps | ||
|
||
build_examples: | ||
name: Build examples | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
|
||
- name: Build examples | ||
run: cargo build --examples | ||
|
||
- name: Clean | ||
run: cargo clean | ||
|
||
- name: Build examples with atlas feature | ||
run: cargo build --examples --features atlas | ||
|
||
test: | ||
name: Tests | ||
strategy: | ||
# Tests are most likely to have OS-specific behavior | ||
matrix: | ||
os: [ubuntu-latest, windows-latest, macOS-latest] | ||
|
||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Checkout sources | ||
uses: actions/checkout@v3 | ||
|
||
- name: Install stable toolchain | ||
uses: dtolnay/rust-toolchain@stable | ||
|
||
- name: Run cargo test | ||
run: cargo test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
use serde::{Deserialize, Serialize}; | ||
|
||
use crate::{ | ||
event::{context::EventHeader, dispatcher::EventHandler}, | ||
service::im::v1::p2_im_message_receive_v1::{EventMessage, EventSender}, | ||
}; | ||
|
||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct P2ImMessageReadV1 { | ||
pub schema: String, | ||
pub header: EventHeader, | ||
pub event: P2ImMessageMessageReadV1Data, | ||
} | ||
|
||
/// 事件 | ||
#[derive(Debug, Serialize, Deserialize)] | ||
pub struct P2ImMessageMessageReadV1Data { | ||
pub sender: EventSender, | ||
pub message: EventMessage, | ||
} | ||
|
||
pub struct P2ImMessageReadV1ProcessorImpl<F> | ||
where | ||
F: Fn(P2ImMessageReadV1) + 'static, | ||
{ | ||
f: F, | ||
} | ||
|
||
impl<F> P2ImMessageReadV1ProcessorImpl<F> | ||
where | ||
F: Fn(P2ImMessageReadV1) + 'static, | ||
{ | ||
pub fn new(f: F) -> Self { | ||
P2ImMessageReadV1ProcessorImpl { f } | ||
} | ||
} | ||
|
||
impl<F> EventHandler for P2ImMessageReadV1ProcessorImpl<F> | ||
where | ||
F: Fn(P2ImMessageReadV1) + 'static + Sync + Send, | ||
{ | ||
fn handle(&self, payload: &[u8]) -> anyhow::Result<()> { | ||
let message: P2ImMessageReadV1 = serde_json::from_slice(payload)?; | ||
(self.f)(message); | ||
Ok(()) | ||
} | ||
} |