4
1
Fork 0

Handle adding DM to person whose DM already exists. Fixes #14

pull/24/head
Daniel Lim 2019-07-03 11:03:44 +08:00
parent ea6729f0e5
commit 36ae44d829
2 changed files with 19 additions and 2 deletions

View File

@ -430,7 +430,7 @@ Add a member to the specified conversation.
#### Success Response (200 OK)
Empty body.
The conversation ID of the conversation the user is added to.
#### Errors

View File

@ -448,6 +448,23 @@ func (h *Handler) CreateConversationMember(w http.ResponseWriter, r *http.Reques
// Log
log.Print(member)
// Check for existing DM
var dmID string
err = h.db.QueryRow(`
SELECT "conversation".id FROM "conversation", "member"
WHERE
"conversation".dm = TRUE
AND "conversation".id = "member".conversation
AND "member".user = $1
`, member.ID).Scan(&dmID)
if err != sql.ErrNoRows {
http.Error(w, http.StatusText(http.StatusInternalServerError), http.StatusInternalServerError)
return
} else if err == nil {
w.Write([]byte(dmID))
return
}
// Check for valid conversation and prevent duplicate entries
var test string
err = h.db.QueryRow(`
@ -504,7 +521,7 @@ func (h *Handler) CreateConversationMember(w http.ResponseWriter, r *http.Reques
// Respond
//w.Header().Set("Content-Type", "application/json")
//json.NewEncoder(w).Encode(member)
w.WriteHeader(200)
w.Write([]byte(conversationID))
}
func (h *Handler) GetConversationMembers(w http.ResponseWriter, r *http.Request, p httprouter.Params) {