From 4b07e29417c415bc151755f120bd6ab98fb0d4f5 Mon Sep 17 00:00:00 2001
From: "Mr. Stallion" <mrstallion@nobody.nowhere.fauxdomain.ext>
Date: Sat, 3 Sep 2022 11:11:37 -0700
Subject: [PATCH] Force save settings at ad post

---
 chat/conversations.ts | 21 +++++++++++++++++++--
 chat/interfaces.ts    |  2 +-
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/chat/conversations.ts b/chat/conversations.ts
index 3e016bd..ad40e11 100644
--- a/chat/conversations.ts
+++ b/chat/conversations.ts
@@ -432,8 +432,18 @@ class ChannelConversation extends Conversation implements Interfaces.ChannelConv
                     createMessage(isAd ? MessageType.Ad : MessageType.Message, core.characters.ownCharacter, message, new Date())
                 );
 
-                if(isAd)
+                if(isAd) {
                     this.nextAd = Date.now() + core.connection.vars.lfrp_flood * 1000;
+
+                    // enforces property setter
+                    this.settings = {
+                        ...this.settings,
+                        adSettings: {
+                          ...this.settings.adSettings,
+                          lastAdTimestamp: Date.now()
+                      }
+                    };
+                }
           }
         );
     }
@@ -485,7 +495,14 @@ class ChannelConversation extends Conversation implements Interfaces.ChannelConv
 
                 this.nextAd = Date.now() + core.connection.vars.lfrp_flood * 1000;
 
-                this.settings.adSettings.lastAdTimestamp = Date.now();
+                // enforces property setter
+                this.settings = {
+                    ...this.settings,
+                    adSettings: {
+                      ...this.settings.adSettings,
+                      lastAdTimestamp: Date.now()
+                  }
+                };
             }
         );
     }
diff --git a/chat/interfaces.ts b/chat/interfaces.ts
index 7252d86..3685bfd 100644
--- a/chat/interfaces.ts
+++ b/chat/interfaces.ts
@@ -113,7 +113,7 @@ export namespace Conversation {
     export interface AdSettings {
         readonly ads: string[];
         readonly randomOrder: boolean;
-        lastAdTimestamp: number;
+        readonly lastAdTimestamp: number;
     }
 
     export const enum UnreadState { None, Unread, Mention }