Skip to content

Commit

Permalink
Get account directly from MLContact
Browse files Browse the repository at this point in the history
  • Loading branch information
matthewrfennell authored and tmolitor-stud-tu committed Aug 6, 2024
1 parent cdde23c commit f005b29
Show file tree
Hide file tree
Showing 13 changed files with 28 additions and 28 deletions.
2 changes: 1 addition & 1 deletion Monal/Classes/ChannelMemberList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ struct ChannelMemberList: View {
@State private var participants: OrderedDictionary<String, String>

init(mucContact: ObservableKVOWrapper<MLContact>) {
account = MLXMPPManager.sharedInstance().getConnectedAccount(forID: mucContact.accountId)! as xmpp
account = mucContact.obj.account! as xmpp
_channel = StateObject(wrappedValue:mucContact)
_ownAffiliation = State(wrappedValue:"none")
_participants = State(wrappedValue:OrderedDictionary<String, String>())
Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/ContactDetails.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ struct ContactDetails: View {
init(delegate: SheetDismisserProtocol, contact: ObservableKVOWrapper<MLContact>) {
self.delegate = delegate
_contact = StateObject(wrappedValue: contact)
self.account = MLXMPPManager.sharedInstance().getConnectedAccount(forID: contact.accountId)!
self.account = contact.obj.account!
}

private func updateRoleAndAffiliation() {
Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/EditGroupSubject.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ struct EditGroupSubject: View {

_subject = State(wrappedValue: contact.obj.groupSubject)
_contact = StateObject(wrappedValue: contact)
self.account = MLXMPPManager.sharedInstance().getConnectedAccount(forID: contact.accountId)! as xmpp
self.account = contact.obj.account! as xmpp
}

var body: some View {
Expand Down
6 changes: 3 additions & 3 deletions Monal/Classes/MLCall.m
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ +(NSSet*) keyPathsForValuesAffectingState
-(xmpp*) account
{
@synchronized(self) {
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.contact.accountId];
xmpp* account = self.contact.account;
MLAssert(account != nil, @"Account of call must be listed in MLXMPPManager connected accounts!", (@{
@"contact": nilWrapper(self.contact),
@"call": nilWrapper(self),
Expand Down Expand Up @@ -1274,7 +1274,7 @@ -(void) processIncomingICECandidate:(NSNotification*) notification
if(account != [[MLXMPPManager sharedInstance] getConnectedAccountForID:account.accountNo])
return;
//don't use self.account because that asserts on nil
if([[MLXMPPManager sharedInstance] getConnectedAccountForID:self.contact.accountId] == nil)
if(self.contact.account == nil)
return;

XMPPIQ* iqNode = userInfo[@"iqNode"];
Expand Down Expand Up @@ -1413,7 +1413,7 @@ -(void) processIncomingSDP:(NSNotification*) notification
if(account != [[MLXMPPManager sharedInstance] getConnectedAccountForID:account.accountNo])
return;
//don't use self.account because that asserts on nil
if([[MLXMPPManager sharedInstance] getConnectedAccountForID:self.contact.accountId] == nil)
if(self.contact.account == nil)
return;
XMPPIQ* iqNode = userInfo[@"iqNode"];

Expand Down
14 changes: 7 additions & 7 deletions Monal/Classes/MLContact.m
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ -(NSString*) contactDisplayNameWithFallback:(NSString* _Nullable) fallbackName a
}
else
{
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.accountId];
xmpp* account = self.account;
if(hasSelfnotesPrefix)
{
//add "Note to self: " prefix for selfchats
Expand Down Expand Up @@ -436,7 +436,7 @@ -(void) setNickNameView:(NSString*) name
_cancelNickChange();
// delay changes because we don't want to update the roster on our server too often while typing
_cancelNickChange = createTimer(2.0, (^{
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.accountId];
xmpp* account = self.account;
[account updateRosterItem:self withName:self.nickName];
}));
}
Expand All @@ -457,7 +457,7 @@ -(void) setFullNameView:(NSString*) name
if([self.fullName isEqualToString:name] || name == nil)
return; //no change at all
self.fullName = name;
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.accountId];
xmpp* account = self.account;
[[DataLayer sharedInstance] setFullName:self.fullName forContact:self.contactJid andAccount:account.accountNo];
// abort old change timer and start a new one
if(_cancelFullNameChange)
Expand Down Expand Up @@ -498,7 +498,7 @@ -(BOOL) hasAvatar

-(BOOL) isSelfChat
{
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.accountId];
xmpp* account = self.account;
return [self.contactJid isEqualToString:account.connectionProperties.identity.jid];
}

Expand Down Expand Up @@ -625,7 +625,7 @@ -(BOOL) toggleEncryption:(BOOL) encrypt
#ifdef DISABLE_OMEMO
return NO;
#else
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.accountId];
xmpp* account = self.account;
if(account == nil || account.omemo == nil)
return NO;
if(self.isGroup == NO)
Expand Down Expand Up @@ -664,7 +664,7 @@ -(void) togglePinnedChat:(BOOL) pinned
[[DataLayer sharedInstance] unPinChat:self.accountId andBuddyJid:self.contactJid];
self.isPinned = pinned;
// update active chats
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.accountId];
xmpp* account = self.account;
if(account == nil)
return;
[[MLNotificationQueue currentQueue] postNotificationName:kMonalContactRefresh object:account userInfo:@{@"contact":self, @"pinningChanged": @YES}];
Expand All @@ -674,7 +674,7 @@ -(BOOL) toggleBlocked:(BOOL) block
{
if(self.isBlocked == block)
return YES;
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.accountId];
xmpp* account = self.account;
if(account == nil)
return NO;
if(![account.connectionProperties.serverDiscoFeatures containsObject:@"urn:xmpp:blocking"])
Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/MLImageManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ -(UIImage*) generateDummyIconForContact:(MLContact*) contact

if(contact.isSelfChat)
{
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;
contactLetter = [[[MLContact ownDisplayNameForAccount:account] substringToIndex:1] uppercaseString];
}
else
Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/MLVoIPProcessor.m
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ -(MLCall* _Nullable) getCallForJmiid:(NSString*) jmiid

-(MLCall*) initiateCallWithType:(MLCallType) callType toContact:(MLContact*) contact
{
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;
MLAssert(account != nil, @"account is nil in initiateCallWithType:ToContact:!", (@{@"contact": contact}));

NSUUID* uuid = [NSUUID UUID];
Expand Down
14 changes: 7 additions & 7 deletions Monal/Classes/MLXMPPManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ -(NSString*) getPasswordForAccount:(NSNumber*) accountNo
-(void) sendMessageAndAddToHistory:(NSString*) message havingType:(NSString*) messageType toContact:(MLContact*) contact isEncrypted:(BOOL) encrypted uploadInfo:(NSDictionary* _Nullable) uploadInfo withCompletionHandler:(void (^ _Nullable)(BOOL success, NSString* messageId)) completion
{
NSString* msgid = [[NSUUID UUID] UUIDString];
xmpp* account = [self getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;

MLAssert(message != nil, @"Message should not be nil");
MLAssert(account != nil, @"Account should not be nil");
Expand Down Expand Up @@ -689,7 +689,7 @@ -(void) sendMessageAndAddToHistory:(NSString*) message havingType:(NSString*) me
-(void) sendMessage:(NSString*) message toContact:(MLContact*) contact isEncrypted:(BOOL) encrypted isUpload:(BOOL) isUpload messageId:(NSString*) messageId withCompletionHandler:(void (^ _Nullable)(BOOL success, NSString* messageId)) completion
{
BOOL success = NO;
xmpp* account = [self getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;
if(account)
{
success = YES;
Expand All @@ -701,7 +701,7 @@ -(void) sendMessage:(NSString*) message toContact:(MLContact*) contact isEncrypt

-(void) sendChatState:(BOOL) isTyping toContact:(MLContact*) contact
{
xmpp* account = [self getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;
if(account)
[account sendChatState:isTyping toContact:contact];
}
Expand Down Expand Up @@ -796,7 +796,7 @@ -(NSString*) getAccountNameForConnectedRow:(NSUInteger) row
$$
-(void) removeContact:(MLContact*) contact
{
xmpp* account = [self getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;
if(account)
{
//queue remove contact for execution once bound (e.g. on catchup done)
Expand Down Expand Up @@ -833,7 +833,7 @@ -(void) addContact:(MLContact*) contact
$$
-(void) addContact:(MLContact*) contact withPreauthToken:(NSString* _Nullable) preauthToken
{
xmpp* account = [self getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;
if(account)
{
//queue add contact for execution once bound (e.g. on catchup done)
Expand Down Expand Up @@ -864,7 +864,7 @@ -(void) addContact:(MLContact*) contact withPreauthToken:(NSString* _Nullable) p

-(void) getEntitySoftWareVersionForContact:(MLContact*) contact andResource:(NSString*) resource
{
xmpp* account = [self getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;

NSString* xmppId = @"";
if ((resource == nil) || ([resource length] == 0)) {
Expand All @@ -879,7 +879,7 @@ -(void) getEntitySoftWareVersionForContact:(MLContact*) contact andResource:(NSS
-(void) block:(BOOL) isBlocked contact:(MLContact*) contact
{
DDLogVerbose(@"Blocking %@: %@", contact, bool2str(isBlocked));
xmpp* account = [self getConnectedAccountForID:contact.accountId];
xmpp* account = contact.account;
[account setBlocked:isBlocked forJid:contact.contactJid];
}

Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/MemberList.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct MemberList: View {
@StateObject private var overlay = LoadingOverlayState()

init(mucContact: ObservableKVOWrapper<MLContact>) {
account = MLXMPPManager.sharedInstance().getConnectedAccount(forID: mucContact.accountId)! as xmpp
account = mucContact.obj.account! as xmpp
_muc = StateObject(wrappedValue:mucContact)
_ownAffiliation = State(wrappedValue:"none")
_memberList = State(wrappedValue:OrderedSet<ObservableKVOWrapper<MLContact>>())
Expand Down
4 changes: 2 additions & 2 deletions Monal/Classes/MonalAppDelegate.m
Original file line number Diff line number Diff line change
Expand Up @@ -879,7 +879,7 @@ -(void) userNotificationCenter:(UNUserNotificationCenter*) center didReceiveNoti
MLAssert(fromContact, @"fromContact should not be nil");
NSString* messageId = response.notification.request.content.userInfo[@"messageId"];
MLAssert(messageId, @"messageId should not be nil");
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:fromContact.accountId];
xmpp* account = fromContact.account;
//this can happen if that account got disabled
if(account == nil)
{
Expand Down Expand Up @@ -954,7 +954,7 @@ -(void) userNotificationCenter:(UNUserNotificationCenter*) center didReceiveNoti
DDLogVerbose(@"notification action '%@' triggered for %@", response.actionIdentifier, response.notification.request.content.userInfo);
MLContact* fromContact = [MLContact createContactFromJid:response.notification.request.content.userInfo[@"fromContactJid"] andAccountNo:response.notification.request.content.userInfo[@"fromContactAccountId"]];
MLAssert(fromContact, @"fromContact should not be nil");
xmpp* account = [[MLXMPPManager sharedInstance] getConnectedAccountForID:fromContact.accountId];
xmpp* account = fromContact.account;
//this can happen if that account got disabled
if(account == nil)
{
Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/OmemoKeys.swift
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ struct OmemoKeys: View {
self.viewContact = contact

if let contact = contact {
if let account = MLXMPPManager.sharedInstance().getConnectedAccount(forID: contact.accountId) {
if let account = contact.obj.account {
self.account = account
}
}
Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/OmemoQrCodeView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ struct OmemoQrCodeView: View {
init(contact: ObservableKVOWrapper<MLContact>)
{
self.jid = contact.obj.contactJid
if let account = MLXMPPManager.sharedInstance().getConnectedAccount(forID: contact.obj.accountId) {
if let account = contact.obj.account {
let devices = Array(account.omemo.knownDevices(forAddressName: self.jid))
var keyList = ""
var prefix = "?"
Expand Down
2 changes: 1 addition & 1 deletion Monal/Classes/chatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -803,7 +803,7 @@ -(void) viewWillAppear:(BOOL)animated
self.viewIsScrolling = YES;
//stop editing (if there is some)
[self stopEditing];
self.xmppAccount = [[MLXMPPManager sharedInstance] getConnectedAccountForID:self.contact.accountId];
self.xmppAccount = self.contact.account;
if(!self.xmppAccount) DDLogDebug(@"Disabled account detected");

[MLNotificationManager sharedInstance].currentContact = self.contact;
Expand Down

0 comments on commit f005b29

Please sign in to comment.