diff --git a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/account_data_table.go b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/account_data_table.go index 20ff655b1..734ffcd96 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/account_data_table.go +++ b/src/github.com/matrix-org/dendrite/clientapi/auth/storage/accounts/account_data_table.go @@ -19,7 +19,7 @@ import ( ) const accountDataSchema = ` --- Stores data about accounts profiles. +-- Stores data about accounts data. CREATE TABLE IF NOT EXISTS account_data ( -- The Matrix user ID localpart for this account localpart TEXT NOT NULL, @@ -28,18 +28,15 @@ CREATE TABLE IF NOT EXISTS account_data ( -- The account data type type TEXT NOT NULL, -- The account data content - content TEXT NOT NULL + content TEXT NOT NULL, PRIMARY KEY(localpart, room_id, type) ); - --- Create index we can reference in the upsert request -CREATE UNIQUE INDEX IF NOT EXISTS ac_user_room_type ON account_data(localpart, room_id, type); ` const insertAccountDataSQL = ` INSERT INTO account_data(localpart, room_id, type, content) VALUES($1, $2, $3, $4) - ON CONFLICT (ac_user_room_type) DO UPDATE SET content = EXCLUDED.content + ON CONFLICT (localpart, room_id, type) DO UPDATE SET content = EXCLUDED.content ` const selectAccountDataByLocalPartSQL = "" + @@ -54,7 +51,7 @@ type accountDataStatements struct { } func (s *accountDataStatements) prepare(db *sql.DB) (err error) { - _, err = db.Exec(accountsSchema) + _, err = db.Exec(accountDataSchema) if err != nil { return } diff --git a/src/github.com/matrix-org/dendrite/clientapi/readers/account_data.go b/src/github.com/matrix-org/dendrite/clientapi/readers/account_data.go new file mode 100644 index 000000000..b262ea4b3 --- /dev/null +++ b/src/github.com/matrix-org/dendrite/clientapi/readers/account_data.go @@ -0,0 +1,34 @@ +// Copyright 2017 Vector Creations Ltd +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +package readers + +import ( + "fmt" + "net/http" + + "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" + "github.com/matrix-org/dendrite/clientapi/httputil" + "github.com/matrix-org/dendrite/clientapi/jsonerror" + "github.com/matrix-org/gomatrixserverlib" + + "github.com/matrix-org/util" +) + +func SaveAccountData( + req *http.Request, accountDB *accounts.Database, userID string, roomID string, +) util.JSONResponse { + + localpart, server, err := gomatrixserverlib.SplitID('@', userID) +} diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go index 8d6f024e2..7eea3881b 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/routing.go @@ -275,7 +275,14 @@ func Setup( r0mux.Handle("/user/{userID}/account_data/{type}", common.MakeAPI("user_account_data", func(req *http.Request) util.JSONResponse { - // TODO: Set and get the account_data + // TODO: Set the account_data + return util.JSONResponse{Code: 200, JSON: struct{}{}} + }), + ) + + r0mux.Handle("/user/{userID}/rooms/{roomID}/account_data/{type}", + common.MakeAPI("user_account_data", func(req *http.Request) util.JSONResponse { + // TODO: Set the account_data return util.JSONResponse{Code: 200, JSON: struct{}{}} }), )