This repository was archived by the owner on Nov 25, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 654
Support PUTing typing status in clientapi #550
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
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
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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
54 changes: 54 additions & 0 deletions
54
src/github.com/matrix-org/dendrite/clientapi/producers/typingserver.go
This file contains hidden or 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,54 @@ | ||
| // 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" | ||
| "time" | ||
|
|
||
| "github.com/matrix-org/dendrite/typingserver/api" | ||
| "github.com/matrix-org/gomatrixserverlib" | ||
| ) | ||
|
|
||
| // TypingServerProducer produces events for the typing server to consume | ||
| type TypingServerProducer struct { | ||
| InputAPI api.TypingServerInputAPI | ||
| } | ||
|
|
||
| // NewTypingServerProducer creates a new TypingServerProducer | ||
| func NewTypingServerProducer(inputAPI api.TypingServerInputAPI) *TypingServerProducer { | ||
| return &TypingServerProducer{ | ||
| InputAPI: inputAPI, | ||
| } | ||
| } | ||
|
|
||
| // Send typing event to typing server | ||
| func (p *TypingServerProducer) Send( | ||
| ctx context.Context, userID, roomID string, | ||
| typing bool, timeout int64, | ||
| ) error { | ||
| requestData := api.InputTypingEvent{ | ||
| UserID: userID, | ||
| RoomID: roomID, | ||
| Typing: typing, | ||
| Timeout: timeout, | ||
| OriginServerTS: gomatrixserverlib.AsTimestamp(time.Now()), | ||
| } | ||
|
|
||
| var response api.InputTypingEventResponse | ||
| err := p.InputAPI.InputTypingEvent( | ||
| ctx, &api.InputTypingEventRequest{InputTypingEvent: requestData}, &response, | ||
| ) | ||
|
|
||
| return err | ||
| } |
This file contains hidden or 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
80 changes: 80 additions & 0 deletions
80
src/github.com/matrix-org/dendrite/clientapi/routing/sendtyping.go
This file contains hidden or 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,80 @@ | ||
| // 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 routing | ||
|
|
||
| import ( | ||
| "database/sql" | ||
| "net/http" | ||
|
|
||
| "github.com/matrix-org/dendrite/clientapi/auth/authtypes" | ||
| "github.com/matrix-org/dendrite/clientapi/auth/storage/accounts" | ||
| "github.com/matrix-org/dendrite/clientapi/httputil" | ||
| "github.com/matrix-org/dendrite/clientapi/jsonerror" | ||
| "github.com/matrix-org/dendrite/clientapi/producers" | ||
| "github.com/matrix-org/dendrite/clientapi/userutil" | ||
| "github.com/matrix-org/util" | ||
| ) | ||
|
|
||
| type typingContentJSON struct { | ||
| Typing bool `json:"typing"` | ||
| Timeout int64 `json:"timeout"` | ||
| } | ||
|
|
||
| // SendTyping handles PUT /rooms/{roomID}/typing/{userID} | ||
| // sends the typing events to client API typingProducer | ||
| func SendTyping( | ||
| req *http.Request, device *authtypes.Device, roomID string, | ||
| userID string, accountDB *accounts.Database, | ||
| typingProducer *producers.TypingServerProducer, | ||
| ) util.JSONResponse { | ||
| if device.UserID != userID { | ||
| return util.JSONResponse{ | ||
| Code: http.StatusForbidden, | ||
| JSON: jsonerror.Forbidden("Cannot set another user's typing state"), | ||
| } | ||
| } | ||
|
|
||
| localpart, err := userutil.ParseUsernameParam(userID, nil) | ||
| if err != nil { | ||
| return httputil.LogThenError(req, err) | ||
| } | ||
|
|
||
| // Verify that the user is a member of this room | ||
| _, err = accountDB.GetMembershipInRoomByLocalpart(req.Context(), localpart, roomID) | ||
| if err == sql.ErrNoRows { | ||
| return util.JSONResponse{ | ||
| Code: http.StatusForbidden, | ||
| JSON: jsonerror.Forbidden("User not in this room"), | ||
| } | ||
| } else if err != nil { | ||
| return httputil.LogThenError(req, err) | ||
| } | ||
|
|
||
| // parse the incoming http request | ||
| var r typingContentJSON | ||
| resErr := httputil.UnmarshalJSONRequest(req, &r) | ||
| if resErr != nil { | ||
| return *resErr | ||
| } | ||
|
|
||
| if err = typingProducer.Send( | ||
| req.Context(), userID, roomID, r.Typing, r.Timeout, | ||
| ); err != nil { | ||
| return httputil.LogThenError(req, err) | ||
| } | ||
|
|
||
| return util.JSONResponse{ | ||
| Code: http.StatusOK, | ||
| JSON: struct{}{}, | ||
| } | ||
| } |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
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.
/me wonders why the other components haven't been added here.
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.
tracking this via #558