Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
converse.js
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
converse.js
Commits
17e0e70e
Commit
17e0e70e
authored
Feb 21, 2017
by
JC Brand
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Support for XEP-0203 delayed delivery of presence stanzas
parent
40605607
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
200 additions
and
185 deletions
+200
-185
docs/CHANGES.md
docs/CHANGES.md
+1
-0
spec/presence.js
spec/presence.js
+156
-160
src/converse-core.js
src/converse-core.js
+43
-25
No files found.
docs/CHANGES.md
View file @
17e0e70e
...
...
@@ -16,6 +16,7 @@
*
Templates are no longer stored as attributes on the
`_converse`
object.
If you need a particular template, use
`require`
to load it.
-
Better support for delayed delivery of presence stanzas (XEP-0203). [jcbrand]
-
The chat room
`description`
is now shown in the heading, not the
`subject`
.
[jcbrand]
-
Chat room features are shown in the sidebar. [jcbrand]
...
...
spec/presence.js
View file @
17e0e70e
This diff is collapsed.
Click to expand it.
src/converse-core.js
View file @
17e0e70e
...
...
@@ -177,6 +177,7 @@
Strophe
.
addNamespace
(
'
NICK
'
,
'
http://jabber.org/protocol/nick
'
);
Strophe
.
addNamespace
(
'
HINTS
'
,
'
urn:xmpp:hints
'
);
Strophe
.
addNamespace
(
'
PUBSUB
'
,
'
http://jabber.org/protocol/pubsub
'
);
Strophe
.
addNamespace
(
'
DELAY
'
,
'
urn:xmpp:delay
'
);
// Instance level constants
this
.
TIMEOUTS
=
{
// Set as module attr so that we can override in tests.
...
...
@@ -855,22 +856,44 @@
return
this
;
},
addResource
:
function
(
resource
,
priority
,
chat_status
)
{
var
resources
=
this
.
get
(
'
resources
'
);
if
(
!
_
.
isObject
(
resources
))
{
resources
=
{};
}
addResource
:
function
(
presence
)
{
/* Adds a new resource and it's associated attributes as taken
* from the passed in presence stanza.
*
* Also updates the contact's chat_status if the presence has
* higher priority (and is newer).
*/
var
jid
=
presence
.
getAttribute
(
'
from
'
),
chat_status
=
_
.
propertyOf
(
presence
.
querySelector
(
'
show
'
))(
'
textContent
'
)
||
'
online
'
,
resource
=
Strophe
.
getResourceFromJid
(
jid
),
priority
=
_
.
propertyOf
(
presence
.
querySelector
(
'
priority
'
))(
'
textContent
'
)
||
0
,
delay
=
presence
.
querySelector
(
'
delay[xmlns="
'
+
Strophe
.
NS
.
DELAY
+
'
"]
'
),
timestamp
=
_
.
isNull
(
delay
)
?
moment
().
format
()
:
moment
(
delay
.
getAttribute
(
'
stamp
'
)).
format
();
priority
=
_
.
isNaN
(
parseInt
(
priority
,
10
))
?
0
:
parseInt
(
priority
,
10
);
var
resources
=
_
.
isObject
(
this
.
get
(
'
resources
'
))
?
this
.
get
(
'
resources
'
)
:
{};
resources
[
resource
]
=
{
'
priority
'
:
_
.
isNaN
(
parseInt
(
priority
,
10
))
?
0
:
parseInt
(
priority
,
10
)
,
'
priority
'
:
priority
,
'
status
'
:
chat_status
,
'
timestamp
'
:
moment
().
format
()
'
timestamp
'
:
timestamp
};
this
.
set
({
'
resources
'
:
resources
});
var
changed
=
{
'
resources
'
:
resources
};
var
hpr
=
this
.
getHighestPriorityResource
();
if
(
priority
==
hpr
.
priority
&&
timestamp
==
hpr
.
timestamp
)
{
// Only set the chat status if this is the newest resource
// with the highest priority
changed
.
chat_status
=
chat_status
;
}
this
.
save
(
changed
);
return
resources
;
},
removeResource
:
function
(
resource
)
{
/* Remove the passed in resource from the contact's resources
* map.
* Return the amount of resources left over.
/* Remove the passed in resource from the contact's resources map.
*
* Also recomputes the chat_status given that there's one less
* resource.
*/
var
resources
=
this
.
get
(
'
resources
'
);
if
(
!
_
.
isObject
(
resources
))
{
...
...
@@ -878,13 +901,15 @@
}
else
{
delete
resources
[
resource
];
}
this
.
save
({
'
resources
'
:
resources
});
return
_
.
size
(
resources
);
this
.
save
({
'
resources
'
:
resources
,
'
chat_status
'
:
_
.
propertyOf
(
this
.
getHighestPriorityResource
())(
'
status
'
)
||
'
offline
'
});
},
getHighestPriorityStatus
:
function
()
{
/* Return the chat status assigned to the resource with the
* highest priority.
getHighestPriorityResource
:
function
()
{
/* Return the resource with the highest priority.
*
* If multiple resources have the same priority, take the
* newest one.
...
...
@@ -897,10 +922,9 @@
_
.
reverse
)(
resources
)[
0
];
if
(
!
_
.
isUndefined
(
val
))
{
return
val
.
status
;
return
val
;
}
}
return
'
offline
'
;
},
removeFromRoster
:
function
(
callback
)
{
...
...
@@ -1225,7 +1249,6 @@
resource
=
Strophe
.
getResourceFromJid
(
jid
),
chat_status
=
_
.
propertyOf
(
presence
.
querySelector
(
'
show
'
))(
'
textContent
'
)
||
'
online
'
,
status_message
=
_
.
propertyOf
(
presence
.
querySelector
(
'
status
'
))(
'
textContent
'
),
priority
=
_
.
propertyOf
(
presence
.
querySelector
(
'
priority
'
))(
'
textContent
'
)
||
0
,
contact
=
this
.
get
(
bare_jid
);
if
(
this
.
isSelf
(
bare_jid
))
{
...
...
@@ -1258,14 +1281,9 @@
this
.
handleIncomingSubscription
(
presence
);
}
else
if
(
presence_type
===
'
unavailable
'
&&
contact
)
{
contact
.
removeResource
(
resource
);
contact
.
save
({
'
chat_status
'
:
contact
.
getHighestPriorityStatus
()});
}
else
if
(
contact
)
{
// presence_type is undefined
var
resources
=
contact
.
addResource
(
resource
,
priority
,
chat_status
);
if
(
priority
>=
_
.
flow
(
_
.
values
,
_
.
partial
(
_
.
map
,
_
,
'
priority
'
),
_
.
max
)(
resources
))
{
// Only save if it's the resource with the highest
// priority
contact
.
save
({
'
chat_status
'
:
chat_status
});
}
}
else
if
(
contact
)
{
// presence_type is undefined
contact
.
addResource
(
presence
);
}
}
});
...
...
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