4
1
Fork 0

fix: Cleanup formatting and add pinned chats schema

pull/24/head
Ambrose Chua 2019-07-27 23:03:05 +08:00
parent e81b91eebb
commit 54e6ae658d
Signed by: ambrose
GPG Key ID: B34FBE029276BA5D
3 changed files with 138 additions and 130 deletions

View File

@ -183,7 +183,7 @@ func (h *Handler) UpdateUser(w http.ResponseWriter, r *http.Request, p httproute
return return
} }
w.WriteHeader(200); w.WriteHeader(200)
} }
func (h *Handler) CreateConversation(w http.ResponseWriter, r *http.Request, p httprouter.Params) { func (h *Handler) CreateConversation(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
@ -358,7 +358,7 @@ func (h *Handler) UpdateConversation(w http.ResponseWriter, r *http.Request, p h
} }
} }
w.WriteHeader(200); w.WriteHeader(200)
} }
func (h *Handler) DeleteConversation(w http.ResponseWriter, r *http.Request, p httprouter.Params) { func (h *Handler) DeleteConversation(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
@ -555,6 +555,7 @@ func (h *Handler) GetConversationMembers(w http.ResponseWriter, r *http.Request,
type PhoneNumber struct { type PhoneNumber struct {
PhoneNumber string `json:"phone_number"` PhoneNumber string `json:"phone_number"`
} }
func (h *Handler) CreateContact(w http.ResponseWriter, r *http.Request, p httprouter.Params) { func (h *Handler) CreateContact(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
// Parse // Parse
userID := r.Context().Value("user").(string) userID := r.Context().Value("user").(string)

View File

@ -73,6 +73,7 @@ type RawClient struct {
UserId string `json:"userid"` UserId string `json:"userid"`
ClientId string `json:"clientid"` ClientId string `json:"clientid"`
} }
func AuthMiddleware(next httprouter.Handle) httprouter.Handle { func AuthMiddleware(next httprouter.Handle) httprouter.Handle {
return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) { return func(w http.ResponseWriter, r *http.Request, p httprouter.Params) {
ua := r.Header.Get("X-User-Claim") ua := r.Header.Get("X-User-Claim")

View File

@ -28,6 +28,12 @@ CREATE TABLE IF NOT EXISTS contact (
UNIQUE ("user", contact) UNIQUE ("user", contact)
); );
CREATE TABLE IF NOT EXISTS pinned_conversation (
"user" BYTEA REFERENCES "user"(id),
"conversation" BYTEA REFERENCES "conversation"(id),
UNIQUE ("user", "conversation")
);
CREATE OR REPLACE FUNCTION notify_permissions_new () RETURNS TRIGGER AS $$ CREATE OR REPLACE FUNCTION notify_permissions_new () RETURNS TRIGGER AS $$
BEGIN BEGIN
PERFORM pg_notify('member_new', CONCAT(NEW."user", '+', NEW."conversation")); PERFORM pg_notify('member_new', CONCAT(NEW."user", '+', NEW."conversation"));