Poll timer, auto-growing poll options, multi-line composer, bundled Inter font so markdown bold renders, full-width code blocks
Browse files at this commitba30ecf577bbf66f7ec2a245a5e936902fa47ac2Parent: f296e6e- feat
- poll timer, auto-growing poll options, multi-line composer, bundled Inter font so markdown bold renders, full-width code blocks
19 changed files +293 -85
- crates/client/assets/fonts/Inter-Bold.ttf +0 -0
- crates/client/assets/fonts/Inter-BoldItalic.ttf +0 -0
- crates/client/assets/fonts/Inter-Italic.ttf +0 -0
- crates/client/assets/fonts/Inter-Medium.ttf +0 -0
- crates/client/assets/fonts/Inter-Regular.ttf +0 -0
- crates/client/assets/fonts/Inter-SemiBold.ttf +0 -0
- crates/client/assets/fonts/LICENSE-Inter.txt +92 -0
- crates/client/src/gui.rs +16 -0
- crates/client/src/gui/chat.rs +23 -13
- crates/client/src/gui/composer.rs +78 -26
- crates/client/src/gui/poll.rs +53 -16
- crates/client/src/main.rs +1 -0
- crates/common/src/call.rs +1 -0
- crates/common/src/model.rs +1 -0
- crates/server/src/call/message.rs +1 -10
- crates/server/src/db/message.rs +3 -7
- crates/server/src/db/poll.rs +21 -12
- crates/server/src/db/schema.sql +2 -1
- harness/ui.sh +1 -0
crates/client/assets/fonts/Inter-Bold.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/Inter-BoldItalic.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/Inter-Italic.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/Inter-Medium.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/Inter-Regular.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/Inter-SemiBold.ttfadded+0 -0
Binary file changed
crates/client/assets/fonts/LICENSE-Inter.txtadded+92 -0
| @@ -0,0 +1,92 @@ | |||
| 1 | +Copyright (c) 2016 The Inter Project Authors (https://github.com/rsms/inter) | ||
| 2 | + | ||
| 3 | +This Font Software is licensed under the SIL Open Font License, Version 1.1. | ||
| 4 | +This license is copied below, and is also available with a FAQ at: | ||
| 5 | +http://scripts.sil.org/OFL | ||
| 6 | + | ||
| 7 | +----------------------------------------------------------- | ||
| 8 | +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 | ||
| 9 | +----------------------------------------------------------- | ||
| 10 | + | ||
| 11 | +PREAMBLE | ||
| 12 | +The goals of the Open Font License (OFL) are to stimulate worldwide | ||
| 13 | +development of collaborative font projects, to support the font creation | ||
| 14 | +efforts of academic and linguistic communities, and to provide a free and | ||
| 15 | +open framework in which fonts may be shared and improved in partnership | ||
| 16 | +with others. | ||
| 17 | + | ||
| 18 | +The OFL allows the licensed fonts to be used, studied, modified and | ||
| 19 | +redistributed freely as long as they are not sold by themselves. The | ||
| 20 | +fonts, including any derivative works, can be bundled, embedded, | ||
| 21 | +redistributed and/or sold with any software provided that any reserved | ||
| 22 | +names are not used by derivative works. The fonts and derivatives, | ||
| 23 | +however, cannot be released under any other type of license. The | ||
| 24 | +requirement for fonts to remain under this license does not apply | ||
| 25 | +to any document created using the fonts or their derivatives. | ||
| 26 | + | ||
| 27 | +DEFINITIONS | ||
| 28 | +"Font Software" refers to the set of files released by the Copyright | ||
| 29 | +Holder(s) under this license and clearly marked as such. This may | ||
| 30 | +include source files, build scripts and documentation. | ||
| 31 | + | ||
| 32 | +"Reserved Font Name" refers to any names specified as such after the | ||
| 33 | +copyright statement(s). | ||
| 34 | + | ||
| 35 | +"Original Version" refers to the collection of Font Software components as | ||
| 36 | +distributed by the Copyright Holder(s). | ||
| 37 | + | ||
| 38 | +"Modified Version" refers to any derivative made by adding to, deleting, | ||
| 39 | +or substituting -- in part or in whole -- any of the components of the | ||
| 40 | +Original Version, by changing formats or by porting the Font Software to a | ||
| 41 | +new environment. | ||
| 42 | + | ||
| 43 | +"Author" refers to any designer, engineer, programmer, technical | ||
| 44 | +writer or other person who contributed to the Font Software. | ||
| 45 | + | ||
| 46 | +PERMISSION AND CONDITIONS | ||
| 47 | +Permission is hereby granted, free of charge, to any person obtaining | ||
| 48 | +a copy of the Font Software, to use, study, copy, merge, embed, modify, | ||
| 49 | +redistribute, and sell modified and unmodified copies of the Font | ||
| 50 | +Software, subject to the following conditions: | ||
| 51 | + | ||
| 52 | +1) Neither the Font Software nor any of its individual components, | ||
| 53 | +in Original or Modified Versions, may be sold by itself. | ||
| 54 | + | ||
| 55 | +2) Original or Modified Versions of the Font Software may be bundled, | ||
| 56 | +redistributed and/or sold with any software, provided that each copy | ||
| 57 | +contains the above copyright notice and this license. These can be | ||
| 58 | +included either as stand-alone text files, human-readable headers or | ||
| 59 | +in the appropriate machine-readable metadata fields within text or | ||
| 60 | +binary files as long as those fields can be easily viewed by the user. | ||
| 61 | + | ||
| 62 | +3) No Modified Version of the Font Software may use the Reserved Font | ||
| 63 | +Name(s) unless explicit written permission is granted by the corresponding | ||
| 64 | +Copyright Holder. This restriction only applies to the primary font name as | ||
| 65 | +presented to the users. | ||
| 66 | + | ||
| 67 | +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font | ||
| 68 | +Software shall not be used to promote, endorse or advertise any | ||
| 69 | +Modified Version, except to acknowledge the contribution(s) of the | ||
| 70 | +Copyright Holder(s) and the Author(s) or with their explicit written | ||
| 71 | +permission. | ||
| 72 | + | ||
| 73 | +5) The Font Software, modified or unmodified, in part or in whole, | ||
| 74 | +must be distributed entirely under this license, and must not be | ||
| 75 | +distributed under any other license. The requirement for fonts to | ||
| 76 | +remain under this license does not apply to any document created | ||
| 77 | +using the Font Software. | ||
| 78 | + | ||
| 79 | +TERMINATION | ||
| 80 | +This license becomes null and void if any of the above conditions are | ||
| 81 | +not met. | ||
| 82 | + | ||
| 83 | +DISCLAIMER | ||
| 84 | +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, | ||
| 85 | +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF | ||
| 86 | +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT | ||
| 87 | +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE | ||
| 88 | +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, | ||
| 89 | +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL | ||
| 90 | +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING | ||
| 91 | +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM | ||
| 92 | +OTHER DEALINGS IN THE FONT SOFTWARE. | ||
crates/client/src/gui.rsmodified+16 -0
| @@ -180,10 +180,26 @@ pub fn sync_accent(accent: Hsla, cx: &mut App) { | |||
| 180 | theme.tokens = (&theme.colors).into(); | 180 | theme.tokens = (&theme.colors).into(); |
| 181 | } | 181 | } |
| 182 | 182 | ||
| 183 | +pub fn load_fonts(cx: &mut App) { | ||
| 184 | + let fonts = [ | ||
| 185 | + include_bytes!("../assets/fonts/Inter-Regular.ttf").as_slice(), | ||
| 186 | + include_bytes!("../assets/fonts/Inter-Italic.ttf"), | ||
| 187 | + include_bytes!("../assets/fonts/Inter-Medium.ttf"), | ||
| 188 | + include_bytes!("../assets/fonts/Inter-SemiBold.ttf"), | ||
| 189 | + include_bytes!("../assets/fonts/Inter-Bold.ttf"), | ||
| 190 | + include_bytes!("../assets/fonts/Inter-BoldItalic.ttf"), | ||
| 191 | + ]; | ||
| 192 | + let fonts = fonts.into_iter().map(std::borrow::Cow::Borrowed).collect(); | ||
| 193 | + if let Err(error) = cx.text_system().add_fonts(fonts) { | ||
| 194 | + tracing::warn!("fonts: {error}"); | ||
| 195 | + } | ||
| 196 | +} | ||
| 197 | + | ||
| 183 | pub fn sync_theme(cx: &mut App) { | 198 | pub fn sync_theme(cx: &mut App) { |
| 184 | let palette = palette(cx); | 199 | let palette = palette(cx); |
| 185 | let font_size = cx.global::<Scale>().0.pixels(); | 200 | let font_size = cx.global::<Scale>().0.pixels(); |
| 186 | let theme = Theme::global_mut(cx); | 201 | let theme = Theme::global_mut(cx); |
| 202 | + theme.font_family = "Inter".into(); | ||
| 187 | let colors = &mut theme.colors; | 203 | let colors = &mut theme.colors; |
| 188 | 204 | ||
| 189 | colors.background = palette.panel; | 205 | colors.background = palette.panel; |
crates/client/src/gui/chat.rsmodified+23 -13
| @@ -57,7 +57,7 @@ use gpui_kit::{ | |||
| 57 | base::Selectable, | 57 | base::Selectable, |
| 58 | component::{ | 58 | component::{ |
| 59 | Icon, IndexPath, WindowExt, | 59 | Icon, IndexPath, WindowExt, |
| 60 | - input::{Input, InputEvent, InputState}, | 60 | + input::{InputEvent, InputState, Textarea, TextareaState}, |
| 61 | popover::Popover, | 61 | popover::Popover, |
| 62 | searchable_list::SearchableVec, | 62 | searchable_list::SearchableVec, |
| 63 | select::SelectState, | 63 | select::SelectState, |
| @@ -135,7 +135,7 @@ pub struct Chat { | |||
| 135 | pub(super) unread_anchor: Option<(Id, u32)>, | 135 | pub(super) unread_anchor: Option<(Id, u32)>, |
| 136 | unseen: u32, | 136 | unseen: u32, |
| 137 | pub(super) muted: HashSet<Id>, | 137 | pub(super) muted: HashSet<Id>, |
| 138 | - pub(super) message_input: Entity<InputState>, | 138 | + pub(super) message_input: Entity<TextareaState>, |
| 139 | pub(super) search_input: Entity<InputState>, | 139 | pub(super) search_input: Entity<InputState>, |
| 140 | pub(super) community_search: Entity<InputState>, | 140 | pub(super) community_search: Entity<InputState>, |
| 141 | pub(super) community_hits: Vec<MessageHit>, | 141 | pub(super) community_hits: Vec<MessageHit>, |
| @@ -149,6 +149,7 @@ pub struct Chat { | |||
| 149 | pub(super) poll_options: Vec<Entity<InputState>>, | 149 | pub(super) poll_options: Vec<Entity<InputState>>, |
| 150 | pub(super) poll_multiple: bool, | 150 | pub(super) poll_multiple: bool, |
| 151 | pub(super) poll_public: bool, | 151 | pub(super) poll_public: bool, |
| 152 | + pub(super) poll_duration: Option<u32>, | ||
| 152 | pub(super) plus_menu: composer::PlusMenu, | 153 | pub(super) plus_menu: composer::PlusMenu, |
| 153 | pub(super) my_votes: HashMap<Id, Vec<u32>>, | 154 | pub(super) my_votes: HashMap<Id, Vec<u32>>, |
| 154 | pub(super) poll_expanded: bool, | 155 | pub(super) poll_expanded: bool, |
| @@ -283,7 +284,13 @@ const HIGHLIGHT_TTL: Duration = Duration::from_secs(2); | |||
| 283 | 284 | ||
| 284 | impl Chat { | 285 | impl Chat { |
| 285 | pub fn new(window: &mut Window, cx: &mut Context<Yumush>) -> Self { | 286 | pub fn new(window: &mut Window, cx: &mut Context<Yumush>) -> Self { |
| 286 | - let message_input = new_input("Message", window, cx); | 287 | + let message_input = cx.new(|cx| { |
| 288 | + let mut state = TextareaState::new(window, cx) | ||
| 289 | + .auto_grow(1, 10) | ||
| 290 | + .submit_on_enter(true); | ||
| 291 | + state.set_placeholder("Message", window, cx); | ||
| 292 | + state | ||
| 293 | + }); | ||
| 287 | cx.subscribe_in( | 294 | cx.subscribe_in( |
| 288 | &message_input, | 295 | &message_input, |
| 289 | window, | 296 | window, |
| @@ -350,11 +357,12 @@ impl Chat { | |||
| 350 | pins: vec![], | 357 | pins: vec![], |
| 351 | poll_question: new_input("Question", window, cx), | 358 | poll_question: new_input("Question", window, cx), |
| 352 | poll_options: vec![ | 359 | poll_options: vec![ |
| 353 | - new_input("Option", window, cx), | 360 | + composer::new_poll_option(window, cx), |
| 354 | - new_input("Option", window, cx), | 361 | + composer::new_poll_option(window, cx), |
| 355 | ], | 362 | ], |
| 356 | poll_multiple: false, | 363 | poll_multiple: false, |
| 357 | - poll_public: false, | 364 | + poll_public: true, |
| 365 | + poll_duration: None, | ||
| 358 | plus_menu: composer::PlusMenu::Menu, | 366 | plus_menu: composer::PlusMenu::Menu, |
| 359 | my_votes: HashMap::new(), | 367 | my_votes: HashMap::new(), |
| 360 | poll_expanded: false, | 368 | poll_expanded: false, |
| @@ -520,11 +528,10 @@ impl Chat { | |||
| 520 | } | 528 | } |
| 521 | 529 | ||
| 522 | pub fn focus(&self, window: &mut Window, cx: &mut Context<Yumush>) { | 530 | pub fn focus(&self, window: &mut Window, cx: &mut Context<Yumush>) { |
| 523 | - let input = match self.selected_community_id { | 531 | + match self.selected_community_id { |
| 524 | - Some(_) => &self.message_input, | 532 | + Some(_) => self.message_input.update(cx, |input, cx| input.focus(window, cx)), |
| 525 | - None => &self.search_input, | 533 | + None => self.search_input.update(cx, |input, cx| input.focus(window, cx)), |
| 526 | - }; | 534 | + } |
| 527 | - input.update(cx, |input, cx| input.focus(window, cx)); | ||
| 528 | } | 535 | } |
| 529 | 536 | ||
| 530 | pub fn focus_find(&mut self, window: &mut Window, cx: &mut Context<Yumush>) { | 537 | pub fn focus_find(&mut self, window: &mut Window, cx: &mut Context<Yumush>) { |
| @@ -1573,7 +1580,7 @@ impl Yumush { | |||
| 1573 | .child(composer::plus_popover(&self.chat, &entity, palette)) | 1580 | .child(composer::plus_popover(&self.chat, &entity, palette)) |
| 1574 | .child(composer::format_popover(palette)) | 1581 | .child(composer::format_popover(palette)) |
| 1575 | .child( | 1582 | .child( |
| 1576 | - Input::new(&self.chat.message_input) | 1583 | + Textarea::new(&self.chat.message_input) |
| 1577 | .appearance(false) | 1584 | .appearance(false) |
| 1578 | .text_color(palette.text) | 1585 | .text_color(palette.text) |
| 1579 | .flex_1() | 1586 | .flex_1() |
| @@ -2917,7 +2924,10 @@ fn render_message( | |||
| 2917 | .line_height(relative(1.55)) | 2924 | .line_height(relative(1.55)) |
| 2918 | .text_color(palette.body) | 2925 | .text_color(palette.body) |
| 2919 | .child( | 2926 | .child( |
| 2920 | - div().min_w_0().child( | 2927 | + div() |
| 2928 | + .min_w_0() | ||
| 2929 | + .when(message.body.contains("```"), |this| this.w_full()) | ||
| 2930 | + .child( | ||
| 2921 | TextView::markdown( | 2931 | TextView::markdown( |
| 2922 | format!("message-body-{}", message.id), | 2932 | format!("message-body-{}", message.id), |
| 2923 | hard_breaks(&message.body), | 2933 | hard_breaks(&message.body), |
crates/client/src/gui/composer.rsmodified+78 -26
| @@ -17,7 +17,7 @@ use gpui_kit::{ | |||
| 17 | IntoElement, KeyBinding, MouseButton, ParentElement, Styled, Window, actions, | 17 | IntoElement, KeyBinding, MouseButton, ParentElement, Styled, Window, actions, |
| 18 | assets::IconName, | 18 | assets::IconName, |
| 19 | component::{ | 19 | component::{ |
| 20 | - Icon, WindowExt, checkbox::Checkbox, input::InputState, notification::Notification, | 20 | + Icon, WindowExt, checkbox::Checkbox, input::{InputEvent, InputState, TextareaState}, notification::Notification, |
| 21 | popover::Popover, text::TextView, | 21 | popover::Popover, text::TextView, |
| 22 | }, | 22 | }, |
| 23 | div, px, | 23 | div, px, |
| @@ -190,7 +190,7 @@ fn cancel_button(entity: &Entity<Yumush>, palette: Palette) -> impl IntoElement | |||
| 190 | impl Yumush { | 190 | impl Yumush { |
| 191 | pub(super) fn submit_composer( | 191 | pub(super) fn submit_composer( |
| 192 | &mut self, | 192 | &mut self, |
| 193 | - input: &Entity<InputState>, | 193 | + input: &Entity<TextareaState>, |
| 194 | window: &mut Window, | 194 | window: &mut Window, |
| 195 | cx: &mut Context<Self>, | 195 | cx: &mut Context<Self>, |
| 196 | ) { | 196 | ) { |
| @@ -239,7 +239,7 @@ impl Yumush { | |||
| 239 | &mut self, | 239 | &mut self, |
| 240 | reply: Option<Id>, | 240 | reply: Option<Id>, |
| 241 | body: String, | 241 | body: String, |
| 242 | - input: &Entity<InputState>, | 242 | + input: &Entity<TextareaState>, |
| 243 | window: &mut Window, | 243 | window: &mut Window, |
| 244 | cx: &mut Context<Self>, | 244 | cx: &mut Context<Self>, |
| 245 | ) { | 245 | ) { |
| @@ -306,7 +306,7 @@ impl Yumush { | |||
| 306 | 306 | ||
| 307 | fn restore_message( | 307 | fn restore_message( |
| 308 | &mut self, | 308 | &mut self, |
| 309 | - input: &Entity<InputState>, | 309 | + input: &Entity<TextareaState>, |
| 310 | community_id: Id, | 310 | community_id: Id, |
| 311 | body: String, | 311 | body: String, |
| 312 | pending: Vec<Attachment>, | 312 | pending: Vec<Attachment>, |
| @@ -348,7 +348,7 @@ impl Yumush { | |||
| 348 | &mut self, | 348 | &mut self, |
| 349 | message_id: Id, | 349 | message_id: Id, |
| 350 | body: String, | 350 | body: String, |
| 351 | - input: &Entity<InputState>, | 351 | + input: &Entity<TextareaState>, |
| 352 | window: &mut Window, | 352 | window: &mut Window, |
| 353 | cx: &mut Context<Self>, | 353 | cx: &mut Context<Self>, |
| 354 | ) { | 354 | ) { |
| @@ -490,7 +490,7 @@ pub fn bind_keys(cx: &mut App) { | |||
| 490 | ]); | 490 | ]); |
| 491 | } | 491 | } |
| 492 | 492 | ||
| 493 | -pub fn format_actions(input: &Entity<InputState>, row: Div) -> Div { | 493 | +pub fn format_actions(input: &Entity<TextareaState>, row: Div) -> Div { |
| 494 | let (bold, italic, code, strike) = (input.clone(), input.clone(), input.clone(), input.clone()); | 494 | let (bold, italic, code, strike) = (input.clone(), input.clone(), input.clone(), input.clone()); |
| 495 | row.key_context(CONTEXT) | 495 | row.key_context(CONTEXT) |
| 496 | .on_action(move |_: &Bold, window, cx| wrap(&bold, "**", window, cx)) | 496 | .on_action(move |_: &Bold, window, cx| wrap(&bold, "**", window, cx)) |
| @@ -499,7 +499,7 @@ pub fn format_actions(input: &Entity<InputState>, row: Div) -> Div { | |||
| 499 | .on_action(move |_: &Strike, window, cx| wrap(&strike, "~~", window, cx)) | 499 | .on_action(move |_: &Strike, window, cx| wrap(&strike, "~~", window, cx)) |
| 500 | } | 500 | } |
| 501 | 501 | ||
| 502 | -fn wrap(input: &Entity<InputState>, mark: &str, window: &mut Window, cx: &mut App) { | 502 | +fn wrap(input: &Entity<TextareaState>, mark: &str, window: &mut Window, cx: &mut App) { |
| 503 | input.update(cx, |state, cx| { | 503 | input.update(cx, |state, cx| { |
| 504 | let start = state.selected_range().start + mark.len(); | 504 | let start = state.selected_range().start + mark.len(); |
| 505 | let selected = state.selected_text().to_string(); | 505 | let selected = state.selected_text().to_string(); |
| @@ -595,6 +595,7 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 595 | let options = chat.poll_options.clone(); | 595 | let options = chat.poll_options.clone(); |
| 596 | let multiple = chat.poll_multiple; | 596 | let multiple = chat.poll_multiple; |
| 597 | let public = chat.poll_public; | 597 | let public = chat.poll_public; |
| 598 | + let duration = chat.poll_duration; | ||
| 598 | let reset = entity.clone(); | 599 | let reset = entity.clone(); |
| 599 | let entity = entity.clone(); | 600 | let entity = entity.clone(); |
| 600 | 601 | ||
| @@ -659,7 +660,7 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 659 | } | 660 | } |
| 660 | let toggle = entity.clone(); | 661 | let toggle = entity.clone(); |
| 661 | let toggle_public = entity.clone(); | 662 | let toggle_public = entity.clone(); |
| 662 | - let add = entity.clone(); | 663 | + let duration_entity = entity.clone(); |
| 663 | let submit = entity.clone(); | 664 | let submit = entity.clone(); |
| 664 | pop_in( | 665 | pop_in( |
| 665 | "poll_form", | 666 | "poll_form", |
| @@ -673,6 +674,8 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 673 | .child(compact_field(palette, &question)) | 674 | .child(compact_field(palette, &question)) |
| 674 | .children(options.iter().enumerate().map(|(index, option)| { | 675 | .children(options.iter().enumerate().map(|(index, option)| { |
| 675 | let remove = entity.clone(); | 676 | let remove = entity.clone(); |
| 677 | + let trailing_blank = | ||
| 678 | + index + 1 == options.len() && option_text(option, cx).is_empty(); | ||
| 676 | div() | 679 | div() |
| 677 | .flex() | 680 | .flex() |
| 678 | .items_center() | 681 | .items_center() |
| @@ -683,7 +686,7 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 683 | .min_w_0() | 686 | .min_w_0() |
| 684 | .child(compact_field(palette, option)), | 687 | .child(compact_field(palette, option)), |
| 685 | ) | 688 | ) |
| 686 | - .children((options.len() > MINIMUM_POLL_OPTIONS).then(|| { | 689 | + .children((options.len() > MINIMUM_POLL_OPTIONS && !trailing_blank).then(|| { |
| 687 | icon_button( | 690 | icon_button( |
| 688 | format!("poll_remove_{index}"), | 691 | format!("poll_remove_{index}"), |
| 689 | palette, | 692 | palette, |
| @@ -697,6 +700,30 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 697 | ) | 700 | ) |
| 698 | })) | 701 | })) |
| 699 | })) | 702 | })) |
| 703 | + .child( | ||
| 704 | + div() | ||
| 705 | + .flex() | ||
| 706 | + .items_center() | ||
| 707 | + .gap(px(4.)) | ||
| 708 | + .text_color(palette.muted) | ||
| 709 | + .child(Icon::new(IconName::Timer).w(px(14.)).h(px(14.))) | ||
| 710 | + .children(POLL_DURATIONS.map(|(label, seconds)| { | ||
| 711 | + let set = duration_entity.clone(); | ||
| 712 | + let active = duration == seconds; | ||
| 713 | + clickable(label, palette, move |_, cx| { | ||
| 714 | + set.update(cx, |yumush, cx| { | ||
| 715 | + yumush.chat.poll_duration = seconds; | ||
| 716 | + cx.notify(); | ||
| 717 | + }) | ||
| 718 | + }) | ||
| 719 | + .px(px(6.)) | ||
| 720 | + .py(px(2.)) | ||
| 721 | + .rounded(px(4.)) | ||
| 722 | + .text_color(if active { palette.accent } else { palette.muted }) | ||
| 723 | + .bg(palette.accent.opacity(if active { 0.15 } else { 0. })) | ||
| 724 | + .child(label) | ||
| 725 | + })), | ||
| 726 | + ) | ||
| 700 | .child( | 727 | .child( |
| 701 | div() | 728 | div() |
| 702 | .flex() | 729 | .flex() |
| @@ -729,20 +756,7 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 729 | }) | 756 | }) |
| 730 | }), | 757 | }), |
| 731 | ), | 758 | ), |
| 732 | - ) | 759 | + ), |
| 733 | - .children((options.len() < MAXIMUM_POLL_OPTIONS).then(|| { | ||
| 734 | - icon_button( | ||
| 735 | - "poll_add", | ||
| 736 | - palette, | ||
| 737 | - IconName::Plus, | ||
| 738 | - "Add option", | ||
| 739 | - move |window, cx| { | ||
| 740 | - add.update(cx, |yumush, cx| { | ||
| 741 | - yumush.add_poll_option(window, cx) | ||
| 742 | - }); | ||
| 743 | - }, | ||
| 744 | - ) | ||
| 745 | - })), | ||
| 746 | ) | 760 | ) |
| 747 | .child( | 761 | .child( |
| 748 | primary_button("poll_create", palette, move |window, cx| { | 762 | primary_button("poll_create", palette, move |window, cx| { |
| @@ -763,10 +777,44 @@ pub fn plus_popover(chat: &Chat, entity: &Entity<Yumush>, palette: Palette) -> i | |||
| 763 | }) | 777 | }) |
| 764 | } | 778 | } |
| 765 | 779 | ||
| 780 | +const POLL_DURATIONS: [(&str, Option<u32>); 4] = [ | ||
| 781 | + ("∞", None), | ||
| 782 | + ("1h", Some(3600)), | ||
| 783 | + ("1d", Some(86400)), | ||
| 784 | + ("1w", Some(604800)), | ||
| 785 | +]; | ||
| 786 | + | ||
| 787 | +fn option_text(input: &Entity<InputState>, cx: &App) -> String { | ||
| 788 | + input.read(cx).text().to_string().trim().to_owned() | ||
| 789 | +} | ||
| 790 | + | ||
| 791 | +pub(super) fn new_poll_option(window: &mut Window, cx: &mut Context<Yumush>) -> Entity<InputState> { | ||
| 792 | + let input = new_input("Option", window, cx); | ||
| 793 | + cx.subscribe_in(&input, window, |this, input, event, window, cx| { | ||
| 794 | + if matches!(event, InputEvent::Change) { | ||
| 795 | + this.grow_poll_options(input, window, cx); | ||
| 796 | + } | ||
| 797 | + }) | ||
| 798 | + .detach(); | ||
| 799 | + input | ||
| 800 | +} | ||
| 801 | + | ||
| 766 | impl Yumush { | 802 | impl Yumush { |
| 803 | + fn grow_poll_options( | ||
| 804 | + &mut self, | ||
| 805 | + input: &Entity<InputState>, | ||
| 806 | + window: &mut Window, | ||
| 807 | + cx: &mut Context<Self>, | ||
| 808 | + ) { | ||
| 809 | + let last = self.chat.poll_options.last() == Some(input); | ||
| 810 | + if last && !option_text(input, cx).is_empty() { | ||
| 811 | + self.add_poll_option(window, cx); | ||
| 812 | + } | ||
| 813 | + } | ||
| 814 | + | ||
| 767 | pub(super) fn add_poll_option(&mut self, window: &mut Window, cx: &mut Context<Self>) { | 815 | pub(super) fn add_poll_option(&mut self, window: &mut Window, cx: &mut Context<Self>) { |
| 768 | if self.chat.poll_options.len() < MAXIMUM_POLL_OPTIONS { | 816 | if self.chat.poll_options.len() < MAXIMUM_POLL_OPTIONS { |
| 769 | - let input = new_input("Option", window, cx); | 817 | + let input = new_poll_option(window, cx); |
| 770 | self.chat.poll_options.push(input); | 818 | self.chat.poll_options.push(input); |
| 771 | cx.notify(); | 819 | cx.notify(); |
| 772 | } | 820 | } |
| @@ -790,7 +838,8 @@ impl Yumush { | |||
| 790 | .chat | 838 | .chat |
| 791 | .poll_options | 839 | .poll_options |
| 792 | .iter() | 840 | .iter() |
| 793 | - .map(|input| input.read(cx).text().to_string()) | 841 | + .map(|input| option_text(input, cx)) |
| 842 | + .filter(|text| !text.is_empty()) | ||
| 794 | .collect(); | 843 | .collect(); |
| 795 | if let Err(error) = validate_poll(&question, &options) { | 844 | if let Err(error) = validate_poll(&question, &options) { |
| 796 | window.push_notification(Notification::error(error.to_string()), cx); | 845 | window.push_notification(Notification::error(error.to_string()), cx); |
| @@ -798,6 +847,7 @@ impl Yumush { | |||
| 798 | } | 847 | } |
| 799 | let multiple = self.chat.poll_multiple; | 848 | let multiple = self.chat.poll_multiple; |
| 800 | let public = self.chat.poll_public; | 849 | let public = self.chat.poll_public; |
| 850 | + let duration = self.chat.poll_duration; | ||
| 801 | let network = self.network.clone(); | 851 | let network = self.network.clone(); |
| 802 | 852 | ||
| 803 | spawn_done(window, cx, async move { | 853 | spawn_done(window, cx, async move { |
| @@ -808,6 +858,7 @@ impl Yumush { | |||
| 808 | options, | 858 | options, |
| 809 | multiple, | 859 | multiple, |
| 810 | public, | 860 | public, |
| 861 | + duration, | ||
| 811 | }) | 862 | }) |
| 812 | .await | 863 | .await |
| 813 | }); | 864 | }); |
| @@ -820,7 +871,8 @@ impl Yumush { | |||
| 820 | input.update(cx, |state, cx| state.set_value("", window, cx)); | 871 | input.update(cx, |state, cx| state.set_value("", window, cx)); |
| 821 | } | 872 | } |
| 822 | self.chat.poll_multiple = false; | 873 | self.chat.poll_multiple = false; |
| 823 | - self.chat.poll_public = false; | 874 | + self.chat.poll_public = true; |
| 875 | + self.chat.poll_duration = None; | ||
| 824 | cx.notify(); | 876 | cx.notify(); |
| 825 | true | 877 | true |
| 826 | } | 878 | } |
crates/client/src/gui/poll.rsmodified+53 -16
| @@ -1,6 +1,7 @@ | |||
| 1 | use common::model::Id; | 1 | use common::model::Id; |
| 2 | use common::call::{ClosePoll, MyVotes, Vote}; | 2 | use common::call::{ClosePoll, MyVotes, Vote}; |
| 3 | use common::model::{Message, Poll, Rank, User}; | 3 | use common::model::{Message, Poll, Rank, User}; |
| 4 | +use common::time::{DAY_MILLIS, HOUR_MILLIS, MINUTE_MILLIS, now_ms}; | ||
| 4 | use gpui_kit::{ | 5 | use gpui_kit::{ |
| 5 | Anchor, AnyElement, Context, Div, Entity, FontWeight, InteractiveElement, IntoElement, | 6 | Anchor, AnyElement, Context, Div, Entity, FontWeight, InteractiveElement, IntoElement, |
| 6 | ParentElement, StatefulInteractiveElement, Styled, Window, assets::IconName, component::Icon, component::popover::Popover, | 7 | ParentElement, StatefulInteractiveElement, Styled, Window, assets::IconName, component::Icon, component::popover::Popover, |
| @@ -152,6 +153,21 @@ fn voters_popover(key: &str, poll: &Poll, entity: &Entity<Yumush>, palette: Pale | |||
| 152 | .into_any_element() | 153 | .into_any_element() |
| 153 | } | 154 | } |
| 154 | 155 | ||
| 156 | +pub fn is_closed(poll: &Poll) -> bool { | ||
| 157 | + poll.closed || poll.ends_at.is_some_and(|end| end <= now_ms()) | ||
| 158 | +} | ||
| 159 | + | ||
| 160 | +fn remaining(end: u64) -> String { | ||
| 161 | + let left = end.saturating_sub(now_ms()); | ||
| 162 | + if left >= DAY_MILLIS { | ||
| 163 | + format!("{}d", left / DAY_MILLIS) | ||
| 164 | + } else if left >= HOUR_MILLIS { | ||
| 165 | + format!("{}h", left / HOUR_MILLIS) | ||
| 166 | + } else { | ||
| 167 | + format!("{}m", (left / MINUTE_MILLIS).max(1)) | ||
| 168 | + } | ||
| 169 | +} | ||
| 170 | + | ||
| 155 | pub fn poll_card( | 171 | pub fn poll_card( |
| 156 | poll: &Poll, | 172 | poll: &Poll, |
| 157 | mode: PollMode, | 173 | mode: PollMode, |
| @@ -161,6 +177,7 @@ pub fn poll_card( | |||
| 161 | palette: Palette, | 177 | palette: Palette, |
| 162 | ) -> impl IntoElement { | 178 | ) -> impl IntoElement { |
| 163 | let voters = voter_count(poll); | 179 | let voters = voter_count(poll); |
| 180 | + let closed = is_closed(poll); | ||
| 164 | let me_id = me.map(|me| me.id); | 181 | let me_id = me.map(|me| me.id); |
| 165 | let (key, live) = match mode { | 182 | let (key, live) = match mode { |
| 166 | PollMode::Live(message) => (message.id.to_string(), Some(message)), | 183 | PollMode::Live(message) => (message.id.to_string(), Some(message)), |
| @@ -174,11 +191,11 @@ pub fn poll_card( | |||
| 174 | .unwrap_or_default(), | 191 | .unwrap_or_default(), |
| 175 | }; | 192 | }; |
| 176 | let vote_id = live | 193 | let vote_id = live |
| 177 | - .filter(|_| !poll.closed && me_id.is_some()) | 194 | + .filter(|_| !closed && me_id.is_some()) |
| 178 | .map(|message| message.id); | 195 | .map(|message| message.id); |
| 179 | let close_id = live | 196 | let close_id = live |
| 180 | .filter(|message| { | 197 | .filter(|message| { |
| 181 | - !poll.closed | 198 | + !closed |
| 182 | && me.is_some_and(|me| { | 199 | && me.is_some_and(|me| { |
| 183 | me.id == message.user_id || chat.rank_of(me) >= Some(Rank::Moderator) | 200 | me.id == message.user_id || chat.rank_of(me) >= Some(Rank::Moderator) |
| 184 | }) | 201 | }) |
| @@ -295,6 +312,18 @@ pub fn poll_card( | |||
| 295 | voters_label(voters).into_any_element() | 312 | voters_label(voters).into_any_element() |
| 296 | }; | 313 | }; |
| 297 | 314 | ||
| 315 | + let timer = poll | ||
| 316 | + .ends_at | ||
| 317 | + .filter(|_| !closed) | ||
| 318 | + .map(|end| { | ||
| 319 | + div() | ||
| 320 | + .flex() | ||
| 321 | + .items_center() | ||
| 322 | + .gap(px(4.)) | ||
| 323 | + .child(Icon::new(IconName::Timer).w(px(12.)).h(px(12.))) | ||
| 324 | + .child(remaining(end)) | ||
| 325 | + }); | ||
| 326 | + | ||
| 298 | let footer = div() | 327 | let footer = div() |
| 299 | .flex() | 328 | .flex() |
| 300 | .items_center() | 329 | .items_center() |
| @@ -302,18 +331,26 @@ pub fn poll_card( | |||
| 302 | .text_size(text(12.)) | 331 | .text_size(text(12.)) |
| 303 | .text_color(palette.muted) | 332 | .text_color(palette.muted) |
| 304 | .child(voters_view) | 333 | .child(voters_view) |
| 305 | - .children(close_id.map(|close_id| { | 334 | + .child( |
| 306 | - let close_entity = entity.clone(); | 335 | + div() |
| 307 | - icon_button( | 336 | + .flex() |
| 308 | - format!("poll_close_{close_id}"), | 337 | + .items_center() |
| 309 | - palette, | 338 | + .gap(px(8.)) |
| 310 | - IconName::CircleStop, | 339 | + .children(timer) |
| 311 | - "End poll", | 340 | + .children(close_id.map(|close_id| { |
| 312 | - move |window, cx| { | 341 | + let close_entity = entity.clone(); |
| 313 | - close_entity.update(cx, |yumush, cx| yumush.close_poll(close_id, window, cx)); | 342 | + icon_button( |
| 314 | - }, | 343 | + format!("poll_close_{close_id}"), |
| 315 | - ) | 344 | + palette, |
| 316 | - })); | 345 | + IconName::CircleStop, |
| 346 | + "End poll", | ||
| 347 | + move |window, cx| { | ||
| 348 | + close_entity | ||
| 349 | + .update(cx, |yumush, cx| yumush.close_poll(close_id, window, cx)); | ||
| 350 | + }, | ||
| 351 | + ) | ||
| 352 | + })), | ||
| 353 | + ); | ||
| 317 | 354 | ||
| 318 | let (visibility, visibility_tip) = if poll.public { | 355 | let (visibility, visibility_tip) = if poll.public { |
| 319 | (IconName::Eye, "Voters visible") | 356 | (IconName::Eye, "Voters visible") |
| @@ -365,7 +402,7 @@ pub fn poll_card( | |||
| 365 | palette, | 402 | palette, |
| 366 | ) | 403 | ) |
| 367 | })) | 404 | })) |
| 368 | - .children(poll.closed.then(|| { | 405 | + .children(closed.then(|| { |
| 369 | status_icon( | 406 | status_icon( |
| 370 | format!("poll_closed_{key}"), | 407 | format!("poll_closed_{key}"), |
| 371 | IconName::Lock, | 408 | IconName::Lock, |
| @@ -384,7 +421,7 @@ impl Yumush { | |||
| 384 | let (message, poll) = self.chat.pins.iter().find_map(|pin| { | 421 | let (message, poll) = self.chat.pins.iter().find_map(|pin| { |
| 385 | pin.poll | 422 | pin.poll |
| 386 | .as_ref() | 423 | .as_ref() |
| 387 | - .filter(|poll| !poll.closed) | 424 | + .filter(|poll| !is_closed(poll)) |
| 388 | .map(|poll| (pin, poll)) | 425 | .map(|poll| (pin, poll)) |
| 389 | })?; | 426 | })?; |
| 390 | let me = self.user.as_ref(); | 427 | let me = self.user.as_ref(); |
crates/client/src/main.rsmodified+1 -0
| @@ -33,6 +33,7 @@ fn main() { | |||
| 33 | .with_quit_mode(QuitMode::Explicit) | 33 | .with_quit_mode(QuitMode::Explicit) |
| 34 | .run(move |cx: &mut App| { | 34 | .run(move |cx: &mut App| { |
| 35 | init(cx); | 35 | init(cx); |
| 36 | + gui::load_fonts(cx); | ||
| 36 | settings::apply(settings.theme, settings.font_size, cx); | 37 | settings::apply(settings.theme, settings.font_size, cx); |
| 37 | gui::bind_keys(cx); | 38 | gui::bind_keys(cx); |
| 38 | 39 | ||
crates/common/src/call.rsmodified+1 -0
| @@ -222,6 +222,7 @@ pub struct CreatePoll { | |||
| 222 | pub options: Vec<String>, | 222 | pub options: Vec<String>, |
| 223 | pub multiple: bool, | 223 | pub multiple: bool, |
| 224 | pub public: bool, | 224 | pub public: bool, |
| 225 | + pub duration: Option<u32>, | ||
| 225 | } | 226 | } |
| 226 | 227 | ||
| 227 | #[derive(Debug, Clone, Encode, Decode)] | 228 | #[derive(Debug, Clone, Encode, Decode)] |
crates/common/src/model.rsmodified+1 -0
| @@ -578,6 +578,7 @@ pub struct Poll { | |||
| 578 | pub closed: bool, | 578 | pub closed: bool, |
| 579 | pub public: bool, | 579 | pub public: bool, |
| 580 | pub voters: u32, | 580 | pub voters: u32, |
| 581 | + pub ends_at: Option<u64>, | ||
| 581 | } | 582 | } |
| 582 | 583 | ||
| 583 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] | 584 | #[derive(Debug, Clone, PartialEq, Eq, Encode, Decode)] |
crates/server/src/call/message.rsmodified+1 -10
| @@ -160,16 +160,7 @@ impl Handle for CreatePoll { | |||
| 160 | let settings = db::settings::read(cx.db).await?; | 160 | let settings = db::settings::read(cx.db).await?; |
| 161 | limit_messages(&me, &settings, cx)?; | 161 | limit_messages(&me, &settings, cx)?; |
| 162 | allowed(&me, self.community_id, cx.db, permission::can_post).await?; | 162 | allowed(&me, self.community_id, cx.db, permission::can_post).await?; |
| 163 | - let created = db::message::create_poll( | 163 | + let created = db::message::create_poll(me.id, &self, cx.db).await?; |
| 164 | - me.id, | ||
| 165 | - self.community_id, | ||
| 166 | - &self.question, | ||
| 167 | - &self.options, | ||
| 168 | - self.multiple, | ||
| 169 | - self.public, | ||
| 170 | - cx.db, | ||
| 171 | - ) | ||
| 172 | - .await?; | ||
| 173 | db::stats::mark_active(me.id, cx.db).await?; | 164 | db::stats::mark_active(me.id, cx.db).await?; |
| 174 | cx.out.push(message_event(&created, Event::MessageCreated)); | 165 | cx.out.push(message_event(&created, Event::MessageCreated)); |
| 175 | 166 | ||
crates/server/src/db/message.rsmodified+3 -7
| @@ -188,15 +188,11 @@ pub async fn pinned(community_id: Id, db: &Connection) -> Result<Vec<Message>, S | |||
| 188 | 188 | ||
| 189 | pub async fn create_poll( | 189 | pub async fn create_poll( |
| 190 | user_id: Id, | 190 | user_id: Id, |
| 191 | - community_id: Id, | 191 | + poll: &common::call::CreatePoll, |
| 192 | - question: &str, | ||
| 193 | - options: &[String], | ||
| 194 | - multiple: bool, | ||
| 195 | - public: bool, | ||
| 196 | db: &Connection, | 192 | db: &Connection, |
| 197 | ) -> Result<Message, ServerError> { | 193 | ) -> Result<Message, ServerError> { |
| 198 | - let id = insert(user_id, community_id, "", None, db).await?; | 194 | + let id = insert(user_id, poll.community_id, "", None, db).await?; |
| 199 | - poll::create(id, question, options, multiple, public, db).await?; | 195 | + poll::create(id, poll, db).await?; |
| 200 | 196 | ||
| 201 | read(id, db).await | 197 | read(id, db).await |
| 202 | } | 198 | } |
crates/server/src/db/poll.rsmodified+21 -12
| @@ -1,25 +1,29 @@ | |||
| 1 | use std::collections::HashSet; | 1 | use std::collections::HashSet; |
| 2 | 2 | ||
| 3 | use common::{ | 3 | use common::{ |
| 4 | + call::CreatePoll, | ||
| 4 | error::Error, | 5 | error::Error, |
| 5 | model::{Id, Poll, PollOption}, | 6 | model::{Id, Poll, PollOption}, |
| 7 | + time::now_ms, | ||
| 6 | }; | 8 | }; |
| 7 | 9 | ||
| 8 | use super::{Connection, all, maybe, run}; | 10 | use super::{Connection, all, maybe, run}; |
| 9 | use crate::error::{ServerError, ensure_with}; | 11 | use crate::error::{ServerError, ensure_with}; |
| 10 | 12 | ||
| 11 | -pub async fn create( | 13 | +pub async fn create(message_id: Id, poll: &CreatePoll, db: &Connection) -> Result<(), ServerError> { |
| 12 | - message_id: Id, | 14 | + let CreatePoll { |
| 13 | - question: &str, | 15 | + question, |
| 14 | - options: &[String], | 16 | + options, |
| 15 | - multiple: bool, | 17 | + multiple, |
| 16 | - public: bool, | 18 | + public, |
| 17 | - db: &Connection, | 19 | + duration, |
| 18 | -) -> Result<(), ServerError> { | 20 | + .. |
| 21 | + } = poll; | ||
| 22 | + let ends_at = duration.map(|seconds| (now_ms() + u64::from(seconds) * 1000) as i64); | ||
| 19 | run( | 23 | run( |
| 20 | db, | 24 | db, |
| 21 | - "INSERT INTO poll (message_id, question, multiple, public) VALUES (?1, ?2, ?3, ?4)", | 25 | + "INSERT INTO poll (message_id, question, multiple, public, ends_at) VALUES (?1, ?2, ?3, ?4, ?5)", |
| 22 | - (message_id, question, multiple, public), | 26 | + (message_id, question.as_str(), *multiple, *public, ends_at), |
| 23 | ) | 27 | ) |
| 24 | .await?; | 28 | .await?; |
| 25 | for (position, text) in (0u32..).zip(options) { | 29 | for (position, text) in (0u32..).zip(options) { |
| @@ -35,9 +39,9 @@ pub async fn create( | |||
| 35 | } | 39 | } |
| 36 | 40 | ||
| 37 | pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerError> { | 41 | pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerError> { |
| 38 | - let Some((question, multiple, closed, public)) = maybe( | 42 | + let Some((question, multiple, closed, public, ends_at)) = maybe( |
| 39 | db, | 43 | db, |
| 40 | - "SELECT question, multiple, closed, public FROM poll WHERE message_id = ?1", | 44 | + "SELECT question, multiple, closed, public, ends_at FROM poll WHERE message_id = ?1", |
| 41 | (message_id,), | 45 | (message_id,), |
| 42 | |r| { | 46 | |r| { |
| 43 | Ok(( | 47 | Ok(( |
| @@ -45,6 +49,7 @@ pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerE | |||
| 45 | r.get::<bool>()?, | 49 | r.get::<bool>()?, |
| 46 | r.get::<bool>()?, | 50 | r.get::<bool>()?, |
| 47 | r.get::<bool>()?, | 51 | r.get::<bool>()?, |
| 52 | + r.get::<Option<i64>>()?, | ||
| 48 | )) | 53 | )) |
| 49 | }, | 54 | }, |
| 50 | ) | 55 | ) |
| @@ -87,6 +92,9 @@ pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerE | |||
| 87 | } | 92 | } |
| 88 | } | 93 | } |
| 89 | 94 | ||
| 95 | + let ends_at = ends_at.map(|ms| ms as u64); | ||
| 96 | + let closed = closed || ends_at.is_some_and(|end| end <= now_ms()); | ||
| 97 | + | ||
| 90 | Ok(Some(Poll { | 98 | Ok(Some(Poll { |
| 91 | question, | 99 | question, |
| 92 | options, | 100 | options, |
| @@ -94,6 +102,7 @@ pub async fn of(message_id: Id, db: &Connection) -> Result<Option<Poll>, ServerE | |||
| 94 | closed, | 102 | closed, |
| 95 | public, | 103 | public, |
| 96 | voters, | 104 | voters, |
| 105 | + ends_at, | ||
| 97 | })) | 106 | })) |
| 98 | } | 107 | } |
| 99 | 108 | ||
crates/server/src/db/schema.sqlmodified+2 -1
| @@ -123,7 +123,8 @@ CREATE TABLE poll ( | |||
| 123 | question TEXT NOT NULL, | 123 | question TEXT NOT NULL, |
| 124 | multiple INTEGER NOT NULL, | 124 | multiple INTEGER NOT NULL, |
| 125 | closed INTEGER NOT NULL DEFAULT 0, | 125 | closed INTEGER NOT NULL DEFAULT 0, |
| 126 | - public INTEGER NOT NULL DEFAULT 0 | 126 | + public INTEGER NOT NULL DEFAULT 0, |
| 127 | + ends_at INTEGER | ||
| 127 | ) STRICT; | 128 | ) STRICT; |
| 128 | 129 | ||
| 129 | CREATE TABLE poll_option ( | 130 | CREATE TABLE poll_option ( |
harness/ui.shmodified+1 -0
| @@ -8,6 +8,7 @@ case "$1" in | |||
| 8 | move) to "$2" "$3";; | 8 | move) to "$2" "$3";; |
| 9 | type) wtype "$2";; | 9 | type) wtype "$2";; |
| 10 | key) wtype -k "$2";; | 10 | key) wtype -k "$2";; |
| 11 | + chord) wtype -M "$2" -k "$3" -m "$2";; | ||
| 11 | clear) args=(); for _ in $(seq "${2:-30}"); do args+=(-k BackSpace); done; wtype "${args[@]}";; | 12 | clear) args=(); for _ in $(seq "${2:-30}"); do args+=(-k BackSpace); done; wtype "${args[@]}";; |
| 12 | field) to "$2" "$3"; wlrctl pointer click left; sleep 0.2; wlrctl pointer click left; sleep 0.2 | 13 | field) to "$2" "$3"; wlrctl pointer click left; sleep 0.2; wlrctl pointer click left; sleep 0.2 |
| 13 | args=(); for _ in $(seq 30); do args+=(-k BackSpace); done; wtype "${args[@]}"; sleep 0.2; wtype "$4";; | 14 | args=(); for _ in $(seq 30); do args+=(-k BackSpace); done; wtype "${args[@]}"; sleep 0.2; wtype "$4";; |