当前位置: 首页>>代码示例>>C#>>正文


C# Models.ChatMessage类代码示例

本文整理汇总了C#中JabbR.Models.ChatMessage的典型用法代码示例。如果您正苦于以下问题:C# ChatMessage类的具体用法?C# ChatMessage怎么用?C# ChatMessage使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


ChatMessage类属于JabbR.Models命名空间,在下文中一共展示了ChatMessage类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: MessageReadStateChanged

 public void MessageReadStateChanged(ChatUser mentionedUser, ChatMessage message, Notification notification)
 {
     foreach (var client in mentionedUser.ConnectedClients)
     {
         HubContext.Clients.Client(client.Id).messageReadStateChanged(message.Id, notification.Read);
     }
 }
开发者ID:Widdershin,项目名称:vox,代码行数:7,代码来源:ChatNotificationService.cs

示例2: NotifyMyAndroid

        private async void NotifyMyAndroid(ChatUser user, ChatMessage message)
        {
            var preferences = user.Preferences.PushNotifications.NMA;

            // Check preferences validity
            if (preferences == null || !preferences.Enabled || preferences.APIKey == null)
                return;

            var apikey = preferences.APIKey.Replace(" ", "");
            if (apikey.Length != 48)
                return;

            // Create event and description content values and add ellipsis if over limits

            var descriptionContent = message.Content;
            if (descriptionContent.Length > 10000)
                descriptionContent = descriptionContent.Substring(0, 10000 - 3) + "...";

            var request = new Dictionary<string, string>
            {
                {"apikey", apikey},
                {"application", "vox"},
                {"event", GetTitle(message, 100)},
                {"description", descriptionContent}
            };

            var result = await _httpClient.PostAsync("https://www.notifymyandroid.com/publicapi/notify", new FormUrlEncodedContent(request));

            _logger.Log("Send NotifyMyAndroid: {0}", result.StatusCode);
        }
开发者ID:Widdershin,项目名称:vox,代码行数:30,代码来源:PushNotificationService.cs

示例3: MessageViewModel

 public MessageViewModel(ChatMessage message)
 {
     Id = message.Id;
     Content = message.Content;
     User = new UserViewModel(message.User);
     When = message.When;
 }
开发者ID:shimazoe,项目名称:cchat2,代码行数:7,代码来源:MessageViewModel.cs

示例4: Add

 public void Add(ChatMessage message)
 {
     RoomCache roomCache;
     if (_cache.TryGetValue(message.Room.Name, out roomCache))
     {
         // Only cache if there's been a store created for this room already
         roomCache.Add(message);
     }
 }
开发者ID:BrianRosamilia,项目名称:JabbR,代码行数:9,代码来源:RecentMessageCache.cs

示例5: GetTitle

        private string GetTitle(ChatMessage message, int lengthLimit = 0)
        {
            var title = string.Format("Message from {0} in #{1}", message.User.Name, message.Room.Name);

            if (lengthLimit > 0 && title.Length > lengthLimit)
                title = title.Substring(0, lengthLimit - 3) + "...";

            return title;
        }
开发者ID:Widdershin,项目名称:vox,代码行数:9,代码来源:PushNotificationService.cs

示例6: MessageViewModel

 public MessageViewModel(ChatMessage message)
 {
     Id = message.Id;
     Content = message.Content;
     HtmlContent = message.HtmlContent;
     User = new UserViewModel(message.User);
     When = message.When;
     HtmlEncoded = message.HtmlEncoded;
     MessageType = message.MessageType;
     Source = message.Source;
     ImageUrl = message.ImageUrl;
 }
开发者ID:phillip-haydon,项目名称:JabbR,代码行数:12,代码来源:MessageViewModel.cs

示例7: MessageViewModel

 public MessageViewModel(ChatMessage message)
 {
     Id = message.Id;
     Content = message.Content;
     HtmlContent = message.HtmlContent;
     User = new UserViewModel(message.User);
     UserRoomPresence = ChatService.GetUserRoomPresence(message.User, message.Room);
     When = message.When;
     HtmlEncoded = message.HtmlEncoded;
     MessageType = message.MessageType;
     Source = message.Source;
     ImageUrl = message.ImageUrl;
 }
开发者ID:BrianRosamilia,项目名称:JabbR,代码行数:13,代码来源:MessageViewModel.cs

示例8: AddMessage

        public ChatMessage AddMessage(ChatUser user, ChatRoom room, string content)
        {
            var chatMessage = new ChatMessage
            {
                Id = Guid.NewGuid().ToString("d"),
                User = user,
                Content = content,
                When = DateTimeOffset.UtcNow,
                Room = room
            };

            _repository.Add(chatMessage);

            return chatMessage;
        }
开发者ID:skalinets,项目名称:JabbR,代码行数:15,代码来源:ChatService.cs

示例9: Send

        public void Send(ChatUser user, ChatMessage message)
        {
            if (user.Preferences == null || user.Preferences.PushNotifications == null)
                return;

            _logger.Log("Send user: {0}, message: {1}", user.Id, message.Id);

            try
            {
                NotifyMyAndroid(user, message);
                Pushover(user, message);
                Pushbullet(user, message);
            }
            catch (Exception ex)
            {
                _logger.Log("Send error: {0}", ex.ToString());
            }
        }
开发者ID:Widdershin,项目名称:vox,代码行数:18,代码来源:PushNotificationService.cs

示例10: Pushover

        private async void Pushover(ChatUser user, ChatMessage message)
        {
            if (_settings.PushoverAPIKey.IsNullOrWhiteSpace())
                return;

            // Check preferences validity
            var preferences = user.Preferences.PushNotifications.Pushover;

            if (preferences == null || !preferences.Enabled || preferences.UserKey.IsNullOrWhiteSpace())
                return;

            var request = new Dictionary<string, string>
            {
                {"token", _settings.PushoverAPIKey},
                {"user", preferences.UserKey},
                {"title", GetTitle(message)},
                {"message", message.Content}
            };

            if (!preferences.DeviceName.IsNullOrWhiteSpace())
                request["device"] = preferences.DeviceName;

            var result = await _httpClient.PostAsync("https://api.pushover.net/1/messages.json", new FormUrlEncodedContent(request));

            _logger.Log("Send Pushover: {0}", result.StatusCode);
        }
开发者ID:Widdershin,项目名称:vox,代码行数:26,代码来源:PushNotificationService.cs

示例11: PostNotification

        public void PostNotification(ClientNotification notification, bool executeContentProviders)
        {
            string userId = Context.User.GetUserId();

            ChatUser user = _repository.GetUserById(userId);
            ChatRoom room = _repository.VerifyUserRoom(_cache, user, notification.Room);

            // User must be an owner
            if (room == null ||
                !room.Owners.Contains(user) ||
                (room.Private && !user.AllowedRooms.Contains(room)))
            {
                throw new HubException(LanguageResources.PostNotification_NotAllowed);
            }

            var chatMessage = new ChatMessage
            {
                Id = Guid.NewGuid().ToString("d"),
                Content = notification.Content,
                User = user,
                Room = room,
                HtmlEncoded = false,
                ImageUrl = notification.ImageUrl,
                Source = notification.Source,
                When = DateTimeOffset.UtcNow,
                MessageType = (int)MessageType.Notification
            };

            _repository.Add(chatMessage);
            _repository.CommitChanges();

            Clients.Group(room.Name).addMessage(new MessageViewModel(chatMessage), room.Name);

            if (executeContentProviders)
            {
                var urls = UrlExtractor.ExtractUrls(chatMessage.Content);
                if (urls.Count > 0)
                {
                    _resourceProcessor.ProcessUrls(urls, Clients, room.Name, chatMessage.Id);
                }
            }
        }
开发者ID:renangrativol,项目名称:JabbR,代码行数:42,代码来源:Chat.cs

示例12: AddMentions

        private void AddMentions(ChatMessage message)
        {
            var mentionedUsers = new List<ChatUser>();
            foreach (var userName in MentionExtractor.ExtractMentions(message.Content))
            {
                ChatUser mentionedUser = _repository.GetUserByName(userName);

                // Don't create a mention if
                // 1. If the mentioned user doesn't exist.
                // 2. If you mention yourself
                // 3. If you're mentioned in a private room that you don't have access to
                // 4. You've already been mentioned in this message
                if (mentionedUser == null ||
                    mentionedUser == message.User ||
                    (message.Room.Private && !mentionedUser.AllowedRooms.Contains(message.Room)) ||
                    mentionedUsers.Contains(mentionedUser))
                {
                    continue;
                }

                // mark as read if ALL of the following
                // 1. user is not offline
                // 2. user is not AFK
                // 3. user has been active within the last 10 minutes
                // 4. user is currently in the room
                bool markAsRead = mentionedUser.Status != (int)UserStatus.Offline
                                  && !mentionedUser.IsAfk
                                  && (DateTimeOffset.UtcNow - mentionedUser.LastActivity) < TimeSpan.FromMinutes(10)
                                  && _repository.IsUserInRoom(_cache, mentionedUser, message.Room);

                _service.AddNotification(mentionedUser, message, message.Room, markAsRead);

                mentionedUsers.Add(mentionedUser);
            }

            if (mentionedUsers.Count > 0)
            {
                _repository.CommitChanges();
            }

            foreach (var user in mentionedUsers)
            {
                UpdateUnreadMentions(user);
            }
        }
开发者ID:renangrativol,项目名称:JabbR,代码行数:45,代码来源:Chat.cs

示例13: Update

        public void Update(ChatMessage message)
        {
            ChatMessage updateMessage = _db.Messages.Where(p => p.Id == message.Id).FirstOrDefault();

            if (updateMessage != null)
            {
                _db.Entry(updateMessage).CurrentValues.SetValues(message);
            }

            _db.SaveChanges();
        }
开发者ID:Widdershin,项目名称:vox,代码行数:11,代码来源:PersistedRepository.cs

示例14: GetNotificationByMessage

 public Notification GetNotificationByMessage(ChatMessage message, ChatUser user)
 {
     return _db.Notifications.SingleOrDefault(n => n.MessageKey == message.Key && n.UserKey == user.Key);
 }
开发者ID:Widdershin,项目名称:vox,代码行数:4,代码来源:PersistedRepository.cs

示例15: Update

        public void Update(ChatMessage message)
        {
            var room = _rooms.First(r => r == message.Room);
            var updateMessage = room.Messages.Where(p => p.Id == message.Id).FirstOrDefault();

            if (updateMessage != null)
            {
                room.Messages.Remove(updateMessage);
                room.Messages.Add(message);
            }
        }
开发者ID:Widdershin,项目名称:vox,代码行数:11,代码来源:InMemoryRepository.cs


注:本文中的JabbR.Models.ChatMessage类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。