Skip to content
Permalink
Browse files

Added the new add MUC dialog

  • Loading branch information...
COM8 committed Jul 10, 2019
1 parent c24f105 commit dafbf33bc49ffa1b47d7b2f45740aba4156e9bed
@@ -59,14 +59,17 @@
<CheckBox Grid.Column="0"
Margin="0,10,0,0"
Content="Bookmark"
IsChecked="True"/>
IsChecked="{x:Bind VIEW_MODEL.MODEL.Bookmark, Mode=TwoWay}"/>
<CheckBox Grid.Column="1"
Margin="0,10,0,0"
Content="Auto join"
IsChecked="True"/>
IsChecked="{x:Bind VIEW_MODEL.MODEL.AutoJoin, Mode=TwoWay}"
Content="Auto join"/>
</Grid>
<controls:IconButtonControl Grid.Row="6"
Margin="0,10,0,0"
IsEnabled="False"
x:Name="browse_ibtn"
Click="Browse_ibtn_Click"
HorizontalAlignment="Left"
Glyph="&#xE721;"
Text="Browse"/>
@@ -66,6 +66,12 @@ private void AccountSelectionControl_AccountSelectionChanged(AccountSelectionCon
VIEW_MODEL.MODEL.Client = args.CLIENT;
}

private void Browse_ibtn_Click(IconButtonControl sender, Windows.UI.Xaml.RoutedEventArgs args)
{
VIEW_MODEL.OnCancel();
Hide();
}

#endregion
}
}
@@ -1,5 +1,4 @@
using Data_Manager2.Classes;
using UWP_XMPP_Client.Dialogs;
using UWP_XMPP_Client.Pages;
using UWPX_UI.Dialogs;
using UWPX_UI.Pages.Settings;
@@ -62,17 +61,16 @@ private async void AddChat_mfoi_Click(object sender, RoutedEventArgs e)
await VIEW_MODEL.OnAddChatAsync(dialog.VIEW_MODEL.MODEL);
}

private async void AddMix_mfoi_Click(object sender, RoutedEventArgs e)
private void AddMix_mfoi_Click(object sender, RoutedEventArgs e)
{
// TODO: Add MIX support.
AddMucDialog dialog = new AddMucDialog();
await UiUtils.ShowDialogAsync(dialog);
}

private async void AddMuc_mfoi_Click(object sender, RoutedEventArgs e)
{
AddMUCDialog dialog = new AddMUCDialog();
AddMucDialog dialog = new AddMucDialog();
await UiUtils.ShowDialogAsync(dialog);
await VIEW_MODEL.OnAddMucAsync(dialog.VIEW_MODEL.MODEL);
}

private void Settings_abb_Click(object sender, RoutedEventArgs e)
@@ -1,12 +1,17 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Data_Manager2.Classes;
using Data_Manager2.Classes.DBManager;
using Data_Manager2.Classes.DBTables;
using Data_Manager2.Classes.Toast;
using Logging;
using UWPX_UI_Context.Classes.DataTemplates.Dialogs;
using UWPX_UI_Context.Classes.DataTemplates.Pages;
using XMPP_API.Classes;
using XMPP_API.Classes.Network.XML.Messages;
using XMPP_API.Classes.Network.XML.Messages.Helper;
using XMPP_API.Classes.Network.XML.Messages.XEP_0048;

namespace UWPX_UI_Context.Classes.DataContext.Pages
{
@@ -37,6 +42,14 @@ public async Task OnAddChatAsync(AddChatDialogDataTemplate dataTemplate)
}
}

public async Task OnAddMucAsync(AddMucDialogDataTemplate dataTemplate)
{
if (dataTemplate.Confirmed)
{
await AddMucAsync(dataTemplate.Client, dataTemplate.RoomBareJid, dataTemplate.Nickname, dataTemplate.Password, dataTemplate.Bookmark, dataTemplate.AutoJoin);
}
}

public void OnNavigatedTo(object parameter)
{
// Subscribe to toast events:
@@ -55,6 +68,52 @@ public void OnNavigatedFrom()
#endregion

#region --Misc Methods (Private)--
private async Task AddMucAsync(XMPPClient client, string roomBareJid, string nickname, string password, bool bookmark, bool autoJoin)
{
ChatTable muc = new ChatTable(roomBareJid, client.getXMPPAccount().getBareJid())
{
chatType = ChatType.MUC,
inRoster = bookmark,
subscription = "none",
isChatActive = true
};
ChatDBManager.INSTANCE.setChat(muc, false, true);

MUCChatInfoTable info = new MUCChatInfoTable()
{
chatId = muc.id,
subject = null,
state = MUCState.DISCONNECTED,
name = null,
password = string.IsNullOrEmpty(password) ? null : password,
nickname = nickname,
autoEnterRoom = autoJoin,
};
MUCDBManager.INSTANCE.setMUCChatInfo(info, false, true);

if (info.autoEnterRoom)
{
Task t = MUCHandler.INSTANCE.enterMUCAsync(client, muc, info);
}

if (bookmark)
{
List<ConferenceItem> conferenceItems = MUCDBManager.INSTANCE.getXEP0048ConferenceItemsForAccount(client.getXMPPAccount().getBareJid());
MessageResponseHelperResult<IQMessage> result = await client.PUB_SUB_COMMAND_HELPER.setBookmars_xep_0048Async(conferenceItems);
if (result.STATE == MessageResponseHelperResultState.SUCCESS)
{
if (result.RESULT is IQErrorMessage errMsg)
{
Logger.Warn("Failed to set bookmarks: " + errMsg.ToString());
}
}
else
{
Logger.Warn("Failed to set bookmarks: " + result.STATE);
}
}
}

/// <summary>
/// Adds and starts a new chat.
/// </summary>
@@ -63,10 +63,28 @@ public XMPPClient Client
set => SetClientProperty(value);
}

private bool _Bookmark;
public bool Bookmark
{
get => _Bookmark;
set => SetProperty(ref _Bookmark, value);
}

private bool _AutoJoin;
public bool AutoJoin
{
get => _AutoJoin;
set => SetProperty(ref _AutoJoin, value);
}

#endregion
//--------------------------------------------------------Constructor:----------------------------------------------------------------\\
#region --Constructors--

public AddMucDialogDataTemplate()
{
AutoJoin = true;
Bookmark = true;
}

#endregion
//--------------------------------------------------------Set-, Get- Methods:---------------------------------------------------------\\
@@ -71,6 +71,20 @@ public MessageResponseHelper<IQMessage> setBookmars_xep_0048(IList<Network.XML.M
return helper;
}

/// <summary>
/// Sends a SetBookmarksMessage to set bookmarks on the server.
/// https://xmpp.org/extensions/xep-0048.html#storage-pubsub-upload
/// </summary>
/// <param name="conferences">A list of XEP-0048 <seealso cref="Network.XML.Messages.XEP_0048.ConferenceItem"/> objects that should be set.</param>
/// <returns>The XEP-0048 SetBookmarksMessage result.</returns>
public async Task<MessageResponseHelperResult<IQMessage>> setBookmars_xep_0048Async(IList<Network.XML.Messages.XEP_0048.ConferenceItem> conferences)
{
Predicate<IQMessage> predicate = (x) => { return true; };
AsyncMessageResponseHelper<IQMessage> helper = new AsyncMessageResponseHelper<IQMessage>(CONNECTION, predicate);
Network.XML.Messages.XEP_0048.SetBookmarksMessage msg = new Network.XML.Messages.XEP_0048.SetBookmarksMessage(CONNECTION.account.getFullJid(), conferences);
return await helper.startAsync(msg);
}

/// <summary>
/// Sends a RequestBookmarksMessage to request all bookmarks from the server.
/// https://xmpp.org/extensions/xep-0402.html#retrieving-bookmarks

0 comments on commit dafbf33

Please sign in to comment.
You can’t perform that action at this time.