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

Commit

Permalink
General chat fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
COM8 committed Mar 17, 2021
1 parent 8bb2ca4 commit cac5bd1
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 5 deletions.
28 changes: 26 additions & 2 deletions Manager/Classes/Client.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Shared.Classes;
using System.ComponentModel;
using Shared.Classes;
using Storage.Classes;
using Storage.Classes.Models.Account;
using XMPP_API.Classes;
Expand Down Expand Up @@ -54,6 +55,7 @@ public Client(AccountModel dbAccount)
private XMPPClient LoadXmppClient(AccountModel account)
{
XMPPAccount xmppAccount = account.ToXMPPAccount();
xmppAccount.PropertyChanged += OnXmppAccountPropertyChanged;
Vault.LoadPassword(xmppAccount);
XMPPClient client = new XMPPClient(xmppAccount);
client.connection.TCP_CONNECTION.disableConnectionTimeout = Settings.GetSettingBoolean(SettingsConsts.DEBUG_DISABLE_TCP_TIMEOUT);
Expand Down Expand Up @@ -88,7 +90,29 @@ private void EnableOmemo(AccountModel account, XMPPClient client)
#endregion
//--------------------------------------------------------Events:---------------------------------------------------------------------\\
#region --Events--

private void OnXmppAccountPropertyChanged(object sender, PropertyChangedEventArgs e)
{
if (sender is XMPPAccount account)
{
switch (e.PropertyName)
{
case nameof(XMPPAccount.omemoDeviceId) when account.omemoDeviceId != dbAccount.omemoInfo.deviceId:
dbAccount.omemoInfo.deviceId = account.omemoDeviceId;
dbAccount.Update();
break;

case nameof(XMPPAccount.omemoBundleInfoAnnounced) when account.omemoBundleInfoAnnounced != dbAccount.omemoInfo.bundleInfoAnnounced:
dbAccount.omemoInfo.bundleInfoAnnounced = account.omemoBundleInfoAnnounced;
dbAccount.Update();
break;

case nameof(XMPPAccount.omemoDeviceLabel) when !string.Equals(account.omemoDeviceLabel, dbAccount.omemoInfo.deviceLabel):
dbAccount.omemoInfo.deviceLabel = account.omemoDeviceLabel;
dbAccount.Update();
break;
}
}
}

#endregion
}
Expand Down
2 changes: 1 addition & 1 deletion Manager/Classes/SpamHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public bool IsSpam(string msg)
if (spamMsg is null)
{
SPAM_SEMA.Wait();
if (spamRegex is null || !spamRegex.IsMatch(msg))
if (spamRegex is null || msg is null || !spamRegex.IsMatch(msg))
{
SPAM_SEMA.Release();
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ private void OnChatsCollectionChanged(object sender, NotifyCollectionChangedEven
break;

case NotifyCollectionChangedAction.Remove:
foreach (ChatDataTemplate chat in e.NewItems)
foreach (ChatDataTemplate chat in e.OldItems)
{
if (filter(chat))
{
Expand Down
2 changes: 1 addition & 1 deletion XMPP_API/Classes/Network/OmemoHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ private async Task updateDevicesIfNeededAsync(OmemoXmlDevices devicesRemote)
// Device id hasn't been set. Pick a random, unique one:
if (CONNECTION.account.omemoDeviceId == 0)
{
tmpDeviceId = Omemo.Classes.CryptoUtils.GenerateUniqueDeviceId(devicesRemote.DEVICES.Select(d => d.ID).ToList());
tmpDeviceId = CryptoUtils.GenerateUniqueDeviceId(devicesRemote.DEVICES.Select(d => d.ID).ToList());
devicesRemote.DEVICES.Add(new OmemoXmlDevice(tmpDeviceId, CONNECTION.account.omemoDeviceLabel));
updateDeviceList = true;
}
Expand Down
2 changes: 2 additions & 0 deletions XMPP_API/Classes/OmemoCommandHelper.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System;
using System.Threading.Tasks;
using Logging;
using XMPP_API.Classes.Network;
using XMPP_API.Classes.Network.XML.Messages;
using XMPP_API.Classes.Network.XML.Messages.Helper;
Expand Down Expand Up @@ -82,6 +83,7 @@ public async Task<MessageResponseHelperResult<IQMessage>> requestBundleInformati
/// <returns>The OmemoRequestDeviceListMessage result.</returns>
public async Task<MessageResponseHelperResult<IQMessage>> requestDeviceListAsync(string toBareJid)
{
Logger.Info($"Requesting OMEMO device list for {toBareJid} ...");
Predicate<IQMessage> predicate = (x) => { return x is OmemoDeviceListResultMessage || x is IQErrorMessage; };
AsyncMessageResponseHelper<IQMessage> helper = new AsyncMessageResponseHelper<IQMessage>(CONNECTION, predicate);
OmemoRequestDeviceListMessage msg = new OmemoRequestDeviceListMessage(CONNECTION.account.getFullJid(), toBareJid);
Expand Down

0 comments on commit cac5bd1

Please sign in to comment.