mirror of
https://github.com/kevin-DL/services.git
synced 2026-01-19 22:15:24 +00:00
enable retrieval of recent thread messages by group id
This commit is contained in:
@@ -28,6 +28,21 @@ func (s *Threads) RecentMessages(ctx context.Context, req *pb.RecentMessagesRequ
|
|||||||
limit = uint(req.LimitPerThread)
|
limit = uint(req.LimitPerThread)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// if group id is present then list threads by group
|
||||||
|
if len(req.GroupId) > 0 && len(req.ThreadIds) == 0 {
|
||||||
|
var threads []*Thread
|
||||||
|
thread := &Thread{GroupID: req.GroupId}
|
||||||
|
if err := model.List(ctx, thread, &threads, model.Query{}); err != nil {
|
||||||
|
logger.Errorf("Error reading threads: %v", err)
|
||||||
|
return errors.InternalServerError("DATABASE_ERROR", "Error connecting to database")
|
||||||
|
}
|
||||||
|
|
||||||
|
// create the thread ids
|
||||||
|
for _, thread := range threads {
|
||||||
|
req.ThreadIds = append(req.ThreadIds, thread.ID)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
for _, thread := range req.ThreadIds {
|
for _, thread := range req.ThreadIds {
|
||||||
q := model.Query{Limit: limit, Order: "desc"}
|
q := model.Query{Limit: limit, Order: "desc"}
|
||||||
m := &Message{ThreadID: thread}
|
m := &Message{ThreadID: thread}
|
||||||
|
|||||||
Reference in New Issue
Block a user