diff options
author | Kegsay <kegan@matrix.org> | 2020-06-10 12:17:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-06-10 12:17:54 +0100 |
commit | b7187a9a354530c1846c2a97be701ea484f91c2c (patch) | |
tree | 6d14903a444fa8bca964247dbe85ae8d9709d4c8 /clientapi/producers | |
parent | d9d6f4568ce891ae0ae9d2a3449974d3777bd21d (diff) |
Remove clientapi producers which aren't actually producers (#1111)
* Remove clientapi producers which aren't actually producers
They are actually just convenience wrappers around the internal APIs
for roomserver/eduserver. Move their logic to their respective `api`
packages and call them directly.
* Remove TODO
* unbreak ygg
Diffstat (limited to 'clientapi/producers')
-rw-r--r-- | clientapi/producers/eduserver.go | 80 | ||||
-rw-r--r-- | clientapi/producers/roomserver.go | 124 |
2 files changed, 0 insertions, 204 deletions
diff --git a/clientapi/producers/eduserver.go b/clientapi/producers/eduserver.go deleted file mode 100644 index 102c1fad..00000000 --- a/clientapi/producers/eduserver.go +++ /dev/null @@ -1,80 +0,0 @@ -// 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 producers - -import ( - "context" - "encoding/json" - "time" - - "github.com/matrix-org/dendrite/eduserver/api" - "github.com/matrix-org/gomatrixserverlib" -) - -// EDUServerProducer produces events for the EDU server to consume -type EDUServerProducer struct { - InputAPI api.EDUServerInputAPI -} - -// NewEDUServerProducer creates a new EDUServerProducer -func NewEDUServerProducer(inputAPI api.EDUServerInputAPI) *EDUServerProducer { - return &EDUServerProducer{ - InputAPI: inputAPI, - } -} - -// SendTyping sends a typing event to EDU server -func (p *EDUServerProducer) SendTyping( - ctx context.Context, userID, roomID string, - typing bool, timeoutMS int64, -) error { - requestData := api.InputTypingEvent{ - UserID: userID, - RoomID: roomID, - Typing: typing, - TimeoutMS: timeoutMS, - OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()), - } - - var response api.InputTypingEventResponse - err := p.InputAPI.InputTypingEvent( - ctx, &api.InputTypingEventRequest{InputTypingEvent: requestData}, &response, - ) - - return err -} - -// SendToDevice sends a typing event to EDU server -func (p *EDUServerProducer) SendToDevice( - ctx context.Context, sender, userID, deviceID, eventType string, - message interface{}, -) error { - js, err := json.Marshal(message) - if err != nil { - return err - } - requestData := api.InputSendToDeviceEvent{ - UserID: userID, - DeviceID: deviceID, - SendToDeviceEvent: gomatrixserverlib.SendToDeviceEvent{ - Sender: sender, - Type: eventType, - Content: js, - }, - } - request := api.InputSendToDeviceEventRequest{ - InputSendToDeviceEvent: requestData, - } - response := api.InputSendToDeviceEventResponse{} - return p.InputAPI.InputSendToDeviceEvent(ctx, &request, &response) -} diff --git a/clientapi/producers/roomserver.go b/clientapi/producers/roomserver.go deleted file mode 100644 index f0733db9..00000000 --- a/clientapi/producers/roomserver.go +++ /dev/null @@ -1,124 +0,0 @@ -// 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 producers - -import ( - "context" - - "github.com/matrix-org/dendrite/roomserver/api" - "github.com/matrix-org/gomatrixserverlib" -) - -// RoomserverProducer produces events for the roomserver to consume. -type RoomserverProducer struct { - RsAPI api.RoomserverInternalAPI -} - -// NewRoomserverProducer creates a new RoomserverProducer -func NewRoomserverProducer(rsAPI api.RoomserverInternalAPI) *RoomserverProducer { - return &RoomserverProducer{ - RsAPI: rsAPI, - } -} - -// SendEvents writes the given events to the roomserver input log. The events are written with KindNew. -func (c *RoomserverProducer) SendEvents( - ctx context.Context, events []gomatrixserverlib.HeaderedEvent, sendAsServer gomatrixserverlib.ServerName, - txnID *api.TransactionID, -) (string, error) { - ires := make([]api.InputRoomEvent, len(events)) - for i, event := range events { - ires[i] = api.InputRoomEvent{ - Kind: api.KindNew, - Event: event, - AuthEventIDs: event.AuthEventIDs(), - SendAsServer: string(sendAsServer), - TransactionID: txnID, - } - } - return c.SendInputRoomEvents(ctx, ires) -} - -// SendEventWithState writes an event with KindNew to the roomserver input log -// with the state at the event as KindOutlier before it. Will not send any event that is -// marked as `true` in haveEventIDs -func (c *RoomserverProducer) SendEventWithState( - ctx context.Context, state *gomatrixserverlib.RespState, event gomatrixserverlib.HeaderedEvent, haveEventIDs map[string]bool, -) error { - outliers, err := state.Events() - if err != nil { - return err - } - - var ires []api.InputRoomEvent - for _, outlier := range outliers { - if haveEventIDs[outlier.EventID()] { - continue - } - ires = append(ires, api.InputRoomEvent{ - Kind: api.KindOutlier, - Event: outlier.Headered(event.RoomVersion), - AuthEventIDs: outlier.AuthEventIDs(), - }) - } - - stateEventIDs := make([]string, len(state.StateEvents)) - for i := range state.StateEvents { - stateEventIDs[i] = state.StateEvents[i].EventID() - } - - ires = append(ires, api.InputRoomEvent{ - Kind: api.KindNew, - Event: event, - AuthEventIDs: event.AuthEventIDs(), - HasState: true, - StateEventIDs: stateEventIDs, - }) - - _, err = c.SendInputRoomEvents(ctx, ires) - return err -} - -// SendInputRoomEvents writes the given input room events to the roomserver input API. -func (c *RoomserverProducer) SendInputRoomEvents( - ctx context.Context, ires []api.InputRoomEvent, -) (eventID string, err error) { - request := api.InputRoomEventsRequest{InputRoomEvents: ires} - var response api.InputRoomEventsResponse - err = c.RsAPI.InputRoomEvents(ctx, &request, &response) - eventID = response.EventID - return -} - -// SendInvite writes the invite event to the roomserver input API. -// This should only be needed for invite events that occur outside of a known room. -// If we are in the room then the event should be sent using the SendEvents method. -func (c *RoomserverProducer) SendInvite( - ctx context.Context, inviteEvent gomatrixserverlib.HeaderedEvent, - inviteRoomState []gomatrixserverlib.InviteV2StrippedState, - sendAsServer gomatrixserverlib.ServerName, txnID *api.TransactionID, -) error { - request := api.InputRoomEventsRequest{ - InputInviteEvents: []api.InputInviteEvent{{ - Event: inviteEvent, - InviteRoomState: inviteRoomState, - RoomVersion: inviteEvent.RoomVersion, - SendAsServer: string(sendAsServer), - TransactionID: txnID, - }}, - } - var response api.InputRoomEventsResponse - return c.RsAPI.InputRoomEvents(ctx, &request, &response) -} |