@@ -49,7 +49,7 @@ func (service *MessageThreadService) UpdateThread(ctx context.Context, params Me
4949
5050 ctxLogger := service .tracer .CtxLogger (service .logger , span )
5151
52- thread , err := service .repository .Load (ctx , params .Owner , params .Contact )
52+ thread , err := service .repository .LoadByOwnerContact (ctx , params .Owner , params .Contact )
5353 if err != nil && stacktrace .GetCode (err ) == repositories .ErrCodeNotFound {
5454 ctxLogger .Info (fmt .Sprintf ("cannot find thread with owner [%s], and contact [%s]. creating new thread" , params .Owner , params .Contact ))
5555 return service .createThread (ctx , params )
@@ -74,6 +74,34 @@ func (service *MessageThreadService) UpdateThread(ctx context.Context, params Me
7474 return nil
7575}
7676
77+ // MessageThreadStatusParams are parameters for updating a thread status
78+ type MessageThreadStatusParams struct {
79+ IsArchived bool
80+ MessageThreadID uuid.UUID
81+ }
82+
83+ // UpdateStatus updates a thread between an owner and a contact
84+ func (service * MessageThreadService ) UpdateStatus (ctx context.Context , params MessageThreadStatusParams ) (* entities.MessageThread , error ) {
85+ ctx , span := service .tracer .Start (ctx )
86+ defer span .End ()
87+
88+ ctxLogger := service .tracer .CtxLogger (service .logger , span )
89+
90+ thread , err := service .repository .Load (ctx , params .MessageThreadID )
91+ if err != nil {
92+ msg := fmt .Sprintf ("cannot find thread with id [%s]" , params .MessageThreadID )
93+ return nil , service .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
94+ }
95+
96+ if err = service .repository .Update (ctx , thread .UpdateArchive (params .IsArchived )); err != nil {
97+ msg := fmt .Sprintf ("cannot update message thread with id [%s] with archive status [%t]" , thread .ID , params .IsArchived )
98+ return nil , service .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
99+ }
100+
101+ ctxLogger .Info (fmt .Sprintf ("thread with id [%s] updated with archive status [%t]" , thread .ID , thread .IsArchived ))
102+ return thread , nil
103+ }
104+
77105func (service * MessageThreadService ) createThread (ctx context.Context , params MessageThreadUpdateParams ) error {
78106 ctx , span := service .tracer .Start (ctx )
79107 defer span .End ()
@@ -134,7 +162,8 @@ func (service *MessageThreadService) getColor() string {
134162// MessageThreadGetParams parameters fetching threads
135163type MessageThreadGetParams struct {
136164 repositories.IndexParams
137- Owner string
165+ IsArchived bool
166+ Owner string
138167}
139168
140169// GetThreads fetches threads for an owner
@@ -144,7 +173,7 @@ func (service *MessageThreadService) GetThreads(ctx context.Context, params Mess
144173
145174 ctxLogger := service .tracer .CtxLogger (service .logger , span )
146175
147- threads , err := service .repository .Index (ctx , params .Owner , params .IndexParams )
176+ threads , err := service .repository .Index (ctx , params .Owner , params .IsArchived , params . IndexParams )
148177 if err != nil {
149178 msg := fmt .Sprintf ("could not fetch messages threads for params [%+#v]" , params )
150179 return nil , service .tracer .WrapErrorSpan (span , stacktrace .Propagate (err , msg ))
0 commit comments