Encrypted messaging app
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

51 lines
1.1 KiB

package Messages
import (
"encoding/json"
"net/http"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Api/Auth"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Database"
"git.tovijaeschke.xyz/tovi/Envelope/Backend/Models"
"github.com/gorilla/mux"
)
func MessageThread(w http.ResponseWriter, r *http.Request) {
var (
userData Models.User
messageThread Models.MessageThread
urlVars map[string]string
threadKey string
returnJson []byte
ok bool
err error
)
userData, err = Auth.CheckCookieCurrentUser(w, r)
if !ok {
http.Error(w, "Forbidden", http.StatusUnauthorized)
return
}
urlVars = mux.Vars(r)
threadKey, ok = urlVars["threadKey"]
if !ok {
http.Error(w, "Not Found", http.StatusNotFound)
return
}
messageThread, err = Database.GetMessageThreadById(threadKey, userData)
if !ok {
http.Error(w, "Not Found", http.StatusNotFound)
return
}
returnJson, err = json.MarshalIndent(messageThread, "", " ")
if err != nil {
http.Error(w, "Error", http.StatusInternalServerError)
return
}
w.WriteHeader(http.StatusOK)
w.Write(returnJson)
}