diff options
author | Carlen White | 2023-01-19 23:41:54 -0500 |
---|---|---|
committer | Carlen White | 2023-01-19 23:41:54 -0500 |
commit | 954ff6ea8fc65bf40d10475dc144fe7d9a502493 (patch) | |
tree | 150db4d426a8f338f210e7884d6acd2942b7b5be /deadletter.patch | |
parent | bf89f52b80b8c42eb19536ab481cda59c4b2b412 (diff) | |
download | aur-954ff6ea8fc65bf40d10475dc144fe7d9a502493.tar.gz |
Patch to send unsent text in channels to file
Instead of unsent text being lost when there's a connection issue or closed for some other reason, a file is created and appended to in the log directory as `deadletter.log`
Exceptions are if the last tab is intentially closed, forcing F-Chat to immediately close.
Diffstat (limited to 'deadletter.patch')
-rw-r--r-- | deadletter.patch | 46 |
1 files changed, 46 insertions, 0 deletions
diff --git a/deadletter.patch b/deadletter.patch new file mode 100644 index 000000000000..7e19786e2802 --- /dev/null +++ b/deadletter.patch @@ -0,0 +1,46 @@ +diff --git a/chat/conversations.ts b/chat/conversations.ts +index 148ebc9..00220a2 100644 +--- a/chat/conversations.ts ++++ b/chat/conversations.ts +@@ -13,6 +13,8 @@ import throat from 'throat'; + import Bluebird from 'bluebird'; + import log from 'electron-log'; + import isChannel = Interfaces.isChannel; ++import path from 'path'; ++import fs from 'fs'; + + function createMessage(this: any, type: MessageType, sender: Character, text: string, time?: Date): Message { + if(type === MessageType.Message && isAction(text)) { +@@ -746,6 +748,32 @@ export default function(this: any): Interfaces.State { + state.selectedConversation.lastRead = state.selectedConversation.messages[state.selectedConversation.messages.length - 1]; + }); + const connection = core.connection; ++ connection.onEvent('closed', (_) => { ++ log.warn('Connection is closing. We are going to panic-save all channels containing unsent text.'); ++ let logLocation = core.state.generalSettings!.logDirectory; ++ fs.mkdirSync(logLocation, {recursive: true}); ++ ++ let collectedLogs: string[][] = []; ++ for (let channelConversation of state.channelConversations) { ++ let conversationName = channelConversation.channel.name; ++ let enteredText = channelConversation.enteredText; ++ if (enteredText != '') { ++ collectedLogs.push([conversationName, enteredText]); ++ } ++ } ++ if (collectedLogs.length > 0) { ++ let deadLetterPath = path.join(logLocation, 'deadletter.log'); ++ log.warn(`We found unsent messages. They will be written to \`${deadLetterPath}\``); ++ let deadLetterFile = fs.openSync(deadLetterPath, 'a'); ++ let now = new Date(); ++ fs.writeSync(deadLetterFile, `### ${now} ###\n`); ++ for (let [conversationName, enteredText] of collectedLogs) { ++ fs.writeSync(deadLetterFile, `=== ${conversationName} ===\n${enteredText}\n`); ++ } ++ fs.closeSync(deadLetterFile); ++ } ++ ++ }); + connection.onEvent('connecting', async(isReconnect) => { + state.channelConversations = []; + state.channelMap = {}; |