private void SendNotification(ChatObjMsg msg) { if (!enabled) { Notification notification = new Notification(_info, msg.Message, $"{msg.From}"); _hudAPI.ShowNotification(notification); } }
private void AddToQueue(ulong recipient, ChatObjMsg msg) { if (!_newMsgs.ContainsKey(recipient)) { _newMsgs[recipient] = new Queue <ChatObjMsg>(); } _newMsgs[recipient].Enqueue(msg); }
private byte[] SendMessage(ulong from, ulong to, string message, MsgContext ctx) { InitChat(from, to); ChatObj chat = _chats[from][to]; ChatObjMsg msg = new ChatObjMsg((ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), from, to, message); lock (chat) { chat.Messages.Add(msg); AddToQueue(to, msg); } return(null); }
public IMenuItem CreateMessageObj(ChatObjMsg msg) { int lines = (int)Math.Ceiling(msg.Message.Length / (float)CHARS_PER_LINE) + 1; MenuItemGrid item = new MenuItemGrid(msg.Time.ToString(), 1, lines); MenuItemText header = new MenuItemText("header"); item.AddChild(0, 0, 1, 1, header); header.SetTextStyle(FontStyle.Bold); header.SetFontSize(5, HEADER_FONT_SIZE); TextAnchor alignment; if (msg.From == _userId) { alignment = TextAnchor.MiddleRight; header.SetText("You"); } else { alignment = TextAnchor.MiddleLeft; header.SetText(_toUsername); } header.SetAlignment(alignment); string text = msg.Message; int i; string textPart; MenuItemText message; for (i = 0; i < lines - 2; ++i) { textPart = text.Substring(i * CHARS_PER_LINE, CHARS_PER_LINE); message = new MenuItemText($"message_line{i+1}"); message.SetFontSize(5, FONT_SIZE); message.SetText(textPart); message.SetAlignment(alignment); item.AddChild(0, i + 1, 1, 1, message); } textPart = text.Substring(i * CHARS_PER_LINE); message = new MenuItemText($"message_line{i + 1}"); message.SetFontSize(5, FONT_SIZE); message.SetText(textPart); message.SetAlignment(alignment); item.AddChild(0, i + 1, 1, 1, message); return(item); }
private void OnSendClicked() { if (_currChat == null) { return; } string msg = _msgInput.GetText(); _msgInput.SetText(""); if (msg.Trim() == "") { return; } ulong to = _currChat.User1 == _userId ? _currChat.User2 : _currChat.User1; MessageSend?.Invoke(to, msg); ChatObjMsg msgObj = new ChatObjMsg((ulong)DateTimeOffset.UtcNow.ToUnixTimeMilliseconds(), _userId, to, msg); _currChat.AddMessage(msgObj); _chatItem.AddChildBottom(CreateMessageObj(msgObj), CalculateHeight(msg)); }