From 2ccd4fa069894738533316e480c31b3da992bea4 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Fri, 4 Sep 2020 16:17:02 +0100 Subject: [PATCH] Clear a whole bunch of lint issues --- clientapi/routing/peekroom.go | 3 +-- roomserver/api/output.go | 4 ++-- roomserver/internal/perform/perform_peek.go | 13 ++++++------- syncapi/storage/shared/syncserver.go | 1 + syncapi/storage/sqlite3/peeks_table.go | 2 +- syncapi/sync/notifier.go | 17 ++++++----------- syncapi/types/types.go | 6 +++--- 7 files changed, 20 insertions(+), 26 deletions(-) diff --git a/clientapi/routing/peekroom.go b/clientapi/routing/peekroom.go index d86ccd6b5..d96f91d0f 100644 --- a/clientapi/routing/peekroom.go +++ b/clientapi/routing/peekroom.go @@ -40,7 +40,7 @@ func PeekRoomByIDOrAlias( peekReq := roomserverAPI.PerformPeekRequest{ RoomIDOrAlias: roomIDOrAlias, UserID: device.UserID, - DeviceID: device.ID, + DeviceID: device.ID, } peekRes := roomserverAPI.PerformPeekResponse{} @@ -64,7 +64,6 @@ func PeekRoomByIDOrAlias( // if this user is already joined to the room, we let them peek anyway // (given they might be about to part the room, and it makes things less fiddly) - // Peeking stops if none of the devices who started peeking have been // /syncing for a while, or if everyone who was peeking calls /leave // (or /unpeek with a server_name param? or DELETE /peek?) diff --git a/roomserver/api/output.go b/roomserver/api/output.go index d74a37b36..013ebdc83 100644 --- a/roomserver/api/output.go +++ b/roomserver/api/output.go @@ -204,7 +204,7 @@ type OutputRedactedEvent struct { // An OutputNewPeek is written whenever a user starts peeking into a room // using a given device. type OutputNewPeek struct { - RoomID string - UserID string + RoomID string + UserID string DeviceID string } diff --git a/roomserver/internal/perform/perform_peek.go b/roomserver/internal/perform/perform_peek.go index 7a212f9af..ab6d17b03 100644 --- a/roomserver/internal/perform/perform_peek.go +++ b/roomserver/internal/perform/perform_peek.go @@ -20,8 +20,8 @@ import ( "fmt" "strings" - "github.com/matrix-org/dendrite/internal/config" fsAPI "github.com/matrix-org/dendrite/federationsender/api" + "github.com/matrix-org/dendrite/internal/config" "github.com/matrix-org/dendrite/roomserver/api" "github.com/matrix-org/dendrite/roomserver/internal/input" "github.com/matrix-org/dendrite/roomserver/storage" @@ -39,7 +39,6 @@ type Peeker struct { Inputer *input.Inputer } - // PerformPeek handles peeking into matrix rooms, including over federation by talking to the federationsender. func (r *Peeker) PerformPeek( ctx context.Context, @@ -164,7 +163,7 @@ func (r *Peeker) performPeekRoomByID( // XXX: we should probably factor out history_visibility checks into a common utility method somewhere // which handles the default value etc. var worldReadable = false - ev, err := r.DB.GetStateEvent(ctx, roomID, "m.room.history_visibility", "") + ev, _ := r.DB.GetStateEvent(ctx, roomID, "m.room.history_visibility", "") if ev != nil { content := map[string]string{} if err = json.Unmarshal(ev.Content(), &content); err != nil { @@ -179,7 +178,7 @@ func (r *Peeker) performPeekRoomByID( if !worldReadable { return "", &api.PerformError{ Code: api.PerformErrorNotAllowed, - Msg: "Room is not world-readable", + Msg: "Room is not world-readable", } } @@ -189,8 +188,8 @@ func (r *Peeker) performPeekRoomByID( { Type: api.OutputTypeNewPeek, NewPeek: &api.OutputNewPeek{ - RoomID: roomID, - UserID: req.UserID, + RoomID: roomID, + UserID: req.UserID, DeviceID: req.DeviceID, }, }, @@ -203,5 +202,5 @@ func (r *Peeker) performPeekRoomByID( // it will have been overwritten with a room ID by performPeekRoomByAlias. // We should now include this in the response so that the CS API can // return the right room ID. - return roomID, nil; + return roomID, nil } diff --git a/syncapi/storage/shared/syncserver.go b/syncapi/storage/shared/syncserver.go index b3c5fc7f1..8170c35c6 100644 --- a/syncapi/storage/shared/syncserver.go +++ b/syncapi/storage/shared/syncserver.go @@ -987,6 +987,7 @@ func (d *Database) fetchMissingStateEvents( // exclusive of oldPos, inclusive of newPos, for the rooms in which // the user has new membership events. // A list of joined room IDs is also returned in case the caller needs it. +// nolint:gocyclo func (d *Database) getStateDeltas( ctx context.Context, device *userapi.Device, txn *sql.Tx, r types.Range, userID string, diff --git a/syncapi/storage/sqlite3/peeks_table.go b/syncapi/storage/sqlite3/peeks_table.go index bc90e175b..431d5ed7a 100644 --- a/syncapi/storage/sqlite3/peeks_table.go +++ b/syncapi/storage/sqlite3/peeks_table.go @@ -178,7 +178,7 @@ func (s *peekStatements) SelectPeekingDevices( return nil, err } devices := result[roomID] - devices = append(devices, types.PeekingDevice{userID, deviceID}) + devices = append(devices, types.PeekingDevice{UserID: userID, DeviceID: deviceID}) result[roomID] = devices } return result, nil diff --git a/syncapi/sync/notifier.go b/syncapi/sync/notifier.go index fc8482037..e7642c3d8 100644 --- a/syncapi/sync/notifier.go +++ b/syncapi/sync/notifier.go @@ -246,12 +246,10 @@ func (n *Notifier) wakeupUsers(userIDs []string, peekingDevices []types.PeekingD } } - if peekingDevices != nil { - for _, peekingDevice := range peekingDevices { - // TODO: don't bother waking up for devices whose users we already woke up - if stream := n.fetchUserDeviceStream(peekingDevice.UserID, peekingDevice.DeviceID, false); stream != nil { - stream.Broadcast(newPos) // wake up all goroutines Wait()ing on this stream - } + for _, peekingDevice := range peekingDevices { + // TODO: don't bother waking up for devices whose users we already woke up + if stream := n.fetchUserDeviceStream(peekingDevice.UserID, peekingDevice.DeviceID, false); stream != nil { + stream.Broadcast(newPos) // wake up all goroutines Wait()ing on this stream } } } @@ -332,13 +330,12 @@ func (n *Notifier) joinedUsers(roomID string) (userIDs []string) { return n.roomIDToJoinedUsers[roomID].values() } - // Not thread-safe: must be called on the OnNewEvent goroutine only func (n *Notifier) addPeekingDevice(roomID, userID, deviceID string) { if _, ok := n.roomIDToPeekingDevices[roomID]; !ok { n.roomIDToPeekingDevices[roomID] = make(peekingDeviceSet) } - n.roomIDToPeekingDevices[roomID].add(types.PeekingDevice{userID, deviceID}) + n.roomIDToPeekingDevices[roomID].add(types.PeekingDevice{UserID: userID, DeviceID: deviceID}) } // Not thread-safe: must be called on the OnNewEvent goroutine only @@ -347,7 +344,7 @@ func (n *Notifier) removePeekingDevice(roomID, userID, deviceID string) { n.roomIDToPeekingDevices[roomID] = make(peekingDeviceSet) } // XXX: is this going to work as a key? - n.roomIDToPeekingDevices[roomID].remove(types.PeekingDevice{userID, deviceID}) + n.roomIDToPeekingDevices[roomID].remove(types.PeekingDevice{UserID: userID, DeviceID: deviceID}) } // Not thread-safe: must be called on the OnNewEvent goroutine only @@ -358,8 +355,6 @@ func (n *Notifier) PeekingDevices(roomID string) (peekingDevices []types.Peeking return n.roomIDToPeekingDevices[roomID].values() } - - // removeEmptyUserStreams iterates through the user stream map and removes any // that have been empty for a certain amount of time. This is a crude way of // ensuring that the userStreams map doesn't grow forver. diff --git a/syncapi/types/types.go b/syncapi/types/types.go index 23d88626c..0c737a29a 100644 --- a/syncapi/types/types.go +++ b/syncapi/types/types.go @@ -511,11 +511,11 @@ type SendToDeviceEvent struct { } type PeekingDevice struct { - UserID string - DeviceID string + UserID string + DeviceID string } type Peek struct { RoomID string New bool -} \ No newline at end of file +}