Skip to content

Commit 5daafd7

Browse files
committed
fix: persist chat lobby auto-subscribe and identity changes across restarts
1 parent d88a7ad commit 5daafd7

4 files changed

Lines changed: 30 additions & 3 deletions

File tree

src/chat/distributedchat.cc

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,7 +1504,6 @@ bool DistributedChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id,const
15041504
entry.last_connexion_challenge_time = now ;
15051505
entry.joined_lobby_packet_sent = false;
15061506
entry.last_keep_alive_packet_time = now ;
1507-
15081507
_chat_lobbys[lobby_id] = entry ;
15091508

15101509
_lobby_invites_queue.erase(it) ; // remove the invite from cache.
@@ -1517,14 +1516,18 @@ bool DistributedChatService::acceptLobbyInvite(const ChatLobbyId& lobby_id,const
15171516
RsChatLobbyMsgItem *item = new RsChatLobbyMsgItem;
15181517
item->lobby_id = entry.lobby_id ;
15191518
item->msg_id = 0 ;
1520-
item->parent_msg_id = 0 ;
1521-
item->nick = "Chat room management" ;
1519+
item->parent_msg_id = 0 ;
1520+
item->nick = "Chat room management" ;
15221521
item->message = std::string("Welcome to chat lobby") ;
15231522
item->PeerId(entry.virtual_peer_id) ;
15241523
item->chatFlags = RS_CHAT_FLAG_PRIVATE | RS_CHAT_FLAG_LOBBY ;
15251524

15261525
locked_storeIncomingMsg(item) ;
15271526
}
1527+
1528+
setLobbyAutoSubscribe(lobby_id, true);
1529+
triggerConfigSave(); // so that we save the subscribed lobbies
1530+
15281531
#ifdef DEBUG_CHAT_LOBBIES
15291532
std::cerr << " Notifying of new recvd msg." << std::endl ;
15301533
#endif
@@ -1706,6 +1709,7 @@ ChatLobbyId DistributedChatService::createChatLobby(const std::string& lobby_nam
17061709
ev->mEventCode = RsChatLobbyEventCode::CHAT_LOBBY_LIST_CHANGED;
17071710
rsEvents->postEvent(ev);
17081711

1712+
setLobbyAutoSubscribe(lobby_id, true);
17091713
triggerConfigSave();
17101714

17111715
return lobby_id ;
@@ -1910,6 +1914,8 @@ bool DistributedChatService::setIdentityForChatLobby(const ChatLobbyId& lobby_id
19101914
it->second.gxs_id = nick ;
19111915
}
19121916

1917+
triggerConfigSave() ;
1918+
19131919
return true ;
19141920
}
19151921

src/retroshare/rswire.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,11 @@ virtual bool getPulseFocus(const RsGxsGroupId &groupId, const RsGxsMessageId &ms
274274
std::vector<RsMsgMetaData>& summaries ) = 0;
275275

276276
virtual bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& groupId, bool subscribe) = 0;
277+
278+
// Simple subscribe/unsubscribe API without token management (for UI use)
279+
// Tokens are handled internally by libretroshare
280+
virtual bool subscribe(const RsGxsGroupId& groupId, bool subscribe) = 0;
281+
277282
virtual uint32_t getFollowingCount() = 0;
278283
virtual bool getSubscribedGroups(std::list<RsGxsGroupId>& groupIds) = 0;
279284

src/services/p3wire.cc

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1919,6 +1919,18 @@ bool p3Wire::subscribeToGroup(uint32_t& token, const RsGxsGroupId& groupId, bool
19191919
return response;
19201920
}
19211921

1922+
bool p3Wire::subscribe(const RsGxsGroupId& groupId, bool subscribe)
1923+
{
1924+
#ifdef WIRE_DEBUG
1925+
std::cerr << "p3Wire::subscribe() id: " << groupId << " subscribe: " << subscribe;
1926+
std::cerr << std::endl;
1927+
#endif
1928+
1929+
// Token is managed internally - UI doesn't need to handle it
1930+
uint32_t token;
1931+
return subscribeToGroup(token, groupId, subscribe);
1932+
}
1933+
19221934
void p3Wire::refreshSubscribedGroups()
19231935
{
19241936
uint32_t token;

src/services/p3wire.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,10 @@ class p3Wire: public RsGenExchange, public RsWire, public p3Config
9494
void setMessageReadStatus(uint32_t& token, const RsGxsGrpMsgIdPair& msgId, bool read) override;
9595

9696
bool subscribeToGroup(uint32_t& token, const RsGxsGroupId& groupId, bool subscribe) override;
97+
98+
// Simple subscribe/unsubscribe API without token management (for UI use)
99+
bool subscribe(const RsGxsGroupId& groupId, bool subscribe) override;
100+
97101
uint32_t getFollowingCount() override;
98102
bool getSubscribedGroups(std::list<RsGxsGroupId>& groupIds) override;
99103

0 commit comments

Comments
 (0)