@@ -128,10 +128,12 @@ func Query(inst *instance.Instance, logger logger.Logger, query QueryMessage) er
128
128
return err
129
129
}
130
130
myself , _ := contact .GetMyself (inst )
131
+ relatives , _ := getRelatives (inst , myself )
131
132
payload := map [string ]interface {}{
132
- "messages" : chat .Messages ,
133
- "myself" : myself ,
134
- "stream" : true ,
133
+ "messages" : chat .Messages ,
134
+ "myself" : myself ,
135
+ "relatives" : relatives ,
136
+ "stream" : true ,
135
137
}
136
138
137
139
res , err := callRAGQuery (inst , payload )
@@ -178,6 +180,40 @@ func Query(inst *instance.Instance, logger logger.Logger, query QueryMessage) er
178
180
return couchdb .UpdateDoc (inst , & chat )
179
181
}
180
182
183
+ func getRelatives (inst * instance.Instance , myself * contact.Contact ) ([]* contact.Contact , error ) {
184
+ if myself == nil {
185
+ return nil , errors .New ("no myself contact" )
186
+ }
187
+ var ids []string
188
+ rels , _ := myself .Get ("relationships" ).(map [string ]interface {})
189
+ if len (rels ) == 0 {
190
+ return nil , nil
191
+ }
192
+ related , _ := rels ["related" ].(map [string ]interface {})
193
+ if len (related ) == 0 {
194
+ return nil , nil
195
+ }
196
+ data , _ := related ["data" ].([]interface {})
197
+ for _ , item := range data {
198
+ item , _ := item .(map [string ]interface {})
199
+ if len (item ) > 0 {
200
+ id , _ := item ["_id" ].(string )
201
+ if len (id ) > 0 {
202
+ ids = append (ids , id )
203
+ }
204
+ }
205
+ }
206
+ if len (ids ) == 0 {
207
+ return nil , nil
208
+ }
209
+ var relatives []* contact.Contact
210
+ req := & couchdb.AllDocsRequest {Keys : ids }
211
+ if err := couchdb .GetAllDocs (inst , consts .Contacts , req , & relatives ); err != nil {
212
+ return nil , err
213
+ }
214
+ return relatives , nil
215
+ }
216
+
181
217
func callRAGQuery (inst * instance.Instance , payload map [string ]interface {}) (* http.Response , error ) {
182
218
ragServer := inst .RAGServer ()
183
219
if ragServer .URL == "" {
0 commit comments