1818import misc
1919import transfers
2020import auth
21- from ops import SendOp , ReceiveOp
22- from util import TransferDirection , OpStatus , OpCommand , RemoteStatus , ReceiveError
21+ from ops import SendOp , ReceiveOp , TextMessageOp
22+ from util import TransferDirection , OpStatus , OpCommand , RemoteStatus , ReceiveError , RemoteFeatures
2323
2424_ = gettext .gettext
2525
@@ -56,6 +56,7 @@ def __init__(self, ident, hostname, display_hostname, ip_info, port, local_ident
5656 self .display_name = ""
5757 self .favorite = prefs .get_is_favorite (self .ident )
5858 self .recent_time = 0 # Keep monotonic time when visited on the user page
59+ self .supports_messages = False
5960
6061 self .avatar_surface = None
6162 self .transfer_ops = []
@@ -366,6 +367,8 @@ def get_info_finished(future):
366367 info = future .result ()
367368 self .display_name = info .display_name
368369 self .user_name = info .user_name
370+ feature_flags = RemoteFeatures (info .feature_flags )
371+ self .supports_messages = RemoteFeatures .TEXT_MESSAGES in feature_flags
369372 self .favorite = prefs .get_is_favorite (self .ident )
370373
371374 valid = GLib .utf8_make_valid (self .display_name , - 1 )
@@ -590,6 +593,21 @@ def _send_files(uri_list):
590593 util .add_to_recents_if_single_selection (uri_list )
591594 self .rpc_call (_send_files , uri_list )
592595
596+ def send_text_message (self , message ):
597+ op = TextMessageOp (TransferDirection .TO_REMOTE_MACHINE , self .local_ident )
598+ op .message = message
599+ op .status = OpStatus .FINISHED
600+ self .add_op (op )
601+ self .rpc_call (self .do_send_text_message , op )
602+
603+ def do_send_text_message (self , op ):
604+ try :
605+ self .stub .SendTextMessage (warp_pb2 .TextMessage (ident = self .local_ident , timestamp = op .start_time , message = op .message ))
606+ except Exception as e :
607+ logging .error ("Sending message failed: %s" % e )
608+ op .status = OpStatus .FAILED
609+ op .emit_status_changed ()
610+
593611 @misc ._idle
594612 def add_op (self , op ):
595613 if op not in self .transfer_ops :
@@ -600,7 +618,7 @@ def add_op(self, op):
600618 if isinstance (op , SendOp ):
601619 op .connect ("initial-setup-complete" , self .notify_remote_machine_of_new_op )
602620 self .emit ("new-outgoing-op" , op )
603- if isinstance (op , ReceiveOp ):
621+ if isinstance (op , ( ReceiveOp , TextMessageOp ) ):
604622 self .emit ("new-incoming-op" , op )
605623
606624 def set_busy ():
@@ -662,8 +680,13 @@ def op_command_issued(self, op, command):
662680 elif command == OpCommand .STOP_TRANSFER_BY_SENDER :
663681 self .rpc_call (self .stop_transfer_op , op , by_sender = True )
664682 elif command == OpCommand .RETRY_TRANSFER :
665- op .set_status (OpStatus .WAITING_PERMISSION )
666- self .rpc_call (self .send_transfer_op_request , op )
683+ if isinstance (op , TextMessageOp ):
684+ op .status = OpStatus .FINISHED
685+ op .emit_status_changed ()
686+ self .rpc_call (self .do_send_text_message , op )
687+ else :
688+ op .set_status (OpStatus .WAITING_PERMISSION )
689+ self .rpc_call (self .send_transfer_op_request , op )
667690 elif command == OpCommand .REMOVE_TRANSFER :
668691 self .remove_op (op )
669692 # receive
0 commit comments