mirror of
https://github.com/element-hq/dendrite.git
synced 2025-09-16 14:12:24 +03:00
Calculate the complete /sync response (#69)
This commit is contained in:
parent
203e706b99
commit
53ec4a255b
9 changed files with 387 additions and 65 deletions
66
vendor/src/github.com/matrix-org/gomatrixserverlib/clientevent.go
vendored
Normal file
66
vendor/src/github.com/matrix-org/gomatrixserverlib/clientevent.go
vendored
Normal file
|
@ -0,0 +1,66 @@
|
|||
/* 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 gomatrixserverlib
|
||||
|
||||
// EventFormat specifies the format of a client event
|
||||
type EventFormat int
|
||||
|
||||
const (
|
||||
// FormatAll will include all client event keys
|
||||
FormatAll EventFormat = iota
|
||||
// FormatSync will include only the event keys required by the /sync API. Notably, this
|
||||
// means the 'room_id' will be missing from the events.
|
||||
FormatSync
|
||||
)
|
||||
|
||||
// ClientEvent is an event which is fit for consumption by clients, in accordance with the specification.
|
||||
type ClientEvent struct {
|
||||
Content rawJSON `json:"content"`
|
||||
EventID string `json:"event_id"`
|
||||
OriginServerTS int64 `json:"origin_server_ts"`
|
||||
// RoomID is omitted on /sync responses
|
||||
RoomID string `json:"room_id,omitempty"`
|
||||
Sender string `json:"sender"`
|
||||
StateKey *string `json:"state_key,omitempty"`
|
||||
Type string `json:"type"`
|
||||
Unsigned rawJSON `json:"unsigned,omitempty"`
|
||||
}
|
||||
|
||||
// ToClientEvents converts server events to client events.
|
||||
func ToClientEvents(serverEvs []Event, format EventFormat) []ClientEvent {
|
||||
evs := make([]ClientEvent, len(serverEvs))
|
||||
for i, se := range serverEvs {
|
||||
evs[i] = ToClientEvent(se, format)
|
||||
}
|
||||
return evs
|
||||
}
|
||||
|
||||
// ToClientEvent converts a single server event to a client event.
|
||||
func ToClientEvent(se Event, format EventFormat) ClientEvent {
|
||||
ce := ClientEvent{
|
||||
Content: rawJSON(se.Content()),
|
||||
Sender: se.Sender(),
|
||||
Type: se.Type(),
|
||||
StateKey: se.StateKey(),
|
||||
Unsigned: rawJSON(se.Unsigned()),
|
||||
OriginServerTS: se.OriginServerTS(),
|
||||
EventID: se.EventID(),
|
||||
}
|
||||
if format == FormatAll {
|
||||
ce.RoomID = se.RoomID()
|
||||
}
|
||||
return ce
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue