mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-19 18:13:41 -05:00
hicli: delete room data on leave
This commit is contained in:
parent
9983a80eaa
commit
abc5327041
7 changed files with 25 additions and 9 deletions
|
@ -56,6 +56,9 @@ const (
|
|||
setRoomPrevBatchQuery = `
|
||||
UPDATE room SET prev_batch = $2 WHERE room_id = $1
|
||||
`
|
||||
deleteRoomQuery = `
|
||||
DELETE FROM room WHERE room_id = $1
|
||||
`
|
||||
updateRoomPreviewIfLaterOnTimelineQuery = `
|
||||
UPDATE room
|
||||
SET preview_event_rowid = $2
|
||||
|
@ -95,6 +98,10 @@ func (rq *RoomQuery) Upsert(ctx context.Context, room *Room) error {
|
|||
return rq.Exec(ctx, upsertRoomFromSyncQuery, room.sqlVariables()...)
|
||||
}
|
||||
|
||||
func (rq *RoomQuery) Delete(ctx context.Context, roomID id.RoomID) error {
|
||||
return rq.Exec(ctx, deleteRoomQuery, roomID)
|
||||
}
|
||||
|
||||
func (rq *RoomQuery) CreateRow(ctx context.Context, roomID id.RoomID) error {
|
||||
return rq.Exec(ctx, ensureRoomExistsQuery, roomID)
|
||||
}
|
||||
|
|
|
@ -29,6 +29,7 @@ type SyncNotification struct {
|
|||
|
||||
type SyncComplete struct {
|
||||
Rooms map[id.RoomID]*SyncRoom `json:"rooms"`
|
||||
LeftRooms []id.RoomID `json:"left_rooms"`
|
||||
}
|
||||
|
||||
func (c *SyncComplete) IsEmpty() bool {
|
||||
|
|
|
@ -63,6 +63,7 @@ func (h *HiClient) GetInitialSync(ctx context.Context, batchSize int) iter.Seq[*
|
|||
}
|
||||
payload := SyncComplete{
|
||||
Rooms: make(map[id.RoomID]*SyncRoom, len(rooms)-1),
|
||||
LeftRooms: make([]id.RoomID, 0),
|
||||
}
|
||||
for _, room := range rooms {
|
||||
if room.SortingTimestamp == rooms[len(rooms)-1].SortingTimestamp {
|
||||
|
|
|
@ -224,15 +224,14 @@ func (h *HiClient) processSyncJoinedRoom(ctx context.Context, roomID id.RoomID,
|
|||
}
|
||||
|
||||
func (h *HiClient) processSyncLeftRoom(ctx context.Context, roomID id.RoomID, room *mautrix.SyncLeftRoom) error {
|
||||
existingRoomData, err := h.DB.Room.Get(ctx, roomID)
|
||||
zerolog.Ctx(ctx).Debug().Stringer("room_id", roomID).Msg("Deleting left room")
|
||||
err := h.DB.Room.Delete(ctx, roomID)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to get room data: %w", err)
|
||||
} else if existingRoomData == nil {
|
||||
return nil
|
||||
return fmt.Errorf("failed to delete room: %w", err)
|
||||
}
|
||||
// TODO delete room
|
||||
payload := ctx.Value(syncContextKey).(*syncContext).evt
|
||||
payload.LeftRooms = append(payload.LeftRooms, roomID)
|
||||
return nil
|
||||
//return h.processStateAndTimeline(ctx, existingRoomData, &room.State, &room.Timeline, &room.Summary, nil, nil)
|
||||
}
|
||||
|
||||
func isDecryptionErrorRetryable(err error) bool {
|
||||
|
|
|
@ -27,7 +27,10 @@ const (
|
|||
|
||||
func (h *hiSyncer) ProcessResponse(ctx context.Context, resp *mautrix.RespSync, since string) error {
|
||||
c := (*HiClient)(h)
|
||||
ctx = context.WithValue(ctx, syncContextKey, &syncContext{evt: &SyncComplete{Rooms: make(map[id.RoomID]*SyncRoom, len(resp.Rooms.Join))}})
|
||||
ctx = context.WithValue(ctx, syncContextKey, &syncContext{evt: &SyncComplete{
|
||||
Rooms: make(map[id.RoomID]*SyncRoom, len(resp.Rooms.Join)),
|
||||
LeftRooms: make([]id.RoomID, 0, len(resp.Rooms.Leave)),
|
||||
}})
|
||||
err := c.preProcessSyncResponse(ctx, resp, since)
|
||||
if err != nil {
|
||||
return err
|
||||
|
|
|
@ -146,6 +146,10 @@ export class StateStore {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (const roomID of sync.left_rooms) {
|
||||
this.rooms.delete(roomID)
|
||||
changedRoomListEntries.set(roomID, null)
|
||||
}
|
||||
|
||||
let updatedRoomList: RoomListEntry[] | undefined
|
||||
if (resyncRoomList) {
|
||||
|
|
|
@ -80,6 +80,7 @@ export interface SyncNotification {
|
|||
|
||||
export interface SyncCompleteData {
|
||||
rooms: Record<RoomID, SyncRoom>
|
||||
left_rooms: RoomID[]
|
||||
}
|
||||
|
||||
export interface SyncCompleteEvent extends RPCCommand<SyncCompleteData> {
|
||||
|
|
Loading…
Add table
Reference in a new issue