Skip to content
This repository has been archived by the owner on Jan 29, 2024. It is now read-only.

Commit

Permalink
Catching #176
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed May 23, 2022
1 parent 31e348d commit da36e2a
Showing 1 changed file with 66 additions and 38 deletions.
104 changes: 66 additions & 38 deletions Manager/Classes/ClientConnectionHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -709,54 +709,82 @@ private void OnMessageSend(XMPPClient xmppClient, MessageSendEventArgs args)

private void OnNewBookmarksResultMessage(XMPPClient xmppClient, NewBookmarksResultMessageEventArgs args)
{
foreach (ConferenceItem ci in args.BOOKMARKS_MESSAGE.STORAGE.CONFERENCES)
try
{
SemaLock semaLock = DataCache.INSTANCE.NewChatSemaLock();
ChatModel chat = DataCache.INSTANCE.GetChat(client.dbAccount.bareJid, ci.jid, semaLock);
bool newMuc = chat is null;
if (newMuc)
foreach (ConferenceItem ci in args.BOOKMARKS_MESSAGE.STORAGE.CONFERENCES)
{
chat = new ChatModel(ci.jid, client.dbAccount)
SemaLock semaLock = DataCache.INSTANCE.NewChatSemaLock();
ChatModel chat = null;
bool newMuc = false;
try
{
chatType = ChatType.MUC
};
chat.muc = new MucInfoModel(chat)
chat = DataCache.INSTANCE.GetChat(client.dbAccount.bareJid, ci.jid, semaLock);
newMuc = chat is null;
if (newMuc)
{
chat = new ChatModel(ci.jid, client.dbAccount)
{
chatType = ChatType.MUC
};
chat.muc = new MucInfoModel(chat)
{
state = MucState.DISCONNECTED
};
}
else
{
semaLock.Dispose();
}
}
catch (Exception e)
{
state = MucState.DISCONNECTED
};
}
else
{
semaLock.Dispose();
}
Logger.Error("Failed to parse bookmarks with:", e);
semaLock.Dispose();
return;
}

// Update chat:
chat.inRoster = true;
chat.presence = Presence.Unavailable;
chat.isChatActive = true;

// Update MUC info:
chat.muc.autoEnterRoom = ci.autoJoin;
chat.muc.name = ci.name;
chat.muc.nickname = ci.nick;
chat.muc.password = ci.password;
try
{
// Update chat:
chat.inRoster = true;
chat.presence = Presence.Unavailable;
chat.isChatActive = true;

// Update MUC info:
chat.muc.autoEnterRoom = ci.autoJoin;
chat.muc.name = ci.name;
chat.muc.nickname = ci.nick;
chat.muc.password = ci.password;

if (newMuc)
{
DataCache.INSTANCE.AddChatUnsafe(chat, client);
semaLock.Dispose();
}
else
{
chat.Update();
}

if (newMuc)
{
DataCache.INSTANCE.AddChatUnsafe(chat, client);
semaLock.Dispose();
}
else
{
chat.Update();
// Enter MUC manually if the MUC is new for this client:
if (newMuc && chat.muc.autoEnterRoom && !Settings.GetSettingBoolean(SettingsConsts.DISABLE_AUTO_JOIN_MUC))
{
Task.Run(() => MucHandler.INSTANCE.EnterMucAsync(xmppClient, chat.muc));
}
}
catch (Exception e)
{
Logger.Error("Failed to properly store bookmarks with:", e);
}
}

// Enter MUC manually if the MUC is new for this client:
if (newMuc && chat.muc.autoEnterRoom && !Settings.GetSettingBoolean(SettingsConsts.DISABLE_AUTO_JOIN_MUC))
{
Task.Run(() => MucHandler.INSTANCE.EnterMucAsync(xmppClient, chat.muc));
}
}
catch (Exception e)
{
Logger.Error("Something went wrong processing received bookmarks:", e);
}

}

private void OnNewDeliveryReceipt(XMPPClient xmppClient, NewDeliveryReceiptEventArgs args)
Expand Down

0 comments on commit da36e2a

Please sign in to comment.