@@ -2,7 +2,10 @@ import { Database } from '@/types/database.supabase';
22import { Channel } from '@/types/dbtypes' ;
33import { SupabaseClient } from '@supabase/supabase-js' ;
44
5- export async function getChannelById ( supabase : SupabaseClient < Database > , channelId : number ) {
5+ export async function getChannelById (
6+ supabase : SupabaseClient < Database > ,
7+ channelId : number
8+ ) {
69 return await supabase
710 . from ( 'channels' )
811 . select ( '*' )
@@ -14,7 +17,10 @@ type ChannelByIdResponse = Awaited<ReturnType<typeof getChannelById>>;
1417export type ChannelByIdResponseSuccess = ChannelByIdResponse [ 'data' ] ;
1518export type ChannelByIdResponseError = ChannelByIdResponse [ 'error' ] ;
1619
17- export async function getChannelsInServer ( supabase : SupabaseClient < Database > , serverId : number ) {
20+ export async function getChannelsInServer (
21+ supabase : SupabaseClient < Database > ,
22+ serverId : number
23+ ) {
1824 return await supabase
1925 . from ( 'channels' )
2026 . select ( '*' )
@@ -27,7 +33,13 @@ type ChannelsInServerResponse = Awaited<ReturnType<typeof getChannelsInServer>>;
2733export type ChannelsInServerResponseSuccess = ChannelsInServerResponse [ 'data' ] ;
2834export type ChannelsInServerResponseError = ChannelsInServerResponse [ 'error' ] ;
2935
30- export async function createChannel ( supabase : SupabaseClient < Database > , serverId : number , name : string , desciption : string | null = null ) {
36+ export async function createChannel (
37+ supabase : SupabaseClient < Database > ,
38+ serverId : number ,
39+ name : string ,
40+ desciption : string | null = null ,
41+ isMedia : boolean = false
42+ ) {
3143 // Validate channel name is present
3244 if ( ! name ) {
3345 return { data : null , error : 'Channel name is required' } ;
@@ -39,6 +51,7 @@ export async function createChannel(supabase: SupabaseClient<Database>, serverId
3951 server_id : serverId ,
4052 name : name ,
4153 description : desciption ,
54+ is_media : isMedia ,
4255 } )
4356 . select ( )
4457 . single ( ) ;
@@ -48,20 +61,24 @@ type CreateChannelResponse = Awaited<ReturnType<typeof createChannel>>;
4861export type CreateChannelResponseSuccess = CreateChannelResponse [ 'data' ] ;
4962export type CreateChannelResponseError = CreateChannelResponse [ 'error' ] ;
5063
51- export async function deleteChannel ( supabase : SupabaseClient < Database > , channelId : number ) {
64+ export async function deleteChannel (
65+ supabase : SupabaseClient < Database > ,
66+ channelId : number
67+ ) {
5268 // NOTE: Supabase has been set up to cascade delete all messages in a channel when the channel is deleted
53- return await supabase
54- . from ( 'channels' )
55- . delete ( )
56- . eq ( 'id' , channelId )
57- . single ( ) ;
69+ return await supabase . from ( 'channels' ) . delete ( ) . eq ( 'id' , channelId ) . single ( ) ;
5870}
5971
6072type DeleteChannelResponse = Awaited < ReturnType < typeof deleteChannel > > ;
6173export type DeleteChannelResponseSuccess = DeleteChannelResponse [ 'data' ] ;
6274export type DeleteChannelResponseError = DeleteChannelResponse [ 'error' ] ;
6375
64- export async function updateChannel ( supabase : SupabaseClient < Database > , channelId : number , name : string , description : string | null ) {
76+ export async function updateChannel (
77+ supabase : SupabaseClient < Database > ,
78+ channelId : number ,
79+ name : string ,
80+ description : string | null
81+ ) {
6582 return await supabase
6683 . from ( 'channels' )
6784 . update ( {
@@ -77,20 +94,34 @@ type UpdateChannelResponse = Awaited<ReturnType<typeof updateChannel>>;
7794export type UpdateChannelResponseSuccess = UpdateChannelResponse [ 'data' ] ;
7895export type UpdateChannelResponseError = UpdateChannelResponse [ 'error' ] ;
7996
80- export async function getAllChannelsForUser ( supabase : SupabaseClient < Database > , userId : string ) {
81- return await supabase
82- . rpc ( 'get_all_channels_for_user' , { p_id : userId } ) ;
97+ export async function getAllChannelsForUser (
98+ supabase : SupabaseClient < Database > ,
99+ userId : string
100+ ) {
101+ return await supabase . rpc ( 'get_all_channels_for_user' , { p_id : userId } ) ;
83102}
84103
85- type AllChannelsForUserResponse = Awaited < ReturnType < typeof getAllChannelsForUser > > ;
86- export type AllChannelsForUserResponseSuccess = AllChannelsForUserResponse [ 'data' ] ;
87- export type AllChannelsForUserResponseError = AllChannelsForUserResponse [ 'error' ] ;
104+ type AllChannelsForUserResponse = Awaited <
105+ ReturnType < typeof getAllChannelsForUser >
106+ > ;
107+ export type AllChannelsForUserResponseSuccess =
108+ AllChannelsForUserResponse [ 'data' ] ;
109+ export type AllChannelsForUserResponseError =
110+ AllChannelsForUserResponse [ 'error' ] ;
88111
89- export async function getCurrentUserChannelPermissions ( supabase : SupabaseClient < Database > , channelId : number ) {
90- return await supabase
91- . rpc ( 'get_channel_permission_flags' , { c_id : channelId } ) ;
112+ export async function getCurrentUserChannelPermissions (
113+ supabase : SupabaseClient < Database > ,
114+ channelId : number
115+ ) {
116+ return await supabase . rpc ( 'get_channel_permission_flags' , {
117+ c_id : channelId ,
118+ } ) ;
92119}
93120
94- type CurrentUserChannelPermissionsResponse = Awaited < ReturnType < typeof getCurrentUserChannelPermissions > > ;
95- export type CurrentUserChannelPermissionsResponseSuccess = CurrentUserChannelPermissionsResponse [ 'data' ] ;
96- export type CurrentUserChannelPermissionsResponseError = CurrentUserChannelPermissionsResponse [ 'error' ] ;
121+ type CurrentUserChannelPermissionsResponse = Awaited <
122+ ReturnType < typeof getCurrentUserChannelPermissions >
123+ > ;
124+ export type CurrentUserChannelPermissionsResponseSuccess =
125+ CurrentUserChannelPermissionsResponse [ 'data' ] ;
126+ export type CurrentUserChannelPermissionsResponseError =
127+ CurrentUserChannelPermissionsResponse [ 'error' ] ;
0 commit comments