soup-sdk 0.3.5

채팅 이벤트 수신 SDK
Documentation
use crate::chat::{
    events::{EventMeta, GiftEvent},
    parser::{
        raw::{ParseResult, RawMessage},
        util::normalize_user_id,
    },
    types::GiftType,
};

pub fn parse_subscribe_gift_event(raw: RawMessage) -> ParseResult<GiftEvent> {
    Ok(GiftEvent {
        meta: EventMeta {
            received_time: raw.received_time,
        },
        gift_type: GiftType::Subscription,
        sender_id: normalize_user_id(raw.field(1)?),
        sender_label: raw.field_string(2)?,
        receiver_id: normalize_user_id(raw.field(3)?),
        receiver_label: raw.field_string(4)?,
        gift_code: raw.field_string(7)?,
    })
}

pub fn parse_quickview_gift_event(raw: RawMessage) -> ParseResult<GiftEvent> {
    Ok(GiftEvent {
        meta: EventMeta {
            received_time: raw.received_time,
        },
        gift_type: GiftType::QuickView,
        sender_id: normalize_user_id(raw.field(1)?),
        sender_label: raw.field_string(2)?,
        receiver_id: normalize_user_id(raw.field(3)?),
        receiver_label: raw.field_string(4)?,
        gift_code: raw.field_string(5)?,
    })
}

pub fn parse_ogq_gift_event(raw: RawMessage) -> ParseResult<GiftEvent> {
    Ok(GiftEvent {
        meta: EventMeta {
            received_time: raw.received_time,
        },
        gift_type: GiftType::OGQ,
        sender_id: normalize_user_id(raw.field(1)?),
        sender_label: raw.field_string(2)?,
        receiver_id: normalize_user_id(raw.field(3)?),
        receiver_label: raw.field_string(4)?,
        gift_code: raw.field_string(5)?,
    })
}