@@ -4,6 +4,7 @@ import { batch } from "solid-js";
44import { ReactiveSet } from "@solid-primitives/set" ;
55import type {
66 Channel ,
7+ ChannelUnread ,
78 Emoji ,
89 Error ,
910 FieldsChannel ,
@@ -22,6 +23,7 @@ import type {
2223import type { Client } from "../Client.js" ;
2324import { MessageEmbed } from "../classes/MessageEmbed.js" ;
2425import { ServerRole } from "../classes/ServerRole.js" ;
26+ import { VoiceParticipant } from "../classes/VoiceParticipant.js" ;
2527import { hydrate } from "../hydration/index.js" ;
2628
2729/**
@@ -173,7 +175,35 @@ type ServerMessage =
173175 user_id : string ;
174176 exclude_session_id : string ;
175177 }
176- ) ) ;
178+ ) )
179+ | {
180+ type : "VoiceChannelJoin" ;
181+ id : string ;
182+ state : UserVoiceState ;
183+ }
184+ | {
185+ type : "VoiceChannelLeave" ;
186+ id : string ;
187+ user : string ;
188+ }
189+ | {
190+ type : "VoiceChannelMove" ;
191+ user : string ;
192+ from : string ;
193+ to : string ;
194+ state : UserVoiceState ;
195+ }
196+ | {
197+ type : "UserVoiceStateUpdate" ;
198+ id : string ;
199+ channel_id : string ;
200+ data : Partial < UserVoiceState > ;
201+ }
202+ | {
203+ type : "UserMoveVoiceChannel" ;
204+ node : string ;
205+ token : string ;
206+ } ;
177207
178208/**
179209 * Policy change type
@@ -185,6 +215,26 @@ type PolicyChange = {
185215 url : string ;
186216} ;
187217
218+ /**
219+ * Voice state for a user
220+ */
221+ export type UserVoiceState = {
222+ id : string ;
223+ joined_at : number ;
224+ is_receiving : boolean ;
225+ is_publishing : boolean ;
226+ screensharing : boolean ;
227+ camera : boolean ;
228+ } ;
229+
230+ /**
231+ * Voice state for a channel
232+ */
233+ type ChannelVoiceState = {
234+ id : string ;
235+ participants : UserVoiceState [ ] ;
236+ } ;
237+
188238/**
189239 * Initial synchronisation packet
190240 */
@@ -194,6 +244,11 @@ type ReadyData = {
194244 channels : Channel [ ] ;
195245 members : Member [ ] ;
196246 emojis : Emoji [ ] ;
247+ voice_states : ChannelVoiceState [ ] ;
248+
249+ user_settings : Record < string , unknown > ;
250+ channel_unreads : ChannelUnread [ ] ;
251+
197252 policy_changes : PolicyChange [ ] ;
198253} ;
199254
@@ -241,6 +296,20 @@ export async function handleEvent(
241296 client . channels . getOrCreate ( channel . _id , channel ) ;
242297 }
243298
299+ for ( const state of event . voice_states ) {
300+ const channel = client . channels . get ( state . id ) ;
301+ if ( channel ) {
302+ channel . voiceParticipants . clear ( ) ;
303+
304+ for ( const participant of state . participants ) {
305+ channel . voiceParticipants . set (
306+ participant . id ,
307+ new VoiceParticipant ( client , participant ) ,
308+ ) ;
309+ }
310+ }
311+ }
312+
244313 for ( const emoji of event . emojis ) {
245314 client . emojis . getOrCreate ( emoji . _id , emoji ) ;
246315 }
@@ -280,7 +349,11 @@ export async function handleEvent(
280349 const channel = client . channels . get ( event . channel ) ;
281350 if ( ! channel ) return ;
282351
283- client . channels . updateUnderlyingObject ( channel . id , "lastMessageId" , event . _id ) ;
352+ client . channels . updateUnderlyingObject (
353+ channel . id ,
354+ "lastMessageId" ,
355+ event . _id ,
356+ ) ;
284357
285358 if (
286359 event . mentions ?. includes ( client . user ! . id ) &&
@@ -865,5 +938,40 @@ export async function handleEvent(
865938 // TODO: implement DeleteSession and DeleteAllSessions
866939 break ;
867940 }
941+ case "VoiceChannelJoin" : {
942+ const channel = client . channels . getOrPartial ( event . id ) ;
943+ if ( channel ) {
944+ channel . voiceParticipants . set (
945+ event . state . id ,
946+ new VoiceParticipant ( client , event . state ) ,
947+ ) ;
948+ // todo: event
949+ }
950+ break ;
951+ }
952+ case "VoiceChannelLeave" : {
953+ const channel = client . channels . getOrPartial ( event . id ) ;
954+ if ( channel ) {
955+ channel . voiceParticipants . delete ( event . user ) ;
956+ // todo: event
957+ }
958+ break ;
959+ }
960+ case "VoiceChannelMove" : {
961+ // todo
962+ break ;
963+ }
964+ case "UserVoiceStateUpdate" : {
965+ const channel = client . channels . getOrPartial ( event . channel_id ) ;
966+ if ( channel ) {
967+ channel . voiceParticipants . get ( event . id ) ?. update ( event . data ) ;
968+ // todo: event
969+ }
970+ break ;
971+ }
972+ case "UserMoveVoiceChannel" : {
973+ // todo
974+ break ;
975+ }
868976 }
869977}
0 commit comments