From e5944e0fdbdf6a908926e5df3b753b63370c03f8 Mon Sep 17 00:00:00 2001 From: Erik Johnston Date: Wed, 25 Oct 2017 14:44:33 +0100 Subject: [PATCH] Move BuildEvent to common package (#315) This is in preperation for implementing various federation APIs that need to build events. --- .../matrix-org/dendrite/clientapi/routing/joinroom.go | 6 +++--- .../matrix-org/dendrite/clientapi/routing/membership.go | 7 +++---- .../matrix-org/dendrite/clientapi/routing/profile.go | 3 +-- .../matrix-org/dendrite/clientapi/routing/sendevent.go | 6 +++--- .../matrix-org/dendrite/clientapi/threepid/invites.go | 3 +-- .../dendrite/{clientapi/events => common}/events.go | 2 +- 6 files changed, 12 insertions(+), 15 deletions(-) rename src/github.com/matrix-org/dendrite/{clientapi/events => common}/events.go (99%) diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go b/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go index 890d6f1a..73a751ac 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/joinroom.go @@ -22,10 +22,10 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/clientapi/events" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" + "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrix" @@ -215,7 +215,7 @@ func (r joinRoomReq) joinRoomUsingServers( } var queryRes api.QueryLatestEventsAndStateResponse - event, err := events.BuildEvent(r.req.Context(), &eb, r.cfg, r.queryAPI, &queryRes) + event, err := common.BuildEvent(r.req.Context(), &eb, r.cfg, r.queryAPI, &queryRes) if err == nil { if err = r.producer.SendEvents(r.req.Context(), []gomatrixserverlib.Event{*event}, r.cfg.Matrix.ServerName); err != nil { return httputil.LogThenError(r.req, err) @@ -227,7 +227,7 @@ func (r joinRoomReq) joinRoomUsingServers( }{roomID}, } } - if err != events.ErrRoomNoExists { + if err != common.ErrRoomNoExists { return httputil.LogThenError(r.req, err) } diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go b/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go index fec27ae7..e94fbde7 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/membership.go @@ -21,7 +21,6 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/clientapi/events" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" @@ -62,7 +61,7 @@ func SendMembership( Code: 400, JSON: jsonerror.NotTrusted(body.IDServer), } - } else if err == events.ErrRoomNoExists { + } else if err == common.ErrRoomNoExists { return util.JSONResponse{ Code: 404, JSON: jsonerror.NotFound(err.Error()), @@ -89,7 +88,7 @@ func SendMembership( Code: 400, JSON: jsonerror.BadJSON(err.Error()), } - } else if err == events.ErrRoomNoExists { + } else if err == common.ErrRoomNoExists { return util.JSONResponse{ Code: 404, JSON: jsonerror.NotFound(err.Error()), @@ -149,7 +148,7 @@ func buildMembershipEvent( return nil, err } - return events.BuildEvent(ctx, &builder, cfg, queryAPI, nil) + return common.BuildEvent(ctx, &builder, cfg, queryAPI, nil) } // loadProfile lookups the profile of a given user from the database and returns diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go b/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go index 918292e5..da47451f 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/profile.go @@ -20,7 +20,6 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/clientapi/events" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" @@ -285,7 +284,7 @@ func buildMembershipEvents( return nil, err } - event, err := events.BuildEvent(ctx, &builder, *cfg, queryAPI, nil) + event, err := common.BuildEvent(ctx, &builder, *cfg, queryAPI, nil) if err != nil { return nil, err } diff --git a/src/github.com/matrix-org/dendrite/clientapi/routing/sendevent.go b/src/github.com/matrix-org/dendrite/clientapi/routing/sendevent.go index d912f10b..dc2f58f6 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/routing/sendevent.go +++ b/src/github.com/matrix-org/dendrite/clientapi/routing/sendevent.go @@ -18,10 +18,10 @@ import ( "net/http" "github.com/matrix-org/dendrite/clientapi/auth/authtypes" - "github.com/matrix-org/dendrite/clientapi/events" "github.com/matrix-org/dendrite/clientapi/httputil" "github.com/matrix-org/dendrite/clientapi/jsonerror" "github.com/matrix-org/dendrite/clientapi/producers" + "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/gomatrixserverlib" @@ -67,8 +67,8 @@ func SendEvent( } var queryRes api.QueryLatestEventsAndStateResponse - e, err := events.BuildEvent(req.Context(), &builder, cfg, queryAPI, &queryRes) - if err == events.ErrRoomNoExists { + e, err := common.BuildEvent(req.Context(), &builder, cfg, queryAPI, &queryRes) + if err == common.ErrRoomNoExists { return util.JSONResponse{ Code: 404, JSON: jsonerror.NotFound("Room does not exist"), diff --git a/src/github.com/matrix-org/dendrite/clientapi/threepid/invites.go b/src/github.com/matrix-org/dendrite/clientapi/threepid/invites.go index 51c0dd9c..83659182 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/threepid/invites.go +++ b/src/github.com/matrix-org/dendrite/clientapi/threepid/invites.go @@ -26,7 +26,6 @@ import ( "github.com/matrix-org/dendrite/clientapi/auth/authtypes" "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" - "github.com/matrix-org/dendrite/clientapi/events" "github.com/matrix-org/dendrite/clientapi/producers" "github.com/matrix-org/dendrite/common" "github.com/matrix-org/dendrite/common/config" @@ -351,7 +350,7 @@ func emit3PIDInviteEvent( } var queryRes *api.QueryLatestEventsAndStateResponse - event, err := events.BuildEvent(ctx, builder, cfg, queryAPI, queryRes) + event, err := common.BuildEvent(ctx, builder, cfg, queryAPI, queryRes) if err != nil { return err } diff --git a/src/github.com/matrix-org/dendrite/clientapi/events/events.go b/src/github.com/matrix-org/dendrite/common/events.go similarity index 99% rename from src/github.com/matrix-org/dendrite/clientapi/events/events.go rename to src/github.com/matrix-org/dendrite/common/events.go index 23cb5bbc..cf2df842 100644 --- a/src/github.com/matrix-org/dendrite/clientapi/events/events.go +++ b/src/github.com/matrix-org/dendrite/common/events.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package events +package common import ( "context"