Compare commits

...

4 Commits

Author SHA1 Message Date
Tulir Asokan bcdfa04c57 Fix order of variables 2024-03-12 20:59:46 +02:00
Tulir Asokan fee357b652 Count messages that failed to save 2024-03-12 20:58:16 +02:00
Tulir Asokan 46420c1319 Fix update user query 2024-03-12 20:58:00 +02:00
Tulir Asokan d1bc6871d0 Give bridge bot PL 100 in DMs 2024-03-12 20:21:01 +02:00
3 changed files with 19 additions and 7 deletions

View File

@ -54,10 +54,10 @@ const (
`
updateUserQuery = `
UPDATE "user"
SET username=$1, agent=$2, device=$3,
management_room=$4, space_room=$5,
phone_last_seen=$6, phone_last_pinged=$7, timezone=$8
WHERE mxid=$9
SET username=$2, agent=$3, device=$4,
management_room=$5, space_room=$6,
phone_last_seen=$7, phone_last_pinged=$8, timezone=$9
WHERE mxid=$1
`
getUserLastAppStateKeyIDQuery = "SELECT key_id FROM whatsmeow_app_state_sync_keys WHERE jid=$1 ORDER BY timestamp DESC LIMIT 1"
)
@ -126,9 +126,9 @@ func (user *User) sqlVariables() []any {
device = dbutil.NumPtr(user.JID.Device)
}
return []any{
username, agent, device, user.ManagementRoom, user.SpaceRoom,
user.MXID, username, agent, device, user.ManagementRoom, user.SpaceRoom,
dbutil.UnixPtr(user.PhoneLastSeen), dbutil.UnixPtr(user.PhoneLastPinged),
user.Timezone, user.MXID,
user.Timezone,
}
}

View File

@ -526,6 +526,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
Msg("Storing history sync")
successfullySavedTotal := 0
failedToSaveTotal := 0
totalMessageCount := 0
for _, conv := range evt.GetConversations() {
jid, err := types.ParseJID(conv.GetId())
@ -578,6 +579,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
var minTimeIndex, maxTimeIndex int
successfullySaved := 0
failedToSave := 0
unsupportedTypes := 0
for i, rawMsg := range conv.GetMessages() {
// Don't store messages that will just be skipped.
@ -614,6 +616,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
Str("msg_id", msgEvt.Info.ID).
Time("msg_time", msgEvt.Info.Timestamp).
Msg("Failed to save historical message")
failedToSave++
continue
}
err = message.Insert(ctx)
@ -623,12 +626,16 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
Str("msg_id", msgEvt.Info.ID).
Time("msg_time", msgEvt.Info.Timestamp).
Msg("Failed to save historical message")
failedToSave++
} else {
successfullySaved++
}
successfullySaved++
}
successfullySavedTotal += successfullySaved
failedToSaveTotal += failedToSave
log.Debug().
Int("saved_count", successfullySaved).
Int("failed_count", failedToSave).
Int("unsupported_msg_type_count", unsupportedTypes).
Time("lowest_time", minTime).
Int("lowest_time_index", minTimeIndex).
@ -646,6 +653,7 @@ func (user *User) storeHistorySync(evt *waProto.HistorySync) {
}
log.Info().
Int("total_saved_count", successfullySavedTotal).
Int("total_failed_count", failedToSaveTotal).
Int("total_message_count", totalMessageCount).
Msg("Finished storing history sync")

View File

@ -1814,6 +1814,7 @@ func (portal *Portal) GetBasePowerLevels() *event.PowerLevelsEventContent {
InvitePtr: &invite,
Users: map[id.UserID]int{
portal.MainIntent().UserID: 100,
portal.bridge.Bot.UserID: 100,
},
Events: map[string]int{
event.StateRoomName.Type: anyone,
@ -1831,6 +1832,9 @@ func (portal *Portal) applyPowerLevelFixes(levels *event.PowerLevelsEventContent
changed = levels.EnsureEventLevel(event.EventReaction, 0) || changed
changed = levels.EnsureEventLevel(event.EventRedaction, 0) || changed
changed = levels.EnsureEventLevel(TypeMSC3381PollResponse, 0) || changed
if portal.IsPrivateChat() {
changed = levels.EnsureUserLevel(portal.bridge.Bot.UserID, 100) || changed
}
return changed
}