mirror of
https://github.com/hedgedoc/hedgedoc.git
synced 2025-05-19 01:35:18 -04:00
Make authorships show up again
It turns out our shiny new typed ES2015 `Map`s are not serializable to JSON. :( Luckily, we only use strings as keys and can write a function that converts them to serializable objects! Signed-off-by: David Mehren <dmehren1@gmail.com>
This commit is contained in:
parent
17f3dc1877
commit
908bf36fa0
2 changed files with 13 additions and 2 deletions
|
@ -13,6 +13,7 @@ import { Author, Note, Revision, User } from './models'
|
||||||
import { NoteAuthorship } from './models/note'
|
import { NoteAuthorship } from './models/note'
|
||||||
import { PhotoProfile } from './models/user'
|
import { PhotoProfile } from './models/user'
|
||||||
import { EditorSocketIOServer } from './ot/editor-socketio-server'
|
import { EditorSocketIOServer } from './ot/editor-socketio-server'
|
||||||
|
import { mapToObject } from './utils'
|
||||||
|
|
||||||
export type SocketWithNoteId = Socket & { noteId: string }
|
export type SocketWithNoteId = Socket & { noteId: string }
|
||||||
|
|
||||||
|
@ -77,7 +78,7 @@ function emitCheck (note: NoteSession): void {
|
||||||
updatetime: note.updatetime,
|
updatetime: note.updatetime,
|
||||||
lastchangeuser: note.lastchangeuser,
|
lastchangeuser: note.lastchangeuser,
|
||||||
lastchangeuserprofile: note.lastchangeuserprofile,
|
lastchangeuserprofile: note.lastchangeuserprofile,
|
||||||
authors: note.authors,
|
authors: mapToObject(note.authors),
|
||||||
authorship: note.authorship
|
authorship: note.authorship
|
||||||
}
|
}
|
||||||
realtime.io.to(note.id).emit('check', out)
|
realtime.io.to(note.id).emit('check', out)
|
||||||
|
@ -380,7 +381,7 @@ function emitRefresh (socket: SocketWithNoteId): void {
|
||||||
ownerprofile: note.ownerprofile,
|
ownerprofile: note.ownerprofile,
|
||||||
lastchangeuser: note.lastchangeuser,
|
lastchangeuser: note.lastchangeuser,
|
||||||
lastchangeuserprofile: note.lastchangeuserprofile,
|
lastchangeuserprofile: note.lastchangeuserprofile,
|
||||||
authors: note.authors,
|
authors: mapToObject(note.authors),
|
||||||
authorship: note.authorship,
|
authorship: note.authorship,
|
||||||
permission: note.permission,
|
permission: note.permission,
|
||||||
createtime: note.createtime,
|
createtime: note.createtime,
|
||||||
|
|
|
@ -4,6 +4,16 @@ import { logger } from './logger'
|
||||||
import { Revision } from './models'
|
import { Revision } from './models'
|
||||||
import { realtime } from './realtime'
|
import { realtime } from './realtime'
|
||||||
|
|
||||||
|
/*
|
||||||
|
Converts a map from string to something into a plain JS object for transmitting via a websocket
|
||||||
|
*/
|
||||||
|
export function mapToObject<T> (map: Map<string, T>): object {
|
||||||
|
return Array.from(map).reduce((obj, [key, value]) => {
|
||||||
|
obj[key] = value
|
||||||
|
return obj
|
||||||
|
}, {})
|
||||||
|
}
|
||||||
|
|
||||||
export function getImageMimeType (imagePath: string): string | undefined {
|
export function getImageMimeType (imagePath: string): string | undefined {
|
||||||
const fileExtension = /[^.]+$/.exec(imagePath)
|
const fileExtension = /[^.]+$/.exec(imagePath)
|
||||||
switch (fileExtension?.[0]) {
|
switch (fileExtension?.[0]) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue