Add a functionality to save/restore open IMs from previous session

Suggested by Luke Rowley; Improvements welcomed
master
PanteraPolnocy 2025-09-04 12:55:44 +02:00
parent 60539d373c
commit dc0d75039b
6 changed files with 167 additions and 0 deletions

View File

@ -23992,6 +23992,17 @@ Change of this parameter will affect the layout of buttons in notification toast
<key>Value</key>
<integer>0</integer>
</map>
<key>FSRestoreOpenIMs</key>
<map>
<key>Comment</key>
<string>Restore open IM windows from the previous session on startup.</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>Boolean</string>
<key>Value</key>
<integer>1</integer>
</map>
<key>FSUseBuiltInHistory</key>
<map>
<key>Comment</key>

View File

@ -876,6 +876,18 @@
<key>Value</key>
<integer>0</integer>
</map>
<key>FSLastOpenIMs</key>
<map>
<key>Comment</key>
<string>List of IM session IDs that were open when the viewer was last closed</string>
<key>Persist</key>
<integer>1</integer>
<key>Type</key>
<string>LLSD</string>
<key>Value</key>
<array>
</array>
</map>
<key>FSKeywordCaseSensitive</key>
<map>
<key>Comment</key>

View File

@ -42,6 +42,11 @@
#include "llurlregistry.h"
#include "llvoiceclient.h"
// <FS:PP> Restore open IMs from previous session
#include "llconversationlog.h"
#include "llimview.h"
// </FS:PP>
constexpr F32 VOICE_STATUS_UPDATE_INTERVAL = 1.0f;
//
@ -162,6 +167,7 @@ void FSFloaterIMContainer::onOpen(const LLSD& key)
{
LLMultiFloater::onOpen(key);
initTabs();
restoreOpenIMs(); // <FS:PP> Restore open IMs from previous session
LLFloater* active_floater = getActiveFloater();
if (active_floater && !active_floater->hasFocus())
{
@ -173,6 +179,7 @@ void FSFloaterIMContainer::onClose(bool app_quitting)
{
if (app_quitting)
{
saveOpenIMs(); // <FS:PP> Save open IM sessions before closing
for (S32 i = 0; i < mTabContainer->getTabCount(); ++i)
{
FSFloaterIM* floater = dynamic_cast<FSFloaterIM*>(mTabContainer->getPanelByIndex(i));
@ -616,4 +623,125 @@ void FSFloaterIMContainer::startFlashingTab(LLFloater* floater, const std::strin
}
LLMultiFloater::setFloaterFlashing(floater, true, is_alt_flashing);
}
// <FS:PP> Restore open IMs from previous session
void FSFloaterIMContainer::saveOpenIMs()
{
static LLCachedControl<bool> fsRestoreOpenIMs(gSavedSettings, "FSRestoreOpenIMs");
if (!fsRestoreOpenIMs)
{
return;
}
LLSD openIMs = LLSD::emptyArray();
S32 saved_count = 0;
// Save all open IM sessions (excluding contacts and nearby chat)
for (S32 i = 0; i < mTabContainer->getTabCount(); ++i)
{
FSFloaterIM* floater = dynamic_cast<FSFloaterIM*>(mTabContainer->getPanelByIndex(i));
if (floater)
{
LLUUID session_id = floater->getKey();
if (session_id.notNull())
{
// Get the session info to save participant details
LLIMModel::LLIMSession* session = LLIMModel::getInstance()->findIMSession(session_id);
if (session)
{
LLSD session_data = LLSD::emptyMap();
session_data["session_type"] = (S32)session->mSessionType;
session_data["other_participant_id"] = session->mOtherParticipantID;
session_data["session_name"] = session->mName;
// For group sessions, also save the group ID
if (session->isGroupSessionType())
{
session_data["group_id"] = session->mOtherParticipantID;
}
openIMs.append(session_data);
++saved_count;
}
}
}
}
gSavedPerAccountSettings.setLLSD("FSLastOpenIMs", openIMs);
LL_DEBUGS("FSFloaterIMContainer") << "Saved " << saved_count << " open IM sessions for restoration" << LL_ENDL;
}
void FSFloaterIMContainer::restoreOpenIMs()
{
static LLCachedControl<bool> fsRestoreOpenIMs(gSavedSettings, "FSRestoreOpenIMs");
if (!fsRestoreOpenIMs)
{
return;
}
LLSD openIMs = gSavedPerAccountSettings.getLLSD("FSLastOpenIMs");
if (!openIMs.isArray() || openIMs.size() == 0)
{
return;
}
S32 restored_count = 0;
// Restore each saved IM session by creating new sessions with the saved participants
for (LLSD::array_const_iterator it = openIMs.beginArray(); it != openIMs.endArray(); ++it)
{
LLSD session_data = *it;
if (session_data.isMap())
{
LLUUID other_participant_id = session_data["other_participant_id"].asUUID();
S32 session_type = session_data["session_type"].asInteger();
std::string session_name = session_data["session_name"].asString();
if (other_participant_id.notNull())
{
LLUUID new_session_id;
// Create a new session based on the saved type
if (session_type == LLIMModel::LLIMSession::P2P_SESSION)
{
// For P2P sessions, start a new IM with the other participant
new_session_id = LLIMMgr::getInstance()->addSession(session_name, IM_NOTHING_SPECIAL, other_participant_id);
}
else if (session_type == LLIMModel::LLIMSession::GROUP_SESSION)
{
// For group sessions, start a new group IM
new_session_id = LLIMMgr::getInstance()->addSession(session_name, IM_SESSION_GROUP_START, other_participant_id);
}
else if (session_type == LLIMModel::LLIMSession::ADHOC_SESSION)
{
// For ad-hoc sessions, we'd need to restore the participant list
// For now, skip these as they're more complex
continue;
}
if (new_session_id.notNull())
{
// Create and show the IM floater
FSFloaterIM* im_floater = FSFloaterIM::show(new_session_id);
if (im_floater)
{
// Add to container if not already there
if (im_floater->getHost() != this)
{
addFloater(im_floater, false);
}
++restored_count;
}
}
}
}
}
LL_DEBUGS("FSFloaterIMContainer") << "Restored " << restored_count << " IM sessions" << LL_ENDL;
// Clear the saved list after restoration
gSavedPerAccountSettings.setLLSD("FSLastOpenIMs", LLSD::emptyArray());
}
// </FS:PP>
// EOF

View File

@ -82,6 +82,11 @@ public:
void startFlashingTab(LLFloater* floater, const std::string& message);
// <FS:PP> Restore open IMs from previous session
void saveOpenIMs();
void restoreOpenIMs();
// </FS:PP>
private:
enum eVoiceState
{

View File

@ -1144,6 +1144,16 @@
name="FSOpenIMContainerOnOfflineMessage"
control_name="FSOpenIMContainerOnOfflineMessage"
label="Open Conversations when an offline message has been received"/>
<check_box
layout="topleft"
follows="left|top"
top_pad="-2"
left="20"
width="400"
height="18"
name="FSRestoreOpenIMs"
control_name="FSRestoreOpenIMs"
label="Restore open IM windows from previous session"/>
<check_box
enabled="false"
layout="topleft"

View File

@ -172,6 +172,7 @@
</text>
<spinner tool_tip="-1 dla pełnej nazwy grupy, 0 aby wyłączyć" name="FSShowGroupNameLength"/>
<check_box name="FSOpenIMContainerOnOfflineMessage" label="Otwórz okno Rozmów, gdy pojawia się wiadomość offline"/>
<check_box name="FSRestoreOpenIMs" label="Przywróć otwarte okna IM z poprzedniej sesji" />
<check_box label="Ślij IM-y na mój e-mail, gdy jestem offline ([EMAIL])" name="send_im_to_email"/>
<text name="email_settings">
[https://accounts.secondlife.com/change_email Pokaż opcje powiadomień e-mail dla IM-ów offline]