diff options
author | Till <2353100+S7evinK@users.noreply.github.com> | 2022-04-06 13:11:19 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-06 13:11:19 +0200 |
commit | e5e3350ce168a192dfc6b6b654276d5cffbdbf0f (patch) | |
tree | 738e3bd364da85767de8c487d3d9a851ab804e8b /syncapi/producers | |
parent | 16e2d243fc8f3d433a9d7f428e6f782065dc5e89 (diff) |
Add presence module V2 (#2312)
* Syncapi presence
* Clientapi http presence handler
* Why is this here?
* Missing files
* FederationAPI presence implementation
* Add new presence stream
* Pinecone update
* Pinecone update
* Add passing tests
* Make linter happy
* Add presence producer
* Add presence config option
* Set user to unavailable after x minutes
* Only set currently_active if online
Avoid unneeded presence updates when syncing
* Tweaks
* Query devices for last_active_ts
Fixes & tweaks
* Export SharedUsers/SharedUsers
* Presence stream in MemoryStorage
* Remove status_msg_nil
* Fix sytest crashes
* Make presence types const and use stringer for it
* Change options to allow inbound/outbound presence
* Fix option & typo
* Update configs
Co-authored-by: Neil Alexander <neilalexander@users.noreply.github.com>
Diffstat (limited to 'syncapi/producers')
-rw-r--r-- | syncapi/producers/federationapi_presence.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/syncapi/producers/federationapi_presence.go b/syncapi/producers/federationapi_presence.go new file mode 100644 index 00000000..dc03457e --- /dev/null +++ b/syncapi/producers/federationapi_presence.go @@ -0,0 +1,48 @@ +// Copyright 2022 The Matrix.org Foundation C.I.C. +// +// 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 ( + "strconv" + "time" + + "github.com/matrix-org/dendrite/setup/jetstream" + "github.com/matrix-org/dendrite/syncapi/types" + "github.com/matrix-org/gomatrixserverlib" + "github.com/nats-io/nats.go" +) + +// FederationAPIPresenceProducer produces events for the federation API server to consume +type FederationAPIPresenceProducer struct { + Topic string + JetStream nats.JetStreamContext +} + +func (f *FederationAPIPresenceProducer) SendPresence( + userID string, presence types.Presence, statusMsg *string, +) error { + msg := nats.NewMsg(f.Topic) + msg.Header.Set(jetstream.UserID, userID) + msg.Header.Set("presence", presence.String()) + msg.Header.Set("from_sync", "true") // only update last_active_ts and presence + msg.Header.Set("last_active_ts", strconv.Itoa(int(gomatrixserverlib.AsTimestamp(time.Now())))) + + if statusMsg != nil { + msg.Header.Set("status_msg", *statusMsg) + } + + _, err := f.JetStream.PublishMsg(msg) + return err +} |