Change summary
lib/registration_repo.rb | 23 ++++++++++-------------
1 file changed, 10 insertions(+), 13 deletions(-)
Detailed changes
@@ -22,23 +22,20 @@ class RegistrationRepo
EMPromise.all([
find(jid),
- REDIS.set(
- jid_key(tel),
- Blather::JID.new(jid).stripped.to_s,
- "NX", "GET"
- )
+ REDIS.exists(jid_key(tel))
]).then { |(oldcreds, oldjid)|
- if oldjid && oldjid != jid.stripped.to_s
+ if oldjid == "1" || (!oldcreds.empty? && oldcreds != creds)
raise Conflict, "Another user exists for #{tel}"
end
- if !oldcreds.empty? && oldcreds != creds
- REDIS.set(jid_key(tel), oldjid).then do
- raise Conflict, "Another user exists for #{jid}"
- end
- end
- }.then {
- REDIS.rpush(cred_key(jid), *creds)
+ EMPromise.all([
+ REDIS.set(
+ jid_key(tel),
+ Blather::JID.new(jid).stripped.to_s,
+ "NX"
+ ),
+ REDIS.rpush(cred_key(jid), *creds)
+ ])
}
end