@@ -17,10 +17,8 @@ use crate::zulip::client::ZulipClient;
1717use crate :: zulip:: commands:: { ChatCommand , LookupCmd , WorkqueueCmd , WorkqueueLimit } ;
1818use anyhow:: { format_err, Context as _} ;
1919use clap:: Parser ;
20- use postgres_types:: ToSql ;
2120use rust_team_data:: v1:: TeamKind ;
2221use std:: fmt:: Write as _;
23- use std:: str:: FromStr ;
2422use subtle:: ConstantTimeEq ;
2523use tracing as log;
2624
@@ -199,12 +197,15 @@ fn handle_command<'a>(
199197 let cmd = ChatCommand :: try_parse_from ( words) ?;
200198 match cmd {
201199 ChatCommand :: Acknowledge { identifier } => {
202- acknowledge ( & ctx, gh_id, identifier. into ( ) ) . await
200+ acknowledge ( & ctx, gh_id, ( & identifier) . into ( ) ) . await
203201 }
204202 ChatCommand :: Add { url, description } => {
205203 add_notification ( & ctx, gh_id, & url, & description. join ( " " ) ) . await
206204 }
207205 ChatCommand :: Move { from, to } => move_notification ( & ctx, gh_id, from, to) . await ,
206+ ChatCommand :: Meta { index, description } => {
207+ add_meta_notification ( & ctx, gh_id, index, & description. join ( " " ) ) . await
208+ }
208209 ChatCommand :: Whoami => whoami_cmd ( & ctx, gh_id) . await ,
209210 ChatCommand :: Lookup ( cmd) => lookup_cmd ( & ctx, cmd) . await ,
210211 ChatCommand :: Work ( cmd) => workqueue_commands ( ctx, gh_id, cmd) . await ,
@@ -699,15 +700,15 @@ impl<'a> UpdateMessageApiRequest<'a> {
699700 }
700701}
701702
702- async fn acknowledge (
703+ async fn acknowledge < ' a > (
703704 ctx : & Context ,
704705 gh_id : u64 ,
705- ident : Identifier ,
706+ ident : Identifier < ' a > ,
706707) -> anyhow:: Result < Option < String > > {
707708 let mut db = ctx. db . get ( ) . await ;
708709 let deleted = delete_ping ( & mut * db, gh_id, ident)
709710 . await
710- . map_err ( |e| format_err ! ( "Failed to acknowledge {filter }: {e:?}." ) ) ?;
711+ . map_err ( |e| format_err ! ( "Failed to acknowledge {ident:? }: {e:?}." ) ) ?;
711712
712713 let resp = if deleted. is_empty ( ) {
713714 format ! ( "No notifications matched `{ident:?}`, so none were deleted." )
@@ -765,27 +766,16 @@ async fn add_notification(
765766async fn add_meta_notification (
766767 ctx : & Context ,
767768 gh_id : u64 ,
768- mut words : impl Iterator < Item = & str > ,
769+ idx : u32 ,
770+ description : & str ,
769771) -> anyhow:: Result < Option < String > > {
770- let idx = match words. next ( ) {
771- Some ( idx) => idx,
772- None => anyhow:: bail!( "idx not present" ) ,
773- } ;
774772 let idx = idx
775- . parse :: < u32 > ( )
776- . context ( "index" ) ?
777773 . checked_sub ( 1 )
778774 . ok_or_else ( || anyhow:: anyhow!( "1-based indexes" ) ) ?;
779- let mut description = words. fold ( String :: new ( ) , |mut acc, piece| {
780- acc. push_str ( piece) ;
781- acc. push ( ' ' ) ;
782- acc
783- } ) ;
784775 let description = if description. is_empty ( ) {
785776 None
786777 } else {
787- assert_eq ! ( description. pop( ) , Some ( ' ' ) ) ; // pop trailing space
788- Some ( description)
778+ Some ( description. to_string ( ) )
789779 } ;
790780 let mut db = ctx. db . get ( ) . await ;
791781 match add_metadata ( & mut db, gh_id, idx, description. as_deref ( ) ) . await {
0 commit comments