Skip to content

Commit

Permalink
add option to automatically delete chats on disconnect
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisballinger committed Apr 25, 2012
1 parent f0563fa commit a8b888b
Show file tree
Hide file tree
Showing 8 changed files with 57 additions and 27 deletions.
17 changes: 9 additions & 8 deletions Off the Record/OTRChatListViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,17 @@ - (void) xmppLoggedOff {
}

- (void) removeConversationsForProtocol:(NSString*)protocol {
NSMutableSet *activeConversations = [OTRProtocolManager sharedInstance].buddyList.activeConversations;
NSSet *iterableConversations = [activeConversations copy];


for (OTRBuddy *buddy in iterableConversations) {
if ([buddy.protocol isEqualToString:protocol]) {
[activeConversations removeObject:buddy];
if ([OTRSettingsManager boolForOTRSettingKey:kOTRSettingKeyDeleteOnDisconnect]) {
NSMutableSet *activeConversations = [OTRProtocolManager sharedInstance].buddyList.activeConversations;
NSSet *iterableConversations = [activeConversations copy];

for (OTRBuddy *buddy in iterableConversations) {
if ([buddy.protocol isEqualToString:protocol]) {
[activeConversations removeObject:buddy];
}
}
[chatListTableView reloadData];
}
[chatListTableView reloadData];
}


Expand Down
20 changes: 20 additions & 0 deletions Off the Record/OTRChatViewController.m
Original file line number Diff line number Diff line change
Expand Up @@ -283,6 +283,26 @@ - (void)viewDidLoad
//turn off scrolling and set the font details.
//chatBox.scrollEnabled = NO;
//chatBox.font = [UIFont fontWithName:@"Helvetica" size:14];
[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(showDisconnectionAlert:)
name:@"OscarLogoutNotification"
object:nil ];

[[NSNotificationCenter defaultCenter]
addObserver:self
selector:@selector(showDisconnectionAlert:)
name:@"XMPPLogoutNotification"
object:nil ];
}

- (void) showDisconnectionAlert:(NSNotification*)notification {
NSMutableString *message = [NSMutableString stringWithString:DISCONNECTED_MESSAGE_STRING];
if ([OTRSettingsManager boolForOTRSettingKey:kOTRSettingKeyDeleteOnDisconnect]) {
[message appendFormat:@" %@", DISCONNECTION_WARNING_STRING];
}
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:DISCONNECTED_TITLE_STRING message:message delegate:nil cancelButtonTitle:OK_STRING otherButtonTitles: nil];
[alert show];
}

- (void) refreshContext {
Expand Down
10 changes: 5 additions & 5 deletions Off the Record/OTRCodec.m
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ static OtrlPolicy policy_cb(void *opdata, ConnContext *context)
static const char *protocol_name_cb(void *opdata, const char *protocol)
{
//return "prpl-oscar";
NSLog(@"protocol: %s",protocol);
//NSLog(@"protocol: %s",protocol);
return protocol;
}

Expand Down Expand Up @@ -222,7 +222,7 @@ static void still_secure_cb(void *opdata, ConnContext *context, int is_reply)
static void log_message_cb(void *opdata, const char *message)
{
//purple_debug_info("otr", message);
NSLog(@"otr: %s",message);
//NSLog(@"otr: %s",message);

}

Expand Down Expand Up @@ -294,7 +294,7 @@ +(OTRMessage*) decodeMessage:(OTRMessage*)theMessage;


ignore_message = otrl_message_receiving(userstate, &ui_ops, NULL,[myAccountName UTF8String], [protocol UTF8String], [friendAccount UTF8String], [message UTF8String], &newmessage, NULL, NULL, NULL);
NSLog(@"ignore message: %d",ignore_message);
//NSLog(@"ignore message: %d",ignore_message);
NSString *newMessage;


Expand Down Expand Up @@ -331,14 +331,14 @@ +(OTRMessage*) encodeMessage:(OTRMessage*)theMessage;
NSString *recipientAccount = theMessage.recipient;
NSString *protocol = theMessage.protocol;
NSString *sendingAccount = theMessage.sender;
NSLog(@"inside encodeMessage: %@ %@ %@ %@",message,recipientAccount,protocol,sendingAccount);
//NSLog(@"inside encodeMessage: %@ %@ %@ %@",message,recipientAccount,protocol,sendingAccount);
OTRProtocolManager *protocolManager = [OTRProtocolManager sharedInstance];

err = otrl_message_sending(protocolManager.encryptionManager.userState, &ui_ops, NULL,
[sendingAccount UTF8String], [protocol UTF8String], [recipientAccount UTF8String], [message UTF8String], NULL, &newmessage,
NULL, NULL);
NSString *newMessage;
NSLog(@"newmessage char: %s",newmessage);
//NSLog(@"newmessage char: %s",newmessage);
if(newmessage)
newMessage = [NSString stringWithUTF8String:newmessage];
else
Expand Down
2 changes: 1 addition & 1 deletion Off the Record/OTRProtocolManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ -(void)sendMessage:(NSNotification *)notification
OTRMessage *message = [notification.userInfo objectForKey:@"message"];
NSString *protocol = message.protocol;

NSLog(@"send message (%@): %@", protocol, message.message);
//NSLog(@"send message (%@): %@", protocol, message.message);


if([protocol isEqualToString:@"xmpp"])
Expand Down
1 change: 1 addition & 0 deletions Off the Record/OTRSettingsManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#define kOTRSettingKeyAllowSSLHostNameMismatch @"kOTRSettingKeyAllowSSLHostNameMismatch"

#define kOTRSettingKeyFontSize @"kOTRSettingKeyFontSize"
#define kOTRSettingKeyDeleteOnDisconnect @"kOTRSettingKeyDeleteOnDisconnect"

@interface OTRSettingsManager : NSObject

Expand Down
5 changes: 4 additions & 1 deletion Off the Record/OTRSettingsManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,11 @@ - (void) populateSettings
fontSizeSetting.numValues = 4;
fontSizeSetting.defaultValue = 1.0;
fontSizeSetting.isPercentage = YES;
OTRSettingsGroup *chatSettingsGroup = [[OTRSettingsGroup alloc] initWithTitle:CHAT_STRING settings:[NSArray arrayWithObject:fontSizeSetting]];

[newSettingsDictionary setObject:fontSizeSetting forKey:kOTRSettingKeyFontSize];
OTRBoolSetting *deletedDisconnectedConversations = [[OTRBoolSetting alloc] initWithTitle:DELETE_CONVERSATIONS_ON_DISCONNECT_TITLE_STRING description:DELETE_CONVERSATIONS_ON_DISCONNECT_DESCRIPTION_STRING settingsKey:kOTRSettingKeyDeleteOnDisconnect];
[newSettingsDictionary setObject:deletedDisconnectedConversations forKey:kOTRSettingKeyDeleteOnDisconnect];
OTRSettingsGroup *chatSettingsGroup = [[OTRSettingsGroup alloc] initWithTitle:CHAT_STRING settings:[NSArray arrayWithObjects:fontSizeSetting, deletedDisconnectedConversations, nil]];
[settingsGroups addObject:chatSettingsGroup];


Expand Down
2 changes: 1 addition & 1 deletion Off the Record/OTRXMPPManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
#if DEBUG
static const int ddLogLevel = LOG_LEVEL_VERBOSE;
#else
static const int ddLogLevel = LOG_LEVEL_INFO;
static const int ddLogLevel = LOG_LEVEL_WARN;
#endif

@interface OTRXMPPManager()
Expand Down
27 changes: 16 additions & 11 deletions Off the Record/Strings.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,19 @@
#define CANCEL_STRING NSLocalizedString(@"Cancel", @"Cancel an alert window")
#define INITIATE_ENCRYPTED_CHAT_STRING NSLocalizedString(@"Initiate Encrypted Chat", @"Shown when starting an encrypted chat session")
#define VERIFY_STRING NSLocalizedString(@"Verify", @"Shown when verifying fingerprints")
#define SEND_STRING NSLocalizedString(@"Send", "For sending a message")
#define OK_STRING NSLocalizedString(@"OK", "Accept the dialog")
#define SEND_STRING NSLocalizedString(@"Send", @"For sending a message")
#define OK_STRING NSLocalizedString(@"OK", @"Accept the dialog")

// Used in OTRChatViewController
#define YOUR_FINGERPRINT_STRING NSLocalizedString(@"Fingerprint for you", @"your fingerprint")
#define THEIR_FINGERPRINT_STRING NSLocalizedString(@"Purported fingerprint for", "the alleged fingerprint of their other person")
#define THEIR_FINGERPRINT_STRING NSLocalizedString(@"Purported fingerprint for", @"the alleged fingerprint of their other person")
#define SECURE_CONVERSATION_STRING NSLocalizedString(@"You must be in a secure conversation first.", @"Inform user that they must be secure their conversation before doing that action")
#define VERIFY_FINGERPRINT_STRING NSLocalizedString(@"Verify Fingerprint", "Title of the dialog for fingerprint verification")
#define CHAT_INSTRUCTIONS_LABEL_STRING NSLocalizedString(@"Log in on the Accounts tab and then select a buddy from the Buddy List to start chatting.", @"Instructions on how to start using the program")
#define OPEN_IN_SAFARI_STRING NSLocalizedString(@"Open in Safari", "Shown when trying to open a link, asking if they want to switch to Safari to view it")
#define OPEN_IN_SAFARI_STRING NSLocalizedString(@"Open in Safari", @"Shown when trying to open a link, asking if they want to switch to Safari to view it")
#define DISCONNECTED_TITLE_STRING NSLocalizedString(@"Disconnected", @"Title of alert when user is disconnected from protocol")
#define DISCONNECTED_MESSAGE_STRING NSLocalizedString(@"You have disconnected.", @"Message shown when user is disconnected")
#define DISCONNECTION_WARNING_STRING NSLocalizedString(@"When you leave this conversation it will be deleted forever.", @"Warn user that conversation will be deleted after leaving it")

// OTRBuddyListViewController
#define IGNORE_STRING NSLocalizedString(@"Ignore", @"Ignore an incoming message")
Expand All @@ -36,8 +39,8 @@
#define ERROR_STRING NSLocalizedString(@"Error!", "Title of error message popup box")
#define OSCAR_FAIL_STRING NSLocalizedString(@"Failed to start authenticating. Please try again.", @"Authentication failed, tell user to try again")
#define XMPP_FAIL_STRING NSLocalizedString(@"Failed to connect to XMPP server. Please check your login credentials and internet connection and try again.", @"Message when cannot connect to XMPP server")
#define LOGGING_IN_STRING NSLocalizedString(@"Logging in...", "shown during the login proceess")
#define USER_PASS_BLANK_STRING NSLocalizedString(@"You must enter a username and a password to login.", "error message shown when user doesnt fill in a username or password")
#define LOGGING_IN_STRING NSLocalizedString(@"Logging in...", @"shown during the login proceess")
#define USER_PASS_BLANK_STRING NSLocalizedString(@"You must enter a username and a password to login.", @"error message shown when user doesnt fill in a username or password")

// OTRAccountsViewController
#define AIM_STRING NSLocalizedString(@"AOL Instant Messenger", "the name for AIM")
Expand All @@ -62,10 +65,11 @@
#define CRITTERCISM_TITLE_STRING NSLocalizedString(@"Send Crash Reports", @"Title for crash reports settings switch")
#define CRITTERCISM_DESCRIPTION_STRING NSLocalizedString(@"Automatically send anonymous crash logs (opt-in)", @"Description for crash reports settings switch")
#define OTHER_STRING NSLocalizedString(@"Other", @"Title for other miscellaneous settings group")
#define ALLOW_SELF_SIGNED_CERTIFICATES_STRING NSLocalizedString(@"Allow Self-Signed SSL", @"Title for settings cell on whether or not the XMPP library should allow self-signed SSL certificates")
#define ALLOW_SSL_HOSTNAME_MISMATCH_STRING NSLocalizedString(@"Allow SSL Hostname Mismatch", @"Title for settings cell on whether or not the XMPP library should allow SSL hostname mismatch")
#define SECURITY_WARNING_STRING NSLocalizedString(@"Warning: Use with caution. This may reduce your security.", @"Cell description text that warns users that enabling that option may reduce their security.")

#define ALLOW_SELF_SIGNED_CERTIFICATES_STRING NSLocalizedString(@"Self-Signed SSL", @"Title for settings cell on whether or not the XMPP library should allow self-signed SSL certificates")
#define ALLOW_SSL_HOSTNAME_MISMATCH_STRING NSLocalizedString(@"Hostname Mismatch", @"Title for settings cell on whether or not the XMPP library should allow SSL hostname mismatch")
#define SECURITY_WARNING_STRING NSLocalizedString(@"Warning: Use with caution! This may reduce your security.", @"Cell description text that warns users that enabling that option may reduce their security.")
#define DELETE_CONVERSATIONS_ON_DISCONNECT_TITLE_STRING NSLocalizedString(@"Auto-delete", @"Title for automatic conversation deletion setting")
#define DELETE_CONVERSATIONS_ON_DISCONNECT_DESCRIPTION_STRING NSLocalizedString(@"Delete chats on disconnect", @"Description for automatic conversation deletion")
#define FONT_SIZE_STRING NSLocalizedString(@"Font Size", @"Size for the font in the chat screen")
#define FONT_SIZE_DESCRIPTION_STRING NSLocalizedString(@"Size for font in chat view", @"description for what the font size setting affects")

Expand All @@ -76,4 +80,5 @@
#define SAVE_STRING NSLocalizedString(@"Save", "Title for button for saving a setting")
// OTRDoubleSettingViewController
#define NEW_STRING NSLocalizedString(@"New", "For a new settings value")
#define OLD_STRING NSLocalizedString(@"Old", "For an old settings value")
#define OLD_STRING NSLocalizedString(@"Old", "For an old settings value")

0 comments on commit a8b888b

Please sign in to comment.