Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
gajim
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
194
Issues
194
List
Boards
Labels
Service Desk
Milestones
Merge Requests
20
Merge Requests
20
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
gajim
gajim
Commits
5ce4ec3e
Commit
5ce4ec3e
authored
Jul 27, 2013
by
Yann Leboulanger
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
use XEP-0033 to send one message to several JIDs
parent
18c4edb1
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
104 additions
and
67 deletions
+104
-67
src/common/connection.py
src/common/connection.py
+97
-56
src/dialogs.py
src/dialogs.py
+7
-11
No files found.
src/common/connection.py
View file @
5ce4ec3e
...
...
@@ -160,6 +160,7 @@ def __init__(self, name):
self
.
archive_pref_supported
=
False
self
.
roster_supported
=
True
self
.
blocking_supported
=
False
self
.
addressing_supported
=
False
self
.
muc_jid
=
{}
# jid of muc server for each transport type
self
.
_stun_servers
=
[]
# STUN servers of our jabber server
...
...
@@ -259,14 +260,33 @@ def _prepare_message(self, jid, msg, keyID, type_='chat', subject='',
if
not
self
.
connection
or
self
.
connected
<
2
:
return
1
try
:
jid
=
self
.
check_jid
(
jid
)
except
helpers
.
InvalidFormat
:
gajim
.
nec
.
push_incoming_event
(
InformationEvent
(
None
,
conn
=
self
,
level
=
'error'
,
pri_txt
=
_
(
'Invalid Jabber ID'
),
sec_txt
=
_
(
'It is not possible to send a message to %s, this JID is not '
'valid.'
)
%
jid
))
return
if
isinstance
(
jid
,
list
):
new_list
=
[]
for
j
in
jid
:
try
:
new_list
.
append
(
self
.
check_jid
(
j
))
except
helpers
.
InvalidFormat
:
gajim
.
nec
.
push_incoming_event
(
InformationEvent
(
None
,
conn
=
self
,
level
=
'error'
,
pri_txt
=
_
(
'Invalid Jabber '
'ID'
),
sec_txt
=
_
(
'It is not possible to send a message '
'to %s, this JID is not valid.'
)
%
j
))
return
fjid
=
new_list
else
:
try
:
jid
=
self
.
check_jid
(
jid
)
except
helpers
.
InvalidFormat
:
gajim
.
nec
.
push_incoming_event
(
InformationEvent
(
None
,
conn
=
self
,
level
=
'error'
,
pri_txt
=
_
(
'Invalid Jabber ID'
),
sec_txt
=
_
(
'It is not possible to send a message to %s, this JID is not '
'valid.'
)
%
jid
))
return
fjid
=
jid
if
resource
:
fjid
+=
'/'
+
resource
if
session
:
fjid
=
session
.
get_to
()
if
msg
and
not
xhtml
and
gajim
.
config
.
get
(
'rst_formatting_outgoing_messages'
):
...
...
@@ -274,15 +294,10 @@ def _prepare_message(self, jid, msg, keyID, type_='chat', subject='',
xhtml
=
create_xhtml
(
msg
)
if
not
msg
and
chatstate
is
None
and
form_node
is
None
:
return
fjid
=
jid
if
resource
:
fjid
+=
'/'
+
resource
msgtxt
=
msg
msgenc
=
''
if
session
:
fjid
=
session
.
get_to
()
if
keyID
and
self
.
USE_GPG
:
xhtml
=
None
if
keyID
==
'UNKNOWN'
:
...
...
@@ -386,15 +401,16 @@ def _on_continue_message(self, type_, msg, msgtxt, original_message, fjid,
subject
,
type_
,
correction_msg
,
xhtml
)
return
if
type_
==
'chat'
:
msg_iq
=
nbxmpp
.
Message
(
to
=
fjid
,
body
=
msgtxt
,
typ
=
type_
,
msg_iq
=
nbxmpp
.
Message
(
body
=
msgtxt
,
typ
=
type_
,
xhtml
=
xhtml
)
else
:
if
subject
:
msg_iq
=
nbxmpp
.
Message
(
to
=
fjid
,
body
=
msgtxt
,
typ
=
'normal'
,
msg_iq
=
nbxmpp
.
Message
(
body
=
msgtxt
,
typ
=
'normal'
,
subject
=
subject
,
xhtml
=
xhtml
)
else
:
msg_iq
=
nbxmpp
.
Message
(
to
=
fjid
,
body
=
msgtxt
,
typ
=
'normal'
,
msg_iq
=
nbxmpp
.
Message
(
body
=
msgtxt
,
typ
=
'normal'
,
xhtml
=
xhtml
)
if
msg_id
:
...
...
@@ -413,26 +429,6 @@ def _on_continue_message(self, type_, msg, msgtxt, original_message, fjid,
msg_iq
.
setTag
(
'nick'
,
namespace
=
nbxmpp
.
NS_NICK
).
setData
(
user_nick
)
# TODO: We might want to write a function so we don't need to
# reproduce that ugly if somewhere else.
if
resource
:
contact
=
gajim
.
contacts
.
get_contact
(
self
.
name
,
jid
,
resource
)
else
:
contact
=
gajim
.
contacts
.
get_contact_with_highest_priority
(
self
.
name
,
jid
)
# chatstates - if peer supports xep85, send chatstates
# please note that the only valid tag inside a message containing a
# <body> tag is the active event
if
chatstate
and
contact
and
contact
.
supports
(
NS_CHATSTATES
):
msg_iq
.
setTag
(
chatstate
,
namespace
=
NS_CHATSTATES
)
if
forward_from
:
addresses
=
msg_iq
.
addChild
(
'addresses'
,
namespace
=
nbxmpp
.
NS_ADDRESS
)
addresses
.
addChild
(
'address'
,
attrs
=
{
'type'
:
'ofrom'
,
'jid'
:
forward_from
})
# XEP-0203
if
delayed
:
our_jid
=
gajim
.
get_jid_from_account
(
self
.
name
)
+
'/'
+
\
...
...
@@ -441,25 +437,60 @@ def _on_continue_message(self, type_, msg, msgtxt, original_message, fjid,
msg_iq
.
addChild
(
'delay'
,
namespace
=
nbxmpp
.
NS_DELAY2
,
attrs
=
{
'from'
:
our_jid
,
'stamp'
:
timestamp
})
# XEP-0184
if
msgtxt
and
gajim
.
config
.
get_per
(
'accounts'
,
self
.
name
,
'request_receipt'
)
and
contact
and
contact
.
supports
(
nbxmpp
.
NS_RECEIPTS
):
msg_iq
.
setTag
(
'request'
,
namespace
=
nbxmpp
.
NS_RECEIPTS
)
if
session
:
# XEP-0201
session
.
last_send
=
time
.
time
()
msg_iq
.
setThread
(
session
.
thread_id
)
# XEP-0200
if
session
.
enable_encryption
:
msg_iq
=
session
.
encrypt_stanza
(
msg_iq
)
# XEP-0224
if
attention
:
msg_iq
.
setTag
(
'attention'
,
namespace
=
nbxmpp
.
NS_ATTENTION
)
if
isinstance
(
jid
,
list
):
if
self
.
addressing_supported
:
msg_iq
.
setTo
(
gajim
.
config
.
get_per
(
'accounts'
,
self
.
name
,
'hostname'
))
addresses
=
msg_iq
.
addChild
(
'addresses'
,
namespace
=
nbxmpp
.
NS_ADDRESS
)
for
j
in
jid
:
addresses
.
addChild
(
'address'
,
attrs
=
{
'type'
:
'to'
,
'jid'
:
j
})
else
:
iqs
=
[]
for
j
in
jid
:
iq
=
nbxmpp
.
Message
(
node
=
msg_iq
)
iq
.
setTo
(
j
)
iqs
.
append
(
iq
)
msg_iq
=
iqs
else
:
msg_id
.
setTo
(
fjid
)
if
resource
:
contact
=
gajim
.
contacts
.
get_contact
(
self
.
name
,
jid
,
resource
)
else
:
contact
=
gajim
.
contacts
.
get_contact_with_highest_priority
(
self
.
name
,
jid
)
# chatstates - if peer supports xep85, send chatstates
# please note that the only valid tag inside a message containing a
# <body> tag is the active event
if
chatstate
and
contact
and
contact
.
supports
(
NS_CHATSTATES
):
msg_iq
.
setTag
(
chatstate
,
namespace
=
NS_CHATSTATES
)
# XEP-0184
if
msgtxt
and
gajim
.
config
.
get_per
(
'accounts'
,
self
.
name
,
'request_receipt'
)
and
contact
and
contact
.
supports
(
nbxmpp
.
NS_RECEIPTS
):
msg_iq
.
setTag
(
'request'
,
namespace
=
nbxmpp
.
NS_RECEIPTS
)
if
forward_from
:
addresses
=
msg_iq
.
addChild
(
'addresses'
,
namespace
=
nbxmpp
.
NS_ADDRESS
)
addresses
.
addChild
(
'address'
,
attrs
=
{
'type'
:
'ofrom'
,
'jid'
:
forward_from
})
if
session
:
# XEP-0201
session
.
last_send
=
time
.
time
()
msg_iq
.
setThread
(
session
.
thread_id
)
# XEP-0200
if
session
.
enable_encryption
:
msg_iq
=
session
.
encrypt_stanza
(
msg_iq
)
if
callback
:
callback
(
jid
,
msg
,
keyID
,
forward_from
,
session
,
original_message
,
subject
,
type_
,
msg_iq
,
xhtml
)
...
...
@@ -1902,6 +1933,8 @@ def _nec_agent_info_received(self, obj):
self
.
archive_pref_supported
=
True
if
nbxmpp
.
NS_BLOCKING
in
obj
.
features
:
self
.
blocking_supported
=
True
if
nbxmpp
.
NS_ADDRESS
in
obj
.
features
:
self
.
addressing_supported
=
True
if
nbxmpp
.
NS_CARBONS
in
obj
.
features
and
gajim
.
config
.
get_per
(
'accounts'
,
self
.
name
,
'enable_message_carbons'
):
# Server supports carbons, activate it
...
...
@@ -1995,8 +2028,11 @@ def _nec_message_outgoing(self, obj):
def
cb
(
jid
,
msg
,
keyID
,
forward_from
,
session
,
original_message
,
subject
,
type_
,
msg_iq
,
xhtml
):
msg_id
=
self
.
connection
.
send
(
msg_iq
,
now
=
obj
.
now
)
jid
=
helpers
.
parse_jid
(
obj
.
jid
)
if
isinstance
(
msg_iq
,
list
):
for
iq
in
msg_iq
:
msg_id
=
self
.
connection
.
send
(
iq
,
now
=
obj
.
now
)
else
:
msg_id
=
self
.
connection
.
send
(
msg_iq
,
now
=
obj
.
now
)
gajim
.
nec
.
push_incoming_event
(
MessageSentEvent
(
None
,
conn
=
self
,
jid
=
jid
,
message
=
msg
,
keyID
=
keyID
,
chatstate
=
obj
.
chatstate
))
if
obj
.
callback
:
...
...
@@ -2004,8 +2040,13 @@ def cb(jid, msg, keyID, forward_from, session, original_message,
if
not
obj
.
is_loggable
:
return
self
.
log_message
(
jid
,
msg
,
forward_from
,
session
,
original_message
,
subject
,
type_
,
xhtml
)
if
isinstance
(
jid
,
list
):
for
j
in
jid
:
self
.
log_message
(
j
,
msg
,
forward_from
,
session
,
original_message
,
subject
,
type_
,
xhtml
)
else
:
self
.
log_message
(
jid
,
msg
,
forward_from
,
session
,
original_message
,
subject
,
type_
,
xhtml
)
self
.
_prepare_message
(
obj
.
jid
,
obj
.
message
,
obj
.
keyID
,
type_
=
obj
.
type_
,
subject
=
obj
.
subject
,
chatstate
=
obj
.
chatstate
,
msg_id
=
obj
.
msg_id
,
...
...
src/dialogs.py
View file @
5ce4ec3e
...
...
@@ -3174,6 +3174,8 @@ def send_single_message(self):
else
:
form_node
=
None
recipient_list
=
[]
for
to_whom_jid
in
sender_list
:
if
to_whom_jid
in
self
.
completion_dict
:
to_whom_jid
=
self
.
completion_dict
[
to_whom_jid
].
jid
...
...
@@ -3190,17 +3192,11 @@ def send_single_message(self):
message
)
continue
if
self
.
session
:
session
=
self
.
session
else
:
session
=
gajim
.
connections
[
self
.
account
].
make_new_session
(
to_whom_jid
)
# FIXME: allow GPG message some day
gajim
.
nec
.
push_outgoing_event
(
MessageOutgoingEvent
(
None
,
account
=
self
.
account
,
jid
=
to_whom_jid
,
message
=
message
,
type_
=
'normal'
,
subject
=
subject
,
session
=
session
,
form_node
=
form_node
))
recipient_list
.
append
(
to_whom_jid
)
gajim
.
nec
.
push_outgoing_event
(
MessageOutgoingEvent
(
None
,
account
=
self
.
account
,
jid
=
recipient_list
,
message
=
message
,
type_
=
'normal'
,
subject
=
subject
,
form_node
=
form_node
))
self
.
subject_entry
.
set_text
(
''
)
# we sent ok, clear the subject
self
.
message_tv_buffer
.
set_text
(
''
)
# we sent ok, clear the textview
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment