public static void PublishChatMessages(this BahamutPubSubService service, ObjectId senderId, ShareChat chat, ChatMessage msg) { foreach (var user in chat.UserIds) { if (user != senderId) { var idstr = user.ToString(); var cacheModel = new BahamutCacheModel { AppUniqueId = Startup.Appname, CacheDateTime = DateTime.UtcNow, UniqueId = idstr, DeserializableString = msg.Id.ToString(), Type = ChatMessage.NotifyType, ExtraInfo = chat.Id.ToString() }; Startup.ServicesProvider.GetBahamutCacheService().PushCacheModelToList(cacheModel); var pbModel = new BahamutPublishModel { NotifyType = "Toronto", ToUser = idstr, CustomCmd = "UsrNewMsg", NotifyInfo = JsonConvert.SerializeObject(new { LocKey = "NEW_MSG_NOTIFICATION" }) }; Startup.ServicesProvider.GetBahamutPubSubService().PublishBahamutUserNotifyMessage(PublishConstants.NotifyId, pbModel); } } }
public async Task<object> Post(string message, string chatId, string type, string messageData, string time, string audienceId, string shareId) { var messageService = this.UseMessageService().GetMessageService(); var msg = new ChatMessage() { Message = message, MessageData = messageData, MessageType = type, SenderId = new ObjectId(UserSessionData.UserId), Time = DateTime.UtcNow, ChatId = chatId, ShareId = shareId }; var sendUserOId = new ObjectId(UserSessionData.UserId); var chat = await messageService.GetOrCreateChat(chatId, UserSessionData.UserId, shareId, audienceId); msg = await messageService.NewMessage(msg); Startup.ServicesProvider.GetBahamutPubSubService().PublishChatMessages(sendUserOId, chat, msg); return new { msgId = msg.Id.ToString() }; }
public async Task<ChatMessage> NewMessage(ChatMessage msg) { var collection = MessageCollection; await collection.InsertOneAsync(msg); return msg; }