This repository has been archived by the owner on Nov 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 674
[Federation] Send typing events #572
Merged
Merged
Changes from 6 commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
b500f2b
GetJoinedHosts from federation server db
APwhitehat acbcf5c
Add dummy api.OutputTypingEvent
APwhitehat 7f6764a
Add a typing server consumer to federation sender
APwhitehat fe17eb5
fix lint
APwhitehat 0bd298a
Update queue to support EDU events
APwhitehat 7ae50ff
Update OutputTypingEvent format
APwhitehat 3d6a862
Use SendEDU in federation server, remove dummy/api
APwhitehat 1de4050
Add helpful comments
APwhitehat 6c1412d
fix typo
APwhitehat 23cf26b
remove origin field
APwhitehat 58dceb1
Count EDUs in sendCounter
APwhitehat File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/github.com/matrix-org/dendrite/federationsender/consumers/typingserver.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// 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 consumers | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
|
||
"github.com/matrix-org/dendrite/common" | ||
"github.com/matrix-org/dendrite/common/config" | ||
"github.com/matrix-org/dendrite/federationsender/queue" | ||
"github.com/matrix-org/dendrite/federationsender/storage" | ||
"github.com/matrix-org/dendrite/typingserver/dummy/api" | ||
"github.com/matrix-org/gomatrixserverlib" | ||
log "github.com/sirupsen/logrus" | ||
"gopkg.in/Shopify/sarama.v1" | ||
) | ||
|
||
// OutputTypingEventConsumer consumes events that originate in typing server. | ||
type OutputTypingEventConsumer struct { | ||
consumer *common.ContinualConsumer | ||
db *storage.Database | ||
queues *queue.OutgoingQueues | ||
ServerName gomatrixserverlib.ServerName | ||
} | ||
|
||
// NewOutputTypingEventConsumer creates a new OutputTypingEventConsumer. Call Start() to begin consuming from typing servers. | ||
func NewOutputTypingEventConsumer( | ||
cfg *config.Dendrite, | ||
kafkaConsumer sarama.Consumer, | ||
queues *queue.OutgoingQueues, | ||
store *storage.Database, | ||
) *OutputTypingEventConsumer { | ||
consumer := common.ContinualConsumer{ | ||
Topic: string(cfg.Kafka.Topics.OutputTypingEvent), | ||
Consumer: kafkaConsumer, | ||
PartitionStore: store, | ||
} | ||
c := &OutputTypingEventConsumer{ | ||
consumer: &consumer, | ||
queues: queues, | ||
db: store, | ||
ServerName: cfg.Matrix.ServerName, | ||
} | ||
consumer.ProcessMessage = c.onMessage | ||
|
||
return c | ||
} | ||
|
||
// Start consuming from typing servers | ||
func (t *OutputTypingEventConsumer) Start() error { | ||
return t.consumer.Start() | ||
} | ||
|
||
func (t *OutputTypingEventConsumer) onMessage(msg *sarama.ConsumerMessage) error { | ||
// Extract the typing event from msg. | ||
var ote api.OutputTypingEvent | ||
if err := json.Unmarshal(msg.Value, &ote); err != nil { | ||
// Skip this msg but continue processing messages. | ||
log.WithError(err).Errorf("typingserver output log: message parse failed") | ||
return nil | ||
} | ||
|
||
joined, err := t.db.GetJoinedHosts(context.TODO(), ote.Event.RoomID()) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
names := make([]gomatrixserverlib.ServerName, len(joined)) | ||
for i := range joined { | ||
names[i] = joined[i].ServerName | ||
} | ||
|
||
return t.queues.SendEvent(&ote.Event, t.ServerName, names) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
src/github.com/matrix-org/dendrite/typingserver/dummy/api/api.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
// 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 api | ||
|
||
import "github.com/matrix-org/gomatrixserverlib" | ||
|
||
// TODO: Remove this package after, typingserver/api is updated to contain a gomatrixserverlib.Event | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should probably move this TODO out of dummy package now that the plan is no longer to change to using Event |
||
|
||
// OutputTypingEvent is an entry in typing server output kafka log. | ||
type OutputTypingEvent struct { | ||
// The Event for the typing edu event. | ||
Event gomatrixserverlib.Event `json:"event"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you expand the
OutputTypingEvent
doc comment to explain why we're sending both a TypingEvent and list of currently typing users?