mirror of
https://github.com/tulir/gomuks.git
synced 2025-04-20 10:33: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 = `
|
setRoomPrevBatchQuery = `
|
||||||
UPDATE room SET prev_batch = $2 WHERE room_id = $1
|
UPDATE room SET prev_batch = $2 WHERE room_id = $1
|
||||||
`
|
`
|
||||||
|
deleteRoomQuery = `
|
||||||
|
DELETE FROM room WHERE room_id = $1
|
||||||
|
`
|
||||||
updateRoomPreviewIfLaterOnTimelineQuery = `
|
updateRoomPreviewIfLaterOnTimelineQuery = `
|
||||||
UPDATE room
|
UPDATE room
|
||||||
SET preview_event_rowid = $2
|
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()...)
|
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 {
|
func (rq *RoomQuery) CreateRow(ctx context.Context, roomID id.RoomID) error {
|
||||||
return rq.Exec(ctx, ensureRoomExistsQuery, roomID)
|
return rq.Exec(ctx, ensureRoomExistsQuery, roomID)
|
||||||
}
|
}
|
||||||
|
|
|
@ -28,7 +28,8 @@ type SyncNotification struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
type SyncComplete struct {
|
type SyncComplete struct {
|
||||||
Rooms map[id.RoomID]*SyncRoom `json:"rooms"`
|
Rooms map[id.RoomID]*SyncRoom `json:"rooms"`
|
||||||
|
LeftRooms []id.RoomID `json:"left_rooms"`
|
||||||
}
|
}
|
||||||
|
|
||||||
func (c *SyncComplete) IsEmpty() bool {
|
func (c *SyncComplete) IsEmpty() bool {
|
||||||
|
|
|
@ -62,7 +62,8 @@ func (h *HiClient) GetInitialSync(ctx context.Context, batchSize int) iter.Seq[*
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
payload := SyncComplete{
|
payload := SyncComplete{
|
||||||
Rooms: make(map[id.RoomID]*SyncRoom, len(rooms)-1),
|
Rooms: make(map[id.RoomID]*SyncRoom, len(rooms)-1),
|
||||||
|
LeftRooms: make([]id.RoomID, 0),
|
||||||
}
|
}
|
||||||
for _, room := range rooms {
|
for _, room := range rooms {
|
||||||
if room.SortingTimestamp == rooms[len(rooms)-1].SortingTimestamp {
|
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 {
|
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 {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to get room data: %w", err)
|
return fmt.Errorf("failed to delete room: %w", err)
|
||||||
} else if existingRoomData == nil {
|
|
||||||
return nil
|
|
||||||
}
|
}
|
||||||
// TODO delete room
|
payload := ctx.Value(syncContextKey).(*syncContext).evt
|
||||||
|
payload.LeftRooms = append(payload.LeftRooms, roomID)
|
||||||
return nil
|
return nil
|
||||||
//return h.processStateAndTimeline(ctx, existingRoomData, &room.State, &room.Timeline, &room.Summary, nil, nil)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isDecryptionErrorRetryable(err error) bool {
|
func isDecryptionErrorRetryable(err error) bool {
|
||||||
|
|
|
@ -27,7 +27,10 @@ const (
|
||||||
|
|
||||||
func (h *hiSyncer) ProcessResponse(ctx context.Context, resp *mautrix.RespSync, since string) error {
|
func (h *hiSyncer) ProcessResponse(ctx context.Context, resp *mautrix.RespSync, since string) error {
|
||||||
c := (*HiClient)(h)
|
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)
|
err := c.preProcessSyncResponse(ctx, resp, since)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
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
|
let updatedRoomList: RoomListEntry[] | undefined
|
||||||
if (resyncRoomList) {
|
if (resyncRoomList) {
|
||||||
|
|
|
@ -80,6 +80,7 @@ export interface SyncNotification {
|
||||||
|
|
||||||
export interface SyncCompleteData {
|
export interface SyncCompleteData {
|
||||||
rooms: Record<RoomID, SyncRoom>
|
rooms: Record<RoomID, SyncRoom>
|
||||||
|
left_rooms: RoomID[]
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface SyncCompleteEvent extends RPCCommand<SyncCompleteData> {
|
export interface SyncCompleteEvent extends RPCCommand<SyncCompleteData> {
|
||||||
|
|
Loading…
Add table
Reference in a new issue