Mercurial > prosody-hg
comparison plugins/mod_storage_internal.lua @ 14011:f77911437539 13.0
mod_storage_internal: Return item-not-found for unknown before/after ids
This is required per XEP-0313, otherwise clients cannot tell the difference
between an empty successful query and a query where their sync point is no
longer within the archive.
| author | Matthew Wild <mwild1@gmail.com> |
|---|---|
| date | Fri, 12 Dec 2025 12:43:23 +0000 |
| parents | cbd234461c41 |
| children |
comparison
equal
deleted
inserted
replaced
| 14010:ed210f6b1d00 | 14011:f77911437539 |
|---|---|
| 171 local iter = function() | 171 local iter = function() |
| 172 i = i + 1; | 172 i = i + 1; |
| 173 return list[i] | 173 return list[i] |
| 174 end | 174 end |
| 175 | 175 |
| 176 local after_found; | |
| 176 if query then | 177 if query then |
| 177 if query.reverse then | 178 if query.reverse then |
| 178 i = #list + 1 | 179 i = #list + 1 |
| 179 iter = function() | 180 iter = function() |
| 180 i = i - 1 | 181 i = i - 1 |
| 229 if query.after then | 230 if query.after then |
| 230 local found = false; | 231 local found = false; |
| 231 iter = it.filter(function(item) | 232 iter = it.filter(function(item) |
| 232 local found_after = found; | 233 local found_after = found; |
| 233 if item.key == query.after then | 234 if item.key == query.after then |
| 235 after_found = true; | |
| 234 found = true | 236 found = true |
| 235 end | 237 end |
| 236 return found_after; | 238 return found_after; |
| 237 end, iter); | 239 end, iter); |
| 238 end | 240 end |
| 239 if query.before then | 241 if query.before then |
| 242 local before_key, before_found = query.before; | |
| 243 for idx = 1, #list do | |
| 244 if list[idx].key == before_key then | |
| 245 before_found = true; | |
| 246 break; | |
| 247 end | |
| 248 end | |
| 249 if not before_found then | |
| 250 return nil, "item-not-found"; | |
| 251 end | |
| 240 local found = false; | 252 local found = false; |
| 241 iter = it.filter(function(item) | 253 iter = it.filter(function(item) |
| 242 if item.key == query.before then | 254 if item.key == query.before then |
| 243 found = true | 255 found = true |
| 244 end | 256 end |
| 248 if query.limit then | 260 if query.limit then |
| 249 iter = it.head(query.limit, iter); | 261 iter = it.head(query.limit, iter); |
| 250 end | 262 end |
| 251 end | 263 end |
| 252 | 264 |
| 265 local first_item = iter(); | |
| 266 if first_item == nil and query and query.after and not after_found then | |
| 267 return nil, "item-not-found"; | |
| 268 end | |
| 269 | |
| 253 return function() | 270 return function() |
| 254 local item = iter(); | 271 local item; |
| 272 if first_item then | |
| 273 item, first_item = first_item, nil; | |
| 274 else | |
| 275 item = iter(); | |
| 276 end | |
| 255 if item == nil then | 277 if item == nil then |
| 256 if list.close then | 278 if list.close then |
| 257 list:close(); | 279 list:close(); |
| 258 end | 280 end |
| 259 return | 281 return |
