File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -652,17 +652,25 @@ function operationCallback(socket, operation) {
652652 if ( ! user ) return ;
653653 userId = socket . request . user . id ;
654654 if ( ! note . authors [ userId ] ) {
655- models . Author . create ( {
656- noteId : noteId ,
657- userId : userId ,
658- color : user . color
659- } ) . then ( function ( author ) {
660- note . authors [ author . userId ] = {
661- userid : author . userId ,
662- color : author . color ,
663- photo : user . photo ,
664- name : user . name
665- } ;
655+ models . Author . findOrCreate ( {
656+ where : {
657+ noteId : noteId ,
658+ userId : userId
659+ } ,
660+ defaults : {
661+ noteId : noteId ,
662+ userId : userId ,
663+ color : user . color
664+ }
665+ } ) . spread ( function ( author , created ) {
666+ if ( author ) {
667+ note . authors [ author . userId ] = {
668+ userid : author . userId ,
669+ color : author . color ,
670+ photo : user . photo ,
671+ name : user . name
672+ } ;
673+ }
666674 } ) . catch ( function ( err ) {
667675 return logger . error ( 'operation callback failed: ' + err ) ;
668676 } ) ;
You can’t perform that action at this time.
0 commit comments