Remove unnecessary utility functions
This commit is contained in:
parent
c46e47aba8
commit
ffd84f5039
5 changed files with 7 additions and 35 deletions
|
@ -293,7 +293,7 @@ func (c *Client) updateJWK(jwk *crypto.JWK) {
|
|||
}
|
||||
|
||||
func (c *Client) updateTachyonAuthToken(t []byte) {
|
||||
authenticatedAt := util.TimestampNow()
|
||||
authenticatedAt := time.Now().UTC()
|
||||
c.authData.TachyonAuthToken = t
|
||||
c.authData.AuthenticatedAt = &authenticatedAt
|
||||
c.Logger.Debug().Any("authenticatedAt", authenticatedAt).Any("tachyonAuthToken", t).Msg("Updated TachyonAuthToken")
|
||||
|
|
|
@ -130,7 +130,7 @@ func (mb *MessageBuilder) AddImage(imgBytes []byte, mime string) *MessageBuilder
|
|||
func (mb *MessageBuilder) newImageData(imgBytes []byte, mime string) (*Image, error) {
|
||||
// TODO explode on unsupported types
|
||||
imgType := ImageTypes[mime]
|
||||
imageId := util.GenerateImageId()
|
||||
imageId := util.GenerateImageID()
|
||||
imageName := util.RandStr(8) + "." + imgType.Extension
|
||||
decryptionKey, err := crypto.GenerateKey(32)
|
||||
if err != nil {
|
||||
|
|
|
@ -95,7 +95,7 @@ func (mb *MessageBuilder) Build() (*binary.SendMessagePayload, error) {
|
|||
}
|
||||
|
||||
if mb.tmpID == "" {
|
||||
mb.tmpID = util.GenerateTmpId()
|
||||
mb.tmpID = util.GenerateTmpID()
|
||||
}
|
||||
|
||||
return mb.newSendConversationMessage(), nil
|
||||
|
@ -106,7 +106,7 @@ func (c *Client) NewMessageBuilder() *MessageBuilder {
|
|||
client: c,
|
||||
}
|
||||
|
||||
tmpId := util.GenerateTmpId()
|
||||
tmpId := util.GenerateTmpID()
|
||||
mb.SetTmpID(tmpId)
|
||||
|
||||
return mb
|
||||
|
|
|
@ -1,8 +1,6 @@
|
|||
package util
|
||||
|
||||
import (
|
||||
crand "crypto/rand"
|
||||
"encoding/hex"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
|
@ -17,10 +15,6 @@ import (
|
|||
|
||||
var Charset = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
|
||||
|
||||
func TimestampNow() time.Time {
|
||||
return time.Now().UTC()
|
||||
}
|
||||
|
||||
func RandStr(length int) string {
|
||||
b := make([]rune, length)
|
||||
for i := range b {
|
||||
|
@ -29,45 +23,23 @@ func RandStr(length int) string {
|
|||
return string(b)
|
||||
}
|
||||
|
||||
func GenerateImageId() string {
|
||||
func GenerateImageID() string {
|
||||
part1 := RandomUUIDv4()
|
||||
part2 := RandStr(25)
|
||||
return part1 + "/" + part2
|
||||
}
|
||||
|
||||
func GenerateTmpId() string {
|
||||
func GenerateTmpID() string {
|
||||
src := rand.NewSource(time.Now().UnixNano())
|
||||
r := rand.New(src)
|
||||
randNum := r.Int63n(1e12)
|
||||
return fmt.Sprintf("tmp_%012d", randNum)
|
||||
}
|
||||
|
||||
func ParseTimestamp(unixTs int64) time.Time {
|
||||
seconds := unixTs / int64(time.Second/time.Microsecond)
|
||||
nanoseconds := (unixTs % int64(time.Second/time.Microsecond)) * int64(time.Microsecond/time.Nanosecond)
|
||||
return time.Unix(seconds, nanoseconds).UTC()
|
||||
}
|
||||
|
||||
func RandomHex(n int) string {
|
||||
bytes := make([]byte, n)
|
||||
crand.Read(bytes)
|
||||
return hex.EncodeToString(bytes)
|
||||
}
|
||||
|
||||
func RandomUUIDv4() string {
|
||||
return uuid.New().String()
|
||||
}
|
||||
|
||||
func RemoveFromSlice(s []string, v string) []string {
|
||||
newS := []string{}
|
||||
for _, i := range s {
|
||||
if i != v {
|
||||
newS = append(newS, i)
|
||||
}
|
||||
}
|
||||
return newS
|
||||
}
|
||||
|
||||
func BuildRelayHeaders(req *http.Request, contentType string, accept string) {
|
||||
req.Header.Add("host", "instantmessaging-pa.googleapis.com")
|
||||
req.Header.Add("connection", "keep-alive")
|
||||
|
|
|
@ -1220,7 +1220,7 @@ func (portal *Portal) HandleMatrixMessage(sender *User, evt *event.Event, timing
|
|||
}
|
||||
}
|
||||
|
||||
txnID := util.GenerateTmpId()
|
||||
txnID := util.GenerateTmpID()
|
||||
portal.outgoingMessagesLock.Lock()
|
||||
portal.outgoingMessages[txnID] = &outgoingMessage{Event: evt}
|
||||
portal.outgoingMessagesLock.Unlock()
|
||||
|
|
Loading…
Reference in a new issue