• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

C# Models.ChatMessage类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: ProcessUrls

        private void ProcessUrls(IEnumerable<string> links, ChatRoom room, ChatMessage chatMessage)
        {
            // REVIEW: is this safe to do? We're holding on to this instance
            // when this should really be a fire and forget.
            var contentTasks = links.Select(_resourceProcessor.ExtractResource).ToArray();
            Task.Factory.ContinueWhenAll(contentTasks, tasks =>
            {
                foreach (var task in tasks)
                {
                    if (task.IsFaulted)
                    {
                        Trace.TraceError(task.Exception.GetBaseException().Message);
                        continue;
                    }

                    if (task.Result == null || String.IsNullOrEmpty(task.Result.Content))
                    {
                        continue;
                    }

                    // Try to get content from each url we're resolved in the query
                    string extractedContent = "<p>" + task.Result.Content + "</p>";

                    // If we did get something, update the message and notify all clients
                    chatMessage.Content += extractedContent;

                    // Notify the room
                    Clients[room.Name].addMessageContent(chatMessage.Id, extractedContent, room.Name);

                    // Commit the changes
                    _repository.CommitChanges();
                }
            });
        }
开发者ID:redsquare,项目名称:JabbR,代码行数:34,代码来源:Chat.cs


示例17: AddMessage

        public ChatMessage AddMessage(ChatUser user, ChatRoom room, string id, string content)
        {
            var chatMessage = new ChatMessage
            {
                Id = id,
                User = user,
                Content = content,
                When = DateTimeOffset.UtcNow,
                Room = room,
                HtmlEncoded = false
            };

            _recentMessageCache.Add(chatMessage);

            _repository.Add(chatMessage);

            return chatMessage;
        }
开发者ID:Virgil-Imbrea,项目名称:fixitnao,代码行数:18,代码来源:ChatService.cs


示例18: Add

 public void Add(ChatMessage message)
 {
     // There's no need to keep a collection of messages outside of a room
     var room = _rooms.First(r => r == message.Room);
     room.Messages.Add(message);
 }
开发者ID:QuinntyneBrown,项目名称:JabbR,代码行数:6,代码来源:InMemoryRepository.cs


示例19: AddMentions

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

                if (mentionedUser == null || mentionedUser == message.User)
                {
                    continue;
                }

                _service.AddNotification(mentionedUser, message);
            }
        }
开发者ID:Buildstarted,项目名称:JabbR,代码行数:14,代码来源:Chat.cs


示例20: Pushbullet

        private async void Pushbullet(ChatUser user, ChatMessage message)
        {
            // Check preferences validity
            var preferences = user.Preferences.PushNotifications.Pushbullet;

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

            // Get a list of all devices for user from pushbullet
            var devices = await PushbulletRequest(preferences.APIKey, "devices", HttpMethod.Get);

            if (devices.Item1.StatusCode != HttpStatusCode.OK)
            {
                _logger.Log("Pushbullet /api/devices request failed, StatusCode: {0}", devices.Item1.StatusCode);
                return;
            }

            var deviceIdentifiers = devices.Item2["devices"]
                .Select(d =>
                {
                    var name = d["extras"]["nickname"].Value<string>();

                    if (name.Length < 1)
                        name = d["extras"]["model"].Value<string>();

                    return new Tuple<string, string>(d["id"].Value<string>(), name);
                })
                .ToList();

            // Filter devices from stored names
            if (!preferences.Devices.IsNullOrWhiteSpace())
            {
                // Parse devices from input
                var names = PushbulletParseDevices(preferences.Devices).ToList();

                // Filter devices based on names
                deviceIdentifiers = deviceIdentifiers.Where(d => names.Contains(d.Item2)).ToList();
            }

            foreach (var device in deviceIdentifiers)
            {
                var request = new Dictionary<string, string>
                {
                    {"device_id", device.Item1},
                    {"type", "note"},
                    {"title", GetTitle(message)},
                    {"body", message.Content}
                };

                var result = await PushbulletRequest(preferences.APIKey, "pushes", HttpMethod.Post, request);

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



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Models.ChatRoom类代码示例发布时间:2022-05-26
下一篇:
C# Commands.CommandContext类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap