Skip to content

Commit

Permalink
fix: cursor data and user status
Browse files Browse the repository at this point in the history
  • Loading branch information
a60814billy committed Jun 14, 2021
1 parent 729164e commit d9ba3d1
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 9 deletions.
15 changes: 8 additions & 7 deletions lib/realtime/realtime.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export interface RealtimeUserData {
'user-agent'?: string
photo?: string

cursor?: {line: number, ch: number}
cursor?: CursorData
login?: boolean
userid?: string
name?: string
Expand Down Expand Up @@ -65,7 +65,7 @@ export interface RealtimeNoteData {
socks: SocketIO.Socket[]
users: Record<string, RealtimeUserData>
//???
tempUsers: any
tempUsers: Record<string, number>

createtime: number
updatetime: number
Expand Down Expand Up @@ -497,7 +497,7 @@ export function emitRefresh(socket: SocketIO.Socket): void {
socket.emit('refresh', out)
}

export function checkViewPermission(req, note) {
export function checkViewPermission(req, note: RealtimeNoteData) {
if (note.permission === 'private') {
if (req.user && req.user.logged_in && req.user.id === note.owner) {
return true
Expand Down Expand Up @@ -644,8 +644,9 @@ interface RealtimeClientUserData {
color?: string
cursor?: CursorData
name?: string
idle?: boolean
type?: string

idle: boolean
type: 'xs' | 'sm' | 'md' | 'lg'
}

export function buildUserOutData(user: RealtimeUserData): RealtimeClientUserData {
Expand All @@ -664,7 +665,7 @@ export function buildUserOutData(user: RealtimeUserData): RealtimeClientUserData
}

// TODO: test it
export function updateUserData(socket: SocketIO.Socket, user): void {
export function updateUserData(socket: SocketIO.Socket, user: RealtimeUserData): void {
// retrieve user data from passport
if (socket.request.user && socket.request.user.logged_in) {
const profile = User.getProfile(socket.request.user)
Expand Down Expand Up @@ -756,7 +757,7 @@ function operationCallback(socket: SocketIO.Socket, operation: any) {
}

// TODO: test it
export function updateHistory(userId: string, note, time?: number): void {
export function updateHistory(userId: string, note: RealtimeNoteData, time?: number): void {
const noteId = note.alias ? note.alias : Note.encodeNoteId(note.id)
if (note.server) history.updateHistory(userId, noteId, note.server.document, time)
}
Expand Down
4 changes: 2 additions & 2 deletions lib/realtime/realtimeClientConnection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import {Note} from "../models";
import {logger} from "../logger";
import {RealtimeNoteData, RealtimeUserData} from "./realtime";

export type CursorData = Record<string, string>
export type CursorData = {line: number, ch: number}

export interface UserStatus {
type: string
idle: boolean
type: 'xs' | 'sm' | 'md' | 'lg'
}

export class RealtimeClientConnection {
Expand Down

0 comments on commit d9ba3d1

Please sign in to comment.