diff --git a/disappearing.go b/disappearing.go index 847511bf..ede68f02 100644 --- a/disappearing.go +++ b/disappearing.go @@ -75,7 +75,7 @@ func (dmm *DisappearingMessagesManager) StartDisappearingLoop(ctx context.Contex log.Err(err).Msg("Failed to get next disappearing message") continue } else if nextMsg != nil { - duration = nextMsg.ExpireAt.Sub(time.Now()) + duration = time.Until(nextMsg.ExpireAt) } select { diff --git a/metrics.go b/metrics.go index d8b5ace7..783a6ad7 100644 --- a/metrics.go +++ b/metrics.go @@ -146,7 +146,7 @@ func (mh *MetricsHandler) TrackMatrixEvent(eventType event.Type) func() { } start := time.Now() return func() { - duration := time.Now().Sub(start) + duration := time.Since(start) mh.matrixEventHandling. With(prometheus.Labels{"event_type": eventType.Type}). Observe(duration.Seconds()) @@ -160,11 +160,11 @@ func (mh *MetricsHandler) TrackSignalMessage(timestamp time.Time, messageType st start := time.Now() return func() { - duration := time.Now().Sub(start) + duration := time.Since(start) mh.signalMessageHandling. With(prometheus.Labels{"message_type": messageType}). Observe(duration.Seconds()) - mh.signalMessageAge.Observe(time.Now().Sub(timestamp).Seconds()) + mh.signalMessageAge.Observe(time.Since(timestamp).Seconds()) } } @@ -271,7 +271,7 @@ func (mh *MetricsHandler) updateStats() { mh.unencryptedGroupCount.Set(float64(unencryptedGroupCount)) mh.unencryptedPrivateCount.Set(float64(encryptedPrivateCount)) } - mh.countCollection.Observe(time.Now().Sub(start).Seconds()) + mh.countCollection.Observe(time.Since(start).Seconds()) } func (mh *MetricsHandler) startUpdatingStats() { diff --git a/pkg/signalmeow/profile.go b/pkg/signalmeow/profile.go index 57aa7f20..7acba443 100644 --- a/pkg/signalmeow/profile.go +++ b/pkg/signalmeow/profile.go @@ -20,7 +20,6 @@ import ( "context" "crypto/aes" "crypto/cipher" - "crypto/rand" "encoding/base64" "encoding/hex" "encoding/json" @@ -300,22 +299,6 @@ func decryptString(key *libsignalgo.ProfileKey, encryptedText []byte) (string, e return string(data), err } -func encryptString(key libsignalgo.ProfileKey, plaintext string, paddedLength int) ([]byte, error) { - inputLength := len(plaintext) - if inputLength > paddedLength { - return nil, errors.New("plaintext longer than paddedLength") - } - padded := append([]byte(plaintext), make([]byte, paddedLength-inputLength)...) - nonce := make([]byte, NONCE_LENGTH) - rand.Read(nonce) - keyBytes := key[:] - ciphertext, err := AesgcmEncrypt(keyBytes, nonce, padded) - if err != nil { - return nil, err - } - return append(nonce, ciphertext...), nil -} - const NONCE_LENGTH = 12 const TAG_LENGTH_BYTES = 16 diff --git a/pkg/signalmeow/sending.go b/pkg/signalmeow/sending.go index b308c397..b079ee30 100644 --- a/pkg/signalmeow/sending.go +++ b/pkg/signalmeow/sending.go @@ -303,11 +303,6 @@ type GroupMessageSendResult struct { FailedToSendTo []FailedSendResult } -func contentFromDataMessage(dataMessage *signalpb.DataMessage) *signalpb.Content { - return &signalpb.Content{ - DataMessage: dataMessage, - } -} func syncMessageFromGroupDataMessage(dataMessage *signalpb.DataMessage, results []SuccessfulSendResult) *signalpb.Content { unidentifiedStatuses := []*signalpb.SyncMessage_Sent_UnidentifiedDeliveryStatus{} for _, result := range results { diff --git a/portal.go b/portal.go index 8b016b27..ac1e4dc3 100644 --- a/portal.go +++ b/portal.go @@ -305,8 +305,7 @@ func (portal *Portal) getBridgeInfo() (string, CustomBridgeInfoContent) { AvatarURL: portal.AvatarURL.CUString(), }, } - var bridgeInfoStateKey string - bridgeInfoStateKey = fmt.Sprintf("fi.mau.signal://signal/%s", portal.ChatID) + bridgeInfoStateKey := fmt.Sprintf("fi.mau.signal://signal/%s", portal.ChatID) bridgeInfo.Channel.ExternalURL = fmt.Sprintf("https://signal.me/#p/%s", portal.ChatID) var roomType string if portal.IsPrivateChat() { diff --git a/puppet.go b/puppet.go index 67f3726c..ce123c85 100644 --- a/puppet.go +++ b/puppet.go @@ -23,7 +23,6 @@ import ( "fmt" "net/http" "regexp" - "sync" "github.com/google/uuid" "github.com/rs/zerolog" @@ -191,8 +190,6 @@ type Puppet struct { customIntent *appservice.IntentAPI customUser *User - - syncLock sync.Mutex } var userIDRegex *regexp.Regexp diff --git a/user.go b/user.go index cad7a166..5978ba6e 100644 --- a/user.go +++ b/user.go @@ -163,8 +163,7 @@ type User struct { Client *signalmeow.Client - BridgeState *bridge.BridgeStateQueue - bridgeStateLock sync.Mutex + BridgeState *bridge.BridgeStateQueue spaceMembershipChecked bool spaceCreateLock sync.Mutex