Skip to content

Commit 865432a

Browse files
committed
Fix private chat being closed on pop-out
1 parent bc85d29 commit 865432a

File tree

2 files changed

+98
-57
lines changed

2 files changed

+98
-57
lines changed

core/src/com/biglybt/plugin/net/buddy/BuddyPluginBeta.java

+71-56
Original file line numberDiff line numberDiff line change
@@ -3304,7 +3304,7 @@ public void perform(TimerEvent e){
33043304

33053305
private volatile String last_bind_fail = null;
33063306

3307-
private boolean destroyed;
3307+
private volatile boolean destroyed;
33083308

33093309
private
33103310
ChatInstance(
@@ -3440,9 +3440,14 @@ public void perform(TimerEvent e){
34403440

34413441
protected void
34423442
addReference()
3443-
{
3443+
{
34443444
synchronized( chat_lock ){
34453445

3446+
if ( isDestroyed()){
3447+
3448+
Debug.out( "Adding reference to a destroyed chat..." );
3449+
}
3450+
34463451
if ( virtual_reference_count > 0 ){
34473452

34483453
virtual_reference_count--;
@@ -6480,7 +6485,7 @@ public void perform(TimerEvent event) {
64806485

64816486
public boolean
64826487
isDestroyed()
6483-
{
6488+
{
64846489
return( destroyed );
64856490
}
64866491

@@ -6494,6 +6499,8 @@ public void perform(TimerEvent event) {
64946499
destroy(
64956500
boolean force )
64966501
{
6502+
boolean do_destroy;
6503+
64976504
synchronized( chat_lock ){
64986505

64996506
if ( force ){
@@ -6513,86 +6520,94 @@ public void perform(TimerEvent event) {
65136520
return;
65146521
}
65156522
}
6516-
}
6517-
6518-
if ( !( keep_alive || (have_interest && !is_private_chat ))){
6523+
6524+
if ( !( keep_alive || (have_interest && !is_private_chat ))){
65196525

6520-
if ( !destroyed ) {
6526+
do_destroy = !destroyed;
65216527

6522-
destroyed = true;
6523-
6524-
for ( ChatListener l: listeners ){
6528+
if ( do_destroy ){
6529+
6530+
destroyed = true;
6531+
}
6532+
}else{
6533+
6534+
do_destroy = false;
6535+
}
6536+
}
65256537

6526-
try{
6527-
l.stateChanged( false );
6538+
if ( do_destroy ){
6539+
6540+
for ( ChatListener l: listeners ){
65286541

6529-
}catch( Throwable e ){
6542+
try{
6543+
l.stateChanged( false );
65306544

6531-
Debug.out( e );
6532-
}
6545+
}catch( Throwable e ){
6546+
6547+
Debug.out( e );
65336548
}
6534-
6535-
try{
6536-
if ( handler != null ){
6537-
6538-
if ( is_private_chat ){
6539-
6540-
Map<String,Object> flags = new HashMap<>();
6541-
6542-
flags.put( FLAGS_MSG_STATUS_KEY, FLAGS_MSG_STATUS_CHAT_QUIT );
6543-
6544-
sendMessageSupport( "", flags, new HashMap<String, Object>());
6545-
}
6546-
6547-
Map<String,Object> options = new HashMap<>();
6549+
}
6550+
6551+
try{
6552+
if ( handler != null ){
65486553

6549-
options.put( "handler", handler );
6550-
6551-
Map<String,Object> reply = (Map<String,Object>)msgsync_pi.getIPC().invoke( "removeMessageHandler", new Object[]{ options } );
6552-
}
6553-
}catch( Throwable e ){
6554+
if ( is_private_chat ){
65546555

6555-
Debug.out( e );
6556+
Map<String,Object> flags = new HashMap<>();
65566557

6557-
}finally{
6558+
flags.put( FLAGS_MSG_STATUS_KEY, FLAGS_MSG_STATUS_CHAT_QUIT );
6559+
6560+
sendMessageSupport( "", flags, new HashMap<String, Object>());
6561+
}
6562+
6563+
Map<String,Object> options = new HashMap<>();
6564+
6565+
options.put( "handler", handler );
65586566

6559-
String meta_key = network + ":" + key;
6567+
Map<String,Object> reply = (Map<String,Object>)msgsync_pi.getIPC().invoke( "removeMessageHandler", new Object[]{ options } );
6568+
}
6569+
}catch( Throwable e ){
6570+
6571+
Debug.out( e );
65606572

6561-
ChatInstance removed = null;
6573+
}finally{
65626574

6563-
synchronized( chat_instances_map ){
6575+
String meta_key = network + ":" + key;
65646576

6565-
ChatInstance inst = chat_instances_map.remove( meta_key );
6577+
ChatInstance removed = null;
65666578

6567-
if ( inst != null ){
6579+
synchronized( chat_instances_map ){
65686580

6569-
removed = inst;
6581+
ChatInstance inst = chat_instances_map.remove( meta_key );
65706582

6571-
chat_instances_list.remove( inst );
6572-
}
6583+
if ( inst != null ){
65736584

6574-
if ( chat_instances_map.size() == 0 ){
6585+
removed = inst;
65756586

6576-
if ( timer != null ){
6587+
chat_instances_list.remove( inst );
6588+
}
65776589

6578-
timer.cancel();
6590+
if ( chat_instances_map.size() == 0 ){
65796591

6580-
timer = null;
6581-
}
6592+
if ( timer != null ){
6593+
6594+
timer.cancel();
6595+
6596+
timer = null;
65826597
}
65836598
}
6599+
}
65846600

6585-
if ( removed != null ){
6601+
if ( removed != null ){
65866602

6587-
for ( ChatManagerListener l: BuddyPluginBeta.this.listeners ){
6603+
for ( ChatManagerListener l: BuddyPluginBeta.this.listeners ){
65886604

6589-
try{
6590-
l.chatRemoved( removed );
6605+
try{
6606+
l.chatRemoved( removed );
65916607

6592-
}catch( Throwable e ){
6608+
}catch( Throwable e ){
65936609

6594-
Debug.out( e );
6595-
}
6610+
Debug.out( e );
65966611
}
65976612
}
65986613
}

uis/src/com/biglybt/ui/swt/plugin/net/buddy/swt/SBC_ChatOverview.java

+27-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
import com.biglybt.core.util.Base32;
3535
import com.biglybt.core.util.Debug;
3636
import com.biglybt.core.util.GeneralUtils;
37+
import com.biglybt.core.util.SimpleTimer;
38+
import com.biglybt.core.util.SystemTime;
3739
import com.biglybt.pifimpl.local.PluginInitializer;
3840
import com.biglybt.plugin.net.buddy.BuddyPluginBeta;
3941
import com.biglybt.plugin.net.buddy.BuddyPluginBeta.ChatInstance;
@@ -258,7 +260,31 @@ public class SBC_ChatOverview
258260
options.put( PopOutManager.OPT_ON_TOP, on_top );
259261
options.put( PopOutManager.OPT_CAN_MINIMIZE, true );
260262

261-
mdi.popoutEntryByID("Chat_", chat, options );
263+
ChatInstance clone = null;
264+
265+
try{
266+
// unfortunately the popup process can create an intermediate mdi chat view
267+
// that gets destroyed before the popup opens so we need to retain a reference
268+
// to the chat during this process :(
269+
270+
clone = chat.getClone();
271+
272+
mdi.popoutEntryByID("Chat_", chat, options );
273+
274+
}finally{
275+
276+
if ( clone != null ){
277+
278+
ChatInstance fclone = clone;
279+
280+
SimpleTimer.addEvent(
281+
"chatdestroy",
282+
SystemTime.getOffsetTime( 10*1000 ),
283+
(ev)->{
284+
fclone.destroy();
285+
});
286+
}
287+
}
262288
}
263289
}catch( Throwable e ){
264290

0 commit comments

Comments
 (0)