updated deps

This commit is contained in:
Aine
2023-02-13 13:02:13 +02:00
parent dbe4a73174
commit 19e2047a2b
140 changed files with 4106 additions and 12049 deletions

View File

@@ -44,7 +44,7 @@ func (as *AppService) Start() {
} else {
err = as.server.ListenAndServeTLS(as.Host.TLSCert, as.Host.TLSKey)
}
if err != nil && err.Error() != "http: Server closed" {
if err != nil && !errors.Is(err, http.ErrServerClosed) {
as.Log.Fatalln("Error while listening:", err)
} else {
as.Log.Debugln("Listener stopped.")

View File

@@ -11,7 +11,6 @@ import (
"errors"
"fmt"
"strings"
"time"
"maunium.net/go/mautrix"
"maunium.net/go/mautrix/event"
@@ -256,11 +255,12 @@ func (intent *IntentAPI) SendCustomMembershipEvent(roomID id.RoomID, target id.U
ok = memberContent != nil
}
if !ok {
err := intent.StateEvent(roomID, event.StateMember, target.String(), &memberContent)
profile, err := intent.GetProfile(target)
if err != nil {
intent.Logger.Debugfln("Failed to get member info for %s/%s to fill new %s membership event: %v", roomID, target, membership, err)
intent.Logger.Debugfln("Failed to get profile for %s to fill new %s membership event: %v", target, membership, err)
} else {
ok = true
content.Displayname = profile.DisplayName
content.AvatarURL = profile.AvatarURL.CUString()
}
}
}
@@ -402,21 +402,6 @@ func (intent *IntentAPI) SetPowerLevel(roomID id.RoomID, userID id.UserID, level
return nil, nil
}
func (intent *IntentAPI) UserTyping(roomID id.RoomID, typing bool, timeout time.Duration) (resp *mautrix.RespTyping, err error) {
if intent.as.StateStore.IsTyping(roomID, intent.UserID) == typing {
return
}
resp, err = intent.Client.UserTyping(roomID, typing, timeout)
if err != nil {
return
}
if !typing {
timeout = -1
}
intent.as.StateStore.SetTyping(roomID, intent.UserID, timeout)
return
}
func (intent *IntentAPI) SendText(roomID id.RoomID, text string) (*mautrix.RespSendEvent, error) {
if err := intent.EnsureJoined(roomID); err != nil {
return nil, err

View File

@@ -20,6 +20,7 @@ import (
)
type OTKCountMap = map[id.UserID]map[id.DeviceID]mautrix.OTKCount
type FallbackKeyMap = map[id.UserID]map[id.DeviceID][]id.KeyAlgorithm
// Transaction contains a list of events.
type Transaction struct {
@@ -29,11 +30,13 @@ type Transaction struct {
DeviceLists *mautrix.DeviceLists `json:"device_lists,omitempty"`
DeviceOTKCount OTKCountMap `json:"device_one_time_keys_count,omitempty"`
FallbackKeys FallbackKeyMap `json:"device_unused_fallback_key_types,omitempty"`
MSC2409EphemeralEvents []*event.Event `json:"de.sorunome.msc2409.ephemeral,omitempty"`
MSC2409ToDeviceEvents []*event.Event `json:"de.sorunome.msc2409.to_device,omitempty"`
MSC3202DeviceLists *mautrix.DeviceLists `json:"org.matrix.msc3202.device_lists,omitempty"`
MSC3202DeviceOTKCount OTKCountMap `json:"org.matrix.msc3202.device_one_time_keys_count,omitempty"`
MSC3202FallbackKeys FallbackKeyMap `json:"org.matrix.msc3202.device_unused_fallback_key_types,omitempty"`
}
func (txn *Transaction) MarshalZerologObject(ctx *zerolog.Event) {
@@ -46,6 +49,9 @@ func (txn *Transaction) MarshalZerologObject(ctx *zerolog.Event) {
if txn.DeviceLists != nil {
ctx.Int("device_changes", len(txn.DeviceLists.Changed))
}
if txn.FallbackKeys != nil {
ctx.Int("fallback_key_users", len(txn.FallbackKeys))
}
}
func (txn *Transaction) ContentString() string {
@@ -73,6 +79,11 @@ func (txn *Transaction) ContentString() string {
} else if txn.MSC3202DeviceLists != nil {
parts = append(parts, fmt.Sprintf("%d device list changes (unstable)", len(txn.MSC3202DeviceLists.Changed)))
}
if txn.FallbackKeys != nil {
parts = append(parts, fmt.Sprintf("unused fallback key counts for %d users", len(txn.FallbackKeys)))
} else if txn.MSC3202FallbackKeys != nil {
parts = append(parts, fmt.Sprintf("unused fallback key counts for %d users (unstable)", len(txn.MSC3202FallbackKeys)))
}
return strings.Join(parts, ", ")
}

View File

@@ -8,7 +8,6 @@ package appservice
import (
"sync"
"time"
"maunium.net/go/mautrix/event"
"maunium.net/go/mautrix/id"
@@ -18,9 +17,6 @@ type StateStore interface {
IsRegistered(userID id.UserID) bool
MarkRegistered(userID id.UserID)
IsTyping(roomID id.RoomID, userID id.UserID) bool
SetTyping(roomID id.RoomID, userID id.UserID, timeout time.Duration)
IsInRoom(roomID id.RoomID, userID id.UserID) bool
IsInvited(roomID id.RoomID, userID id.UserID) bool
IsMembership(roomID id.RoomID, userID id.UserID, allowedMemberships ...event.Membership) bool
@@ -45,67 +41,21 @@ func (as *AppService) UpdateState(evt *event.Event) {
}
}
type TypingStateStore struct {
typing map[id.RoomID]map[id.UserID]time.Time
typingLock sync.RWMutex
}
func NewTypingStateStore() *TypingStateStore {
return &TypingStateStore{
typing: make(map[id.RoomID]map[id.UserID]time.Time),
}
}
func (store *TypingStateStore) IsTyping(roomID id.RoomID, userID id.UserID) bool {
store.typingLock.RLock()
defer store.typingLock.RUnlock()
roomTyping, ok := store.typing[roomID]
if !ok {
return false
}
typingEndsAt := roomTyping[userID]
return typingEndsAt.After(time.Now())
}
func (store *TypingStateStore) SetTyping(roomID id.RoomID, userID id.UserID, timeout time.Duration) {
store.typingLock.Lock()
defer store.typingLock.Unlock()
roomTyping, ok := store.typing[roomID]
if !ok {
if timeout >= 0 {
roomTyping = map[id.UserID]time.Time{
userID: time.Now().Add(timeout),
}
} else {
return
}
} else {
if timeout >= 0 {
roomTyping[userID] = time.Now().Add(timeout)
} else {
delete(roomTyping, userID)
}
}
store.typing[roomID] = roomTyping
}
type BasicStateStore struct {
registrationsLock sync.RWMutex `json:"-"`
Registrations map[id.UserID]bool `json:"registrations"`
membersLock sync.RWMutex `json:"-"`
Members map[id.RoomID]map[id.UserID]*event.MemberEventContent `json:"memberships"`
powerLevelsLock sync.RWMutex `json:"-"`
PowerLevels map[id.RoomID]*event.PowerLevelsEventContent `json:"power_levels"`
Registrations map[id.UserID]bool `json:"registrations"`
Members map[id.RoomID]map[id.UserID]*event.MemberEventContent `json:"memberships"`
PowerLevels map[id.RoomID]*event.PowerLevelsEventContent `json:"power_levels"`
*TypingStateStore
registrationsLock sync.RWMutex
membersLock sync.RWMutex
powerLevelsLock sync.RWMutex
}
func NewBasicStateStore() StateStore {
return &BasicStateStore{
Registrations: make(map[id.UserID]bool),
Members: make(map[id.RoomID]map[id.UserID]*event.MemberEventContent),
PowerLevels: make(map[id.RoomID]*event.PowerLevelsEventContent),
TypingStateStore: NewTypingStateStore(),
Registrations: make(map[id.UserID]bool),
Members: make(map[id.RoomID]map[id.UserID]*event.MemberEventContent),
PowerLevels: make(map[id.RoomID]*event.PowerLevelsEventContent),
}
}