Skip to content
This repository has been archived by the owner on Feb 21, 2024. It is now read-only.

Commit

Permalink
support for ephemeral events and more message types (#69)
Browse files Browse the repository at this point in the history
* support ephemeral events

* added AudioMessage,LocationMessage,FileMessage

Co-authored-by: Bernhard Tittelbach <bernhard@tittelbach.org>
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
  • Loading branch information
3 people authored Aug 27, 2020
1 parent bceb63b commit 7dd5e2a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 0 deletions.
41 changes: 41 additions & 0 deletions events.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,47 @@ type HTMLMessage struct {
FormattedBody string `json:"formatted_body"`
}

// FileInfo contains info about an file - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-file
type FileInfo struct {
Mimetype string `json:"mimetype,omitempty"`
Size uint `json:"size,omitempty"` //filesize in bytes
}

// FileMessage is an m.file event - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-file
type FileMessage struct {
MsgType string `json:"msgtype"`
Body string `json:"body"`
URL string `json:"url"`
Filename string `json:"filename"`
Info FileInfo `json:"info,omitempty"`
ThumbnailURL string `json:"thumbnail_url,omitempty"`
ThumbnailInfo ImageInfo `json:"thumbnail_info,omitempty"`
}

// LocationMessage is an m.location event - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-location
type LocationMessage struct {
MsgType string `json:"msgtype"`
Body string `json:"body"`
GeoURI string `json:"geo_uri"`
ThumbnailURL string `json:"thumbnail_url,omitempty"`
ThumbnailInfo ImageInfo `json:"thumbnail_info,omitempty"`
}

// AudioInfo contains info about an file - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-audio
type AudioInfo struct {
Mimetype string `json:"mimetype,omitempty"`
Size uint `json:"size,omitempty"` //filesize in bytes
Duration uint `json:"duration,omitempty"` //audio duration in ms
}

// AudioMessage is an m.audio event - http://matrix.org/docs/spec/client_server/r0.2.0.html#m-audio
type AudioMessage struct {
MsgType string `json:"msgtype"`
Body string `json:"body"`
URL string `json:"url"`
Info AudioInfo `json:"info,omitempty"`
}

var htmlRegex = regexp.MustCompile("<[^<]+?>")

// GetHTMLMessage returns an HTMLMessage with the body set to a stripped version of the provided HTML, in addition
Expand Down
3 changes: 3 additions & 0 deletions responses.go
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,9 @@ type RespSync struct {
Limited bool `json:"limited"`
PrevBatch string `json:"prev_batch"`
} `json:"timeline"`
Ephemeral struct {
Events []Event `json:"events"`
} `json:"ephemeral"`
} `json:"join"`
Invite map[string]struct {
State struct {
Expand Down
4 changes: 4 additions & 0 deletions sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ func (s *DefaultSyncer) ProcessResponse(res *RespSync, since string) (err error)
event.RoomID = roomID
s.notifyListeners(&event)
}
for _, event := range roomData.Ephemeral.Events {
event.RoomID = roomID
s.notifyListeners(&event)
}
}
for roomID, roomData := range res.Rooms.Invite {
room := s.getOrCreateRoom(roomID)
Expand Down

0 comments on commit 7dd5e2a

Please sign in to comment.