mirror of
https://github.com/matrix-org/dendrite.git
synced 2025-12-29 01:33:10 -06:00
Fix linter errors
This commit is contained in:
parent
1dbcd842b0
commit
5ccfe77cea
|
|
@ -14,8 +14,6 @@ import (
|
|||
"github.com/matrix-org/util"
|
||||
)
|
||||
|
||||
const pushRulesAccountDataType = "m.push_rules"
|
||||
|
||||
func errorResponse(ctx context.Context, err error, msg string, args ...interface{}) util.JSONResponse {
|
||||
if eerr, ok := err.(*jsonerror.MatrixError); ok {
|
||||
var status int
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@
|
|||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
//go:build !windows
|
||||
// +build !windows
|
||||
|
||||
package internal
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ import (
|
|||
"github.com/matrix-org/gomatrixserverlib"
|
||||
)
|
||||
|
||||
// A Client is how interactions iwth a Push Gateway is done.
|
||||
// A Client is how interactions with a Push Gateway is done.
|
||||
type Client interface {
|
||||
// Notify sends a notification to the gateway at the given URL.
|
||||
Notify(ctx context.Context, url string, req *NotifyRequest, resp *NotifyResponse) error
|
||||
|
|
|
|||
|
|
@ -70,7 +70,7 @@ const (
|
|||
|
||||
// CoalesceAction tells the clients to show a notification, and
|
||||
// tells both servers and clients that multiple events can be
|
||||
// coalesced into a single notification. The behavior is
|
||||
// coalesced into a single notification. The behaviour is
|
||||
// implementation-specific.
|
||||
CoalesceAction ActionKind = "coalesce"
|
||||
|
||||
|
|
|
|||
|
|
@ -151,7 +151,7 @@ func patternMatches(key, pattern string, event *gomatrixserverlib.Event) (bool,
|
|||
}
|
||||
|
||||
var eventMap map[string]interface{}
|
||||
if err := json.Unmarshal(event.JSON(), &eventMap); err != nil {
|
||||
if err = json.Unmarshal(event.JSON(), &eventMap); err != nil {
|
||||
return false, fmt.Errorf("parsing event: %w", err)
|
||||
}
|
||||
v, err := lookupMapPath(strings.Split(key, "."), eventMap)
|
||||
|
|
|
|||
|
|
@ -93,7 +93,7 @@ func lookupMapPath(path []string, m map[string]interface{}) (interface{}, error)
|
|||
}
|
||||
|
||||
// parseRoomMemberCountCondition parses a string like "2", "==2", "<2"
|
||||
// into a function that checks if the argument to it fulfills the
|
||||
// into a function that checks if the argument to it fulfils the
|
||||
// condition.
|
||||
func parseRoomMemberCountCondition(s string) (func(int) bool, error) {
|
||||
var b int
|
||||
|
|
|
|||
|
|
@ -104,7 +104,7 @@ func (s *OutputClientDataConsumer) onMessage(msg *sarama.ConsumerMessage) error
|
|||
DataType: mFullyRead,
|
||||
}
|
||||
var userRes uapi.QueryAccountDataResponse
|
||||
if err := s.userAPI.QueryAccountData(ctx, &userReq, &userRes); err != nil {
|
||||
if err = s.userAPI.QueryAccountData(ctx, &userReq, &userRes); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"localpart": localpart,
|
||||
"room_id": event.RoomID,
|
||||
|
|
@ -129,7 +129,7 @@ func (s *OutputClientDataConsumer) onMessage(msg *sarama.ConsumerMessage) error
|
|||
return nil
|
||||
}
|
||||
var data fullyReadAccountData
|
||||
if err := json.Unmarshal([]byte(bs), &data); err != nil {
|
||||
if err = json.Unmarshal([]byte(bs), &data); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"localpart": localpart,
|
||||
"room_id": event.RoomID,
|
||||
|
|
|
|||
|
|
@ -119,7 +119,8 @@ func (s *OutputRoomEventConsumer) processMessage(ctx context.Context, event *gom
|
|||
|
||||
if event.Type() == gomatrixserverlib.MRoomMember {
|
||||
cevent := gomatrixserverlib.HeaderedToClientEvent(event, gomatrixserverlib.FormatAll)
|
||||
member, err := newLocalMembership(&cevent)
|
||||
var member *localMembership
|
||||
member, err = newLocalMembership(&cevent)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
@ -252,8 +253,8 @@ func (s *OutputRoomEventConsumer) roomName(ctx context.Context, event *gomatrixs
|
|||
return "", err
|
||||
}
|
||||
|
||||
if event := res.StateEvents[roomNameTuple]; event != nil {
|
||||
return unmarshalRoomName(event)
|
||||
if eventS := res.StateEvents[roomNameTuple]; eventS != nil {
|
||||
return unmarshalRoomName(eventS)
|
||||
}
|
||||
|
||||
if event.Type() == gomatrixserverlib.MRoomCanonicalAlias {
|
||||
|
|
@ -326,7 +327,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *gomatr
|
|||
Actions: actions,
|
||||
// UNSPEC: the spec doesn't say this is a ClientEvent, but the
|
||||
// fields seem to match. room_id should be missing, which
|
||||
// matches the behavior of FormatSync.
|
||||
// matches the behaviour of FormatSync.
|
||||
Event: gomatrixserverlib.HeaderedToClientEvent(event, gomatrixserverlib.FormatSync),
|
||||
// TODO: this is per-device, but it's not part of the primary
|
||||
// key. So inserting one notification per profile tag doesn't
|
||||
|
|
@ -336,11 +337,11 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *gomatr
|
|||
RoomID: event.RoomID(),
|
||||
TS: gomatrixserverlib.AsTimestamp(time.Now()),
|
||||
}
|
||||
if err := s.db.InsertNotification(ctx, mem.Localpart, event.EventID(), tweaks, n); err != nil {
|
||||
if err = s.db.InsertNotification(ctx, mem.Localpart, event.EventID(), tweaks, n); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if err := s.syncProducer.GetAndSendNotificationData(ctx, mem.UserID, event.RoomID()); err != nil {
|
||||
if err = s.syncProducer.GetAndSendNotificationData(ctx, mem.UserID, event.RoomID()); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
|
|
@ -398,12 +399,7 @@ func (s *OutputRoomEventConsumer) notifyLocal(ctx context.Context, event *gomatr
|
|||
}
|
||||
|
||||
if len(rejected) > 0 {
|
||||
if err := s.deleteRejectedPushers(ctx, rejected, mem.Localpart); err != nil {
|
||||
log.WithFields(log.Fields{
|
||||
"localpart": mem.Localpart,
|
||||
"num_pushers": len(rejected),
|
||||
}).WithError(err).Errorf("Unable to delete rejected pushers")
|
||||
}
|
||||
s.deleteRejectedPushers(ctx, rejected, mem.Localpart)
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
@ -593,7 +589,7 @@ func (s *OutputRoomEventConsumer) notifyHTTP(ctx context.Context, event *gomatri
|
|||
}
|
||||
|
||||
// deleteRejectedPushers deletes the pushers associated with the given devices.
|
||||
func (s *OutputRoomEventConsumer) deleteRejectedPushers(ctx context.Context, devices []*pushgateway.Device, localpart string) error {
|
||||
func (s *OutputRoomEventConsumer) deleteRejectedPushers(ctx context.Context, devices []*pushgateway.Device, localpart string) {
|
||||
log.WithFields(log.Fields{
|
||||
"localpart": localpart,
|
||||
"app_id0": devices[0].AppID,
|
||||
|
|
@ -607,23 +603,4 @@ func (s *OutputRoomEventConsumer) deleteRejectedPushers(ctx context.Context, dev
|
|||
}).WithError(err).Errorf("Unable to delete rejected pusher")
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// mapWithout returns a shallow copy of the map, without the given
|
||||
// key. Returns nil if the resulting map is empty.
|
||||
func mapWithout(m map[string]interface{}, key string) map[string]interface{} {
|
||||
ret := make(map[string]interface{}, len(m))
|
||||
for k, v := range m {
|
||||
// The specification says we do not send "url".
|
||||
if k == key {
|
||||
continue
|
||||
}
|
||||
ret[k] = v
|
||||
}
|
||||
if len(ret) == 0 {
|
||||
return nil
|
||||
}
|
||||
return ret
|
||||
}
|
||||
|
|
|
|||
|
|
@ -226,14 +226,6 @@ func (c *fakePushGatewayClient) Notify(ctx context.Context, url string, req *pus
|
|||
return nil
|
||||
}
|
||||
|
||||
func mustMarshalJSON(v interface{}) []byte {
|
||||
bs, err := json.Marshal(v)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
return bs
|
||||
}
|
||||
|
||||
func mustParseClientEventJSON(s string) gomatrixserverlib.ClientEvent {
|
||||
var ev gomatrixserverlib.ClientEvent
|
||||
if err := json.Unmarshal([]byte(s), &ev); err != nil {
|
||||
|
|
|
|||
|
|
@ -197,7 +197,7 @@ func (s *notificationsStatements) SelectCount(ctx context.Context, localpart str
|
|||
}
|
||||
defer internal.CloseAndLogIfError(ctx, rows, "notifications.Select: rows.Close() failed")
|
||||
|
||||
for rows.Next() {
|
||||
if rows.Next() {
|
||||
var count int64
|
||||
if err := rows.Scan(&count); err != nil {
|
||||
return 0, err
|
||||
|
|
@ -225,7 +225,7 @@ func (s *notificationsStatements) SelectRoomCounts(ctx context.Context, localpar
|
|||
}
|
||||
defer internal.CloseAndLogIfError(ctx, rows, "notifications.Select: rows.Close() failed")
|
||||
|
||||
for rows.Next() {
|
||||
if rows.Next() {
|
||||
var total, highlight int64
|
||||
if err := rows.Scan(&total, &highlight); err != nil {
|
||||
return 0, 0, err
|
||||
|
|
|
|||
|
|
@ -127,7 +127,7 @@ func TestNewEventAndJoinedToRoom(t *testing.T) {
|
|||
go func() {
|
||||
pos, err := waitForEvents(n, newTestSyncRequest(bob, bobDev, syncPositionBefore))
|
||||
if err != nil {
|
||||
t.Errorf("TestNewEventAndJoinedToRoom error: %w", err)
|
||||
t.Errorf("TestNewEventAndJoinedToRoom error: %v", err)
|
||||
}
|
||||
mustEqualPositions(t, pos, syncPositionAfter)
|
||||
wg.Done()
|
||||
|
|
@ -190,7 +190,7 @@ func TestNewInviteEventForUser(t *testing.T) {
|
|||
go func() {
|
||||
pos, err := waitForEvents(n, newTestSyncRequest(bob, bobDev, syncPositionBefore))
|
||||
if err != nil {
|
||||
t.Errorf("TestNewInviteEventForUser error: %w", err)
|
||||
t.Errorf("TestNewInviteEventForUser error: %v", err)
|
||||
}
|
||||
mustEqualPositions(t, pos, syncPositionAfter)
|
||||
wg.Done()
|
||||
|
|
@ -219,7 +219,7 @@ func TestEDUWakeup(t *testing.T) {
|
|||
go func() {
|
||||
pos, err := waitForEvents(n, newTestSyncRequest(bob, bobDev, syncPositionAfter))
|
||||
if err != nil {
|
||||
t.Errorf("TestNewInviteEventForUser error: %w", err)
|
||||
t.Errorf("TestNewInviteEventForUser error: %v", err)
|
||||
}
|
||||
mustEqualPositions(t, pos, syncPositionNewEDU)
|
||||
wg.Done()
|
||||
|
|
@ -246,7 +246,7 @@ func TestMultipleRequestWakeup(t *testing.T) {
|
|||
poll := func() {
|
||||
pos, err := waitForEvents(n, newTestSyncRequest(bob, bobDev, syncPositionBefore))
|
||||
if err != nil {
|
||||
t.Errorf("TestMultipleRequestWakeup error: %w", err)
|
||||
t.Errorf("TestMultipleRequestWakeup error: %v", err)
|
||||
}
|
||||
mustEqualPositions(t, pos, syncPositionAfter)
|
||||
wg.Done()
|
||||
|
|
@ -284,7 +284,7 @@ func TestNewEventAndWasPreviouslyJoinedToRoom(t *testing.T) {
|
|||
go func() {
|
||||
pos, err := waitForEvents(n, newTestSyncRequest(bob, bobDev, syncPositionBefore))
|
||||
if err != nil {
|
||||
t.Errorf("TestNewEventAndWasPreviouslyJoinedToRoom error: %w", err)
|
||||
t.Errorf("TestNewEventAndWasPreviouslyJoinedToRoom error: %v", err)
|
||||
}
|
||||
mustEqualPositions(t, pos, syncPositionAfter)
|
||||
leaveWG.Done()
|
||||
|
|
@ -301,7 +301,7 @@ func TestNewEventAndWasPreviouslyJoinedToRoom(t *testing.T) {
|
|||
go func() {
|
||||
pos, err := waitForEvents(n, newTestSyncRequest(alice, aliceDev, syncPositionAfter))
|
||||
if err != nil {
|
||||
t.Errorf("TestNewEventAndWasPreviouslyJoinedToRoom error: %w", err)
|
||||
t.Errorf("TestNewEventAndWasPreviouslyJoinedToRoom error: %v", err)
|
||||
}
|
||||
mustEqualPositions(t, pos, syncPositionAfter2)
|
||||
aliceWG.Done()
|
||||
|
|
|
|||
Loading…
Reference in a new issue