@@ -495,10 +495,6 @@ func (g *PushHandler) Activity(ctx context.Context, m gregor.OutOfBandMessage) (
495495 }}
496496 g .G ().Syncer .SendChatStaleNotifications (ctx , m .UID ().Bytes (), supdate , true )
497497 }
498-
499- if g .badger != nil && nm .UnreadUpdate != nil {
500- g .badger .PushChatUpdate (* nm .UnreadUpdate , nm .InboxVers )
501- }
502498 case types .ActionReadMessage :
503499 var nm chat1.ReadMessagePayload
504500 err = dec .Decode (& nm )
@@ -519,10 +515,6 @@ func (g *PushHandler) Activity(ctx context.Context, m gregor.OutOfBandMessage) (
519515 ConvID : nm .ConvID ,
520516 Conv : g .presentUIItem (conv ),
521517 })
522-
523- if g .badger != nil && nm .UnreadUpdate != nil {
524- g .badger .PushChatUpdate (* nm .UnreadUpdate , nm .InboxVers )
525- }
526518 case types .ActionSetStatus :
527519 var nm chat1.SetStatusPayload
528520 err = dec .Decode (& nm )
@@ -542,10 +534,6 @@ func (g *PushHandler) Activity(ctx context.Context, m gregor.OutOfBandMessage) (
542534 Status : nm .Status ,
543535 Conv : g .presentUIItem (conv ),
544536 })
545-
546- if g .badger != nil && nm .UnreadUpdate != nil {
547- g .badger .PushChatUpdate (* nm .UnreadUpdate , nm .InboxVers )
548- }
549537 case types .ActionSetAppNotificationSettings :
550538 var nm chat1.SetAppNotificationSettingsPayload
551539 err = dec .Decode (& nm )
@@ -598,11 +586,6 @@ func (g *PushHandler) Activity(ctx context.Context, m gregor.OutOfBandMessage) (
598586 activity = chat1 .NewChatActivityWithNewConversation (chat1.NewConversationInfo {
599587 Conv : * g .presentUIItem (conv ),
600588 })
601-
602- if g .badger != nil && nm .UnreadUpdate != nil {
603- g .badger .PushChatUpdate (* nm .UnreadUpdate , nm .InboxVers )
604- }
605-
606589 case types .ActionTeamType :
607590 var nm chat1.TeamTypePayload
608591 err = dec .Decode (& nm )
@@ -621,13 +604,12 @@ func (g *PushHandler) Activity(ctx context.Context, m gregor.OutOfBandMessage) (
621604 TeamType : nm .TeamType ,
622605 Conv : g .presentUIItem (conv ),
623606 })
624-
625- if g .badger != nil && nm .UnreadUpdate != nil {
626- g .badger .PushChatUpdate (* nm .UnreadUpdate , nm .InboxVers )
627- }
628607 default :
629608 g .Debug (ctx , "unhandled chat.activity action %q" , action )
630609 }
610+ if g .badger != nil && gm .UnreadUpdate != nil {
611+ g .badger .PushChatUpdate (* gm .UnreadUpdate , gm .InboxVers )
612+ }
631613 g .notifyNewChatActivity (ctx , m .UID (), convID , conv , & activity )
632614 }(bctx )
633615 return nil
@@ -861,6 +843,125 @@ func (g *PushHandler) TeamChannels(ctx context.Context, m gregor.OutOfBandMessag
861843 return nil
862844}
863845
846+ func (g * PushHandler ) SetConvRetention (ctx context.Context , m gregor.OutOfBandMessage ) (err error ) {
847+ var identBreaks []keybase1.TLFIdentifyFailure
848+ ctx = Context (ctx , g .G (), keybase1 .TLFIdentifyBehavior_CHAT_GUI , & identBreaks ,
849+ g .identNotifier )
850+ defer g .Trace (ctx , func () error { return err }, "SetConvRetention" )()
851+ if m .Body () == nil {
852+ return errors .New ("gregor handler for SetConvRetention update: nil message body" )
853+ }
854+
855+ var update chat1.SetConvRetentionUpdate
856+ reader := bytes .NewReader (m .Body ().Bytes ())
857+ dec := codec .NewDecoder (reader , & codec.MsgpackHandle {WriteExt : true })
858+ err = dec .Decode (& update )
859+ if err != nil {
860+ return err
861+ }
862+ uid := gregor1 .UID (m .UID ().Bytes ())
863+
864+ // Order updates based on inbox version of the update from the server
865+ cb := g .orderer .WaitForTurn (ctx , uid , update .InboxVers )
866+ bctx := BackgroundContext (ctx , g .G ())
867+ go func (ctx context.Context ) {
868+ defer g .Trace (ctx , func () error { return err }, "SetConvRetention(goroutine)" )()
869+ <- cb
870+ g .Lock ()
871+ defer g .Unlock ()
872+ defer g .orderer .CompleteTurn (ctx , uid , update .InboxVers )
873+
874+ // Update inbox
875+ conv , err := g .G ().InboxSource .SetConvRetention (ctx , m .UID ().Bytes (), update .InboxVers ,
876+ update .ConvID , update .Policy )
877+ if err != nil {
878+ g .Debug (ctx , "SetConvRetention: unable to update inbox: %s" , err .Error ())
879+ return
880+ }
881+ if conv == nil {
882+ return
883+ }
884+ // Send notify for each conversation ID
885+ if conv .GetTopicType () == chat1 .TopicType_CHAT {
886+ if g .shouldSendNotifications () {
887+ g .G ().NotifyRouter .HandleChatSetConvRetention (ctx , keybase1 .UID (uid .String ()),
888+ conv .GetConvID (), g .presentUIItem (conv ))
889+ } else {
890+ supdate := []chat1.ConversationStaleUpdate {chat1.ConversationStaleUpdate {
891+ ConvID : conv .GetConvID (),
892+ UpdateType : chat1 .StaleUpdateType_CLEAR ,
893+ }}
894+ g .G ().Syncer .SendChatStaleNotifications (ctx , uid , supdate , false )
895+ }
896+ }
897+ }(bctx )
898+
899+ return nil
900+ }
901+
902+ func (g * PushHandler ) SetTeamRetention (ctx context.Context , m gregor.OutOfBandMessage ) (err error ) {
903+ var identBreaks []keybase1.TLFIdentifyFailure
904+ ctx = Context (ctx , g .G (), keybase1 .TLFIdentifyBehavior_CHAT_GUI , & identBreaks ,
905+ g .identNotifier )
906+ defer g .Trace (ctx , func () error { return err }, "SetTeamRetention" )()
907+ if m .Body () == nil {
908+ return errors .New ("gregor handler for SetTeamRetention update: nil message body" )
909+ }
910+
911+ var update chat1.SetTeamRetentionUpdate
912+ reader := bytes .NewReader (m .Body ().Bytes ())
913+ dec := codec .NewDecoder (reader , & codec.MsgpackHandle {WriteExt : true })
914+ err = dec .Decode (& update )
915+ if err != nil {
916+ return err
917+ }
918+ uid := gregor1 .UID (m .UID ().Bytes ())
919+
920+ // Order updates based on inbox version of the update from the server
921+ cb := g .orderer .WaitForTurn (ctx , uid , update .InboxVers )
922+ bctx := BackgroundContext (ctx , g .G ())
923+ go func (ctx context.Context ) {
924+ defer g .Trace (ctx , func () error { return err }, "SetTeamRetention(goroutine)" )()
925+ <- cb
926+ g .Lock ()
927+ defer g .Unlock ()
928+ defer g .orderer .CompleteTurn (ctx , uid , update .InboxVers )
929+
930+ // Update inbox
931+ var convs []chat1.ConversationLocal
932+ if convs , err = g .G ().InboxSource .SetTeamRetention (ctx , m .UID ().Bytes (), update .InboxVers ,
933+ update .TeamID , update .Policy ); err != nil {
934+ g .Debug (ctx , "SetTeamRetention: unable to update inbox: %s" , err .Error ())
935+ return
936+ }
937+ if len (convs ) == 0 {
938+ g .Debug (ctx , "SetTeamRetention: no local convs affected" )
939+ return
940+ }
941+ // Send notify for each conversation ID
942+ var convUIItems []chat1.InboxUIItem
943+ var staleUpdates []chat1.ConversationStaleUpdate
944+ for _ , conv := range convs {
945+ if conv .GetTopicType () == chat1 .TopicType_CHAT {
946+ convUIItems = append (convUIItems , * g .presentUIItem (& conv ))
947+ staleUpdates = append (staleUpdates , chat1.ConversationStaleUpdate {
948+ ConvID : conv .GetConvID (),
949+ UpdateType : chat1 .StaleUpdateType_CLEAR ,
950+ })
951+ }
952+ }
953+
954+ if g .shouldSendNotifications () {
955+ g .G ().NotifyRouter .HandleChatSetTeamRetention (ctx , keybase1 .UID (uid .String ()), update .TeamID , convUIItems )
956+ } else {
957+ g .G ().Syncer .SendChatStaleNotifications (ctx , uid , staleUpdates , false )
958+ }
959+
960+ }(bctx )
961+
962+ return nil
963+ }
964+
864965func (g * PushHandler ) HandleOobm (ctx context.Context , obm gregor.OutOfBandMessage ) (bool , error ) {
865966 if obm .System () == nil {
866967 return false , errors .New ("nil system in out of band message" )
@@ -879,6 +980,10 @@ func (g *PushHandler) HandleOobm(ctx context.Context, obm gregor.OutOfBandMessag
879980 return true , g .MembershipUpdate (ctx , obm )
880981 case types .PushTeamChannels :
881982 return true , g .TeamChannels (ctx , obm )
983+ case types .PushConvRetention :
984+ return true , g .SetConvRetention (ctx , obm )
985+ case types .PushTeamRetention :
986+ return true , g .SetTeamRetention (ctx , obm )
882987 }
883988
884989 return false , nil
0 commit comments