File tree Expand file tree Collapse file tree 1 file changed +38
-2
lines changed Expand file tree Collapse file tree 1 file changed +38
-2
lines changed Original file line number Diff line number Diff line change @@ -67,7 +67,43 @@ func (b *backendServer) GetChat(ctx context.Context, r *pb.ChatRequest) (*pb.Cha
67
67
}, nil
68
68
}
69
69
70
+ // GetAllChats returns a list of chats according to the request
70
71
func (b * backendServer ) GetAllChats (ctx context.Context , r * pb.ChatRequest ) (* pb.ChatResponse , error ) {
71
- // TODO: implement me
72
- return nil , nil
72
+ chats , err := b .backend .GetAllChats ()
73
+ if err != nil {
74
+ return & pb.ChatResponse {
75
+ Code : 500 ,
76
+ Message : err .Error (),
77
+ }, fmt .Errorf ("error while getting chats list" )
78
+ }
79
+
80
+ // Has a filter?
81
+ if len (r .Type ) == 0 {
82
+ return & pb.ChatResponse {
83
+ Code : 200 ,
84
+ Message : "ok" ,
85
+ Chats : chats ,
86
+ }, nil
87
+ }
88
+
89
+ if r .Type != "group" && r .Type != "supergroup" && r .Type != "private" || r .Type != "channel" {
90
+ return & pb.ChatResponse {
91
+ Code : 500 ,
92
+ Message : "unrecognized chat type" ,
93
+ Chats : chats ,
94
+ }, fmt .Errorf ("unrecognized chat type (%s)" , r .Type )
95
+ }
96
+
97
+ _chats := []* pb.Chat {}
98
+ for _ , chat := range chats {
99
+ if chat .Type == r .Type {
100
+ _chats = append (_chats , chat )
101
+ }
102
+ }
103
+
104
+ return & pb.ChatResponse {
105
+ Code : 200 ,
106
+ Message : "ok" ,
107
+ Chats : _chats ,
108
+ }, nil
73
109
}
You can’t perform that action at this time.
0 commit comments