File tree Expand file tree Collapse file tree 1 file changed +16
-0
lines changed
Expand file tree Collapse file tree 1 file changed +16
-0
lines changed Original file line number Diff line number Diff line change @@ -3,6 +3,7 @@ import { Messages } from './collections/messages';
33import { MessageType , Profile } from './models' ;
44import { check , Match } from 'meteor/check' ;
55import { Users } from "./collections/users" ;
6+ import { fcmService } from "./services/fcm" ;
67
78const nonEmptyString = Match . Where ( ( str ) => {
89 check ( str , String ) ;
@@ -83,6 +84,21 @@ Meteor.methods({
8384 'Chat doesn\'t exist' ) ;
8485 }
8586
87+ const userId = this . userId ;
88+ const senderName = Users . collection . findOne ( { _id : userId } ) . profile . name ;
89+ const memberIds = Chats . collection . findOne ( { _id : chatId } ) . memberIds ;
90+ const tokens : string [ ] = Users . collection . find (
91+ {
92+ _id : { $in : memberIds , $nin : [ userId ] } ,
93+ fcmToken : { $exists : true }
94+ }
95+ ) . map ( ( el ) => el . fcmToken ) ;
96+
97+ for ( let token of tokens ) {
98+ console . log ( "Sending FCM notification" ) ;
99+ fcmService . sendNotification ( { "title" : `New message from ${ senderName } ` , "text" : content } , token ) ;
100+ }
101+
86102 return {
87103 messageId : Messages . collection . insert ( {
88104 chatId : chatId ,
You can’t perform that action at this time.
0 commit comments