slidingSync.ts (2505B)
1 import { IRoomEvent, IRoomStateEvent } from "./events"; 2 3 export interface ISlidingSyncReq { 4 txn_id?: string; 5 lists?: { 6 [key: string]: { 7 ranges?: number[][]; 8 slow_get_all_rooms?: boolean; 9 sort?: string[]; 10 required_state?: string[][]; 11 timeline_limit?: number; 12 filters?: { 13 [key: string]: any; 14 }; 15 }; 16 } 17 bump_event_types?: string[]; 18 extensions?: { 19 [key: string]: any; 20 }; 21 room_subscriptions?: { 22 [key: string]: { 23 sort?: string[]; 24 required_state?: string[][]; 25 timeline_limit?: number; 26 filters?: { 27 [key: string]: any; 28 }; 29 }; 30 }; 31 } 32 33 34 export interface ISlidingSyncResp { 35 lists?: { 36 [key: string]: List; 37 }; 38 rooms?: { 39 [key: string]: RoomJson; 40 }; 41 extensions?: Extensions; 42 pos: string; 43 txn_id: string; 44 } 45 46 export interface Extensions { 47 e2ee?: E2EEExtension; 48 to_device?: ToDeviceExtension; 49 } 50 51 export interface E2EEExtension { 52 device_one_time_keys_count?: { 53 [key: string]: number; 54 }; 55 device_lists?: { 56 changed?: string[]; 57 left?: string[]; 58 }; 59 device_unused_fallback_key_types?: string[]; 60 } 61 62 export interface ToDeviceExtension { 63 next_batch: string; 64 events?: any[]; 65 } 66 67 export interface List { 68 ops?: (SYNC_OP | INSERT_OP | INVALIDATE_OP | DELETE_OP)[]; 69 count: number; 70 } 71 72 export function isSyncOp(op: any): op is SYNC_OP { 73 return op.op === "SYNC"; 74 } 75 76 export function isInsertOp(op: any): op is INSERT_OP { 77 return op.op === "INSERT"; 78 } 79 80 export function isInvalidateOp(op: any): op is INVALIDATE_OP { 81 return op.op === "INVALIDATE"; 82 } 83 84 export function isDeleteOp(op: any): op is DELETE_OP { 85 return op.op === "DELETE"; 86 } 87 88 export interface DELETE_OP { 89 op: string; 90 index: number; 91 } 92 93 export interface INVALIDATE_OP { 94 op: string; 95 range: number[]; 96 } 97 98 export interface INSERT_OP { 99 op: string; 100 index: number; 101 room_id: string; 102 } 103 104 export interface SYNC_OP { 105 op: string; 106 range: number[]; 107 room_ids: string[]; 108 } 109 110 export interface RoomJson { 111 name?: string, 112 // List of events 113 timeline?: IRoomEvent[], 114 required_state?: IRoomStateEvent[], 115 notification_count: number, 116 highlight_count: number, 117 initial: boolean, 118 joined_count: number, 119 invited_count: number, 120 prev_batch: string, 121 is_dm?: boolean, 122 }