public async Task SendChatMessage(ChatItem chatItem) { var msg = new Message(true, true) { Text = chatItem.ComposeMessage, Nickname = account?.Nickname ?? "Foo", IsSelf = true }; var toJid = new Matrix.Jid(chatItem.Contact.Jid); if (chatItem.Contact.MessageResource != null) { toJid.Resource = chatItem.Contact.MessageResource; } var xmppMsg = new MatrixMessage { Type = MatriXMessageType.Chat, To = toJid, Id = msg.Id, Body = chatItem.ComposeMessage }; await xmppClient.SendAsync(xmppMsg); chatItem.Messages.Add(msg); // clear the textbox chatItem.ComposeMessage = string.Empty; }
public async Task Connect(Account account) { try { this.account = account; var jid = new MatrixJid(account.XmppId); // set username, xmpp domain and password xmppClient.Username = jid.User; xmppClient.XmppDomain = jid.Server; xmppClient.Password = account.Password; xmppClient.Resource = account.Resource; //xmppClient.Priority = 10; if (!account.SpecifyHostnameAndPort) { xmppClient.HostnameResolver = new MatrixSrvResolver(); } else { xmppClient.HostnameResolver = new StaticNameResolver(account.Hostname, account.Port); } await SetConnectionStatus("Connecting..."); // Connect the XMPP session await xmppClient.ConnectAsync(); await SetConnectionStatus("Getting contacts..."); // request the contact list from the server await RequestRosterAsync(); await SetConnectionStatus("Setting presence..."); // send our presence to the server await presenceManager.SendPresenceAsync(); await ResetConnectionStatus(); } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); throw; } }