@@ -137,18 +137,21 @@ import { MessageEvent } from '$types/matrix/room';
137137import { usePowerLevelsContext } from '$hooks/usePowerLevels' ;
138138import { useRoomCreators } from '$hooks/useRoomCreators' ;
139139import { useRoomPermissions } from '$hooks/useRoomPermissions' ;
140+ import { useClientConfig } from '$hooks/useClientConfig' ;
140141import { AutocompleteNotice } from '$components/editor/autocomplete/AutocompleteNotice' ;
141142import {
142143 convertPerMessageProfileToBeeperFormat ,
143144 getCurrentlyUsedPerMessageProfileForRoom ,
144145} from '$hooks/usePerMessageProfile' ;
145- import { Microphone , Stop } from '@phosphor-icons/react' ;
146+ import { Microphone , Stop , ChartBarHorizontal } from '@phosphor-icons/react' ;
146147import { getSupportedAudioExtension } from '$plugins/voice-recorder-kit/supportedCodec' ;
147148import { sanitizeCustomHtml } from '$utils/sanitize' ;
148149import { PKitCommandMessageHandler } from '$plugins/pluralkit-handler/PKitCommandMessageHandler' ;
149150import { PKitProxyMessageHandler } from '$plugins/pluralkit-handler/PKitProxyMessageHandler' ;
150151import { SchedulePickerDialog } from './schedule-send' ;
151152import * as css from './schedule-send/SchedulePickerDialog.css' ;
153+ import { PollCreatorDialog } from './poll' ;
154+ import type { PollCreatorContent } from './poll' ;
152155import {
153156 getAudioMsgContent ,
154157 getFileMsgContent ,
@@ -364,6 +367,9 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
364367 ) ;
365368 const [ scheduleMenuAnchor , setScheduleMenuAnchor ] = useState < RectCords > ( ) ;
366369 const [ showSchedulePicker , setShowSchedulePicker ] = useState ( false ) ;
370+ const [ showPollCreator , setShowPollCreator ] = useState ( false ) ;
371+ const clientConfig = useClientConfig ( ) ;
372+ const pollsEnabled = clientConfig . features ?. polls ?? false ;
367373 const [ silentReply , setSilentReply ] = useState ( ! mentionInReplies ) ;
368374 const [ hour24Clock ] = useSetting ( settingsAtom , 'hour24Clock' ) ;
369375 const isEncrypted = room . hasEncryptionStateEvent ( ) ;
@@ -1348,16 +1354,30 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
13481354 </ >
13491355 }
13501356 before = {
1351- < IconButton
1352- onClick = { ( ) => pickFile ( '*' ) }
1353- variant = "SurfaceVariant"
1354- size = "300"
1355- radii = "300"
1356- title = "Upload File"
1357- aria-label = "Upload and attach a File"
1358- >
1359- < Icon src = { Icons . PlusCircle } />
1360- </ IconButton >
1357+ < Box alignItems = "Center" gap = "100" >
1358+ < IconButton
1359+ onClick = { ( ) => pickFile ( '*' ) }
1360+ variant = "SurfaceVariant"
1361+ size = "300"
1362+ radii = "300"
1363+ title = "Upload File"
1364+ aria-label = "Upload and attach a File"
1365+ >
1366+ < Icon src = { Icons . PlusCircle } />
1367+ </ IconButton >
1368+ { pollsEnabled && (
1369+ < IconButton
1370+ onClick = { ( ) => setShowPollCreator ( true ) }
1371+ variant = "SurfaceVariant"
1372+ size = "300"
1373+ radii = "300"
1374+ title = "Create Poll"
1375+ aria-label = "Create a poll"
1376+ >
1377+ < ChartBarHorizontal size = { 20 } />
1378+ </ IconButton >
1379+ ) }
1380+ </ Box >
13611381 }
13621382 after = {
13631383 < >
@@ -1616,6 +1636,37 @@ export const RoomInput = forwardRef<HTMLDivElement, RoomInputProps>(
16161636 } }
16171637 />
16181638 ) }
1639+ { showPollCreator && (
1640+ < PollCreatorDialog
1641+ onCancel = { ( ) => setShowPollCreator ( false ) }
1642+ onSubmit = { ( content : PollCreatorContent ) => {
1643+ setShowPollCreator ( false ) ;
1644+ const pollKindKey = content . kind ;
1645+ const eventContent : Record < string , unknown > = {
1646+ 'org.matrix.msc1767.text' : content . question ,
1647+ 'org.matrix.msc3381.poll.start' : {
1648+ question : {
1649+ 'org.matrix.msc1767.text' : content . question ,
1650+ } ,
1651+ kind : pollKindKey ,
1652+ max_selections : content . maxSelections ,
1653+ answers : content . answers . map ( ( a ) => ( {
1654+ id : a . id ,
1655+ 'org.matrix.msc1767.text' : a . text ,
1656+ } ) ) ,
1657+ show_voter_names : content . showVoterNames ,
1658+ ...( content . closesAt !== undefined ? { closes_at : content . closesAt } : { } ) ,
1659+ } ,
1660+ } ;
1661+ ( mx as any ) . sendEvent ( roomId , 'org.matrix.msc3381.poll.start' , eventContent ) . catch (
1662+ // unstable MSC3381 type
1663+ ( err : unknown ) => {
1664+ console . error ( 'Failed to send poll:' , err ) ;
1665+ }
1666+ ) ;
1667+ } }
1668+ />
1669+ ) }
16191670 </ div >
16201671 ) ;
16211672 }
0 commit comments