Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
O
Openfire
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Openfire
Commits
d9f4a94e
Commit
d9f4a94e
authored
Aug 15, 2015
by
PGoski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
get count of users unread messages
parent
1f68e1bc
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
144 additions
and
2 deletions
+144
-2
changelog.html
src/plugins/restAPI/changelog.html
+5
-0
plugin.xml
src/plugins/restAPI/plugin.xml
+2
-2
MsgArchiveController.java
...openfire/plugin/rest/controller/MsgArchiveController.java
+74
-0
MsgArchiveEntity.java
...oftware/openfire/plugin/rest/entity/MsgArchiveEntity.java
+29
-0
JerseyWrapper.java
...esoftware/openfire/plugin/rest/service/JerseyWrapper.java
+2
-0
MsgArchiveService.java
...tware/openfire/plugin/rest/service/MsgArchiveService.java
+32
-0
No files found.
src/plugins/restAPI/changelog.html
View file @
d9f4a94e
...
@@ -44,6 +44,11 @@
...
@@ -44,6 +44,11 @@
REST API Plugin Changelog
REST API Plugin Changelog
</h1>
</h1>
<p><b>
1.1.3
</b>
-- August 15th, 2015
</p>
<ul>
<li>
Added: get count of users unread messages
</li>
</ul>
<p><b>
1.1.2
</b>
-- August 4th, 2015
</p>
<p><b>
1.1.2
</b>
-- August 4th, 2015
</p>
<ul>
<ul>
<li>
Added: CORS to all endpoints
</li>
<li>
Added: CORS to all endpoints
</li>
...
...
src/plugins/restAPI/plugin.xml
View file @
d9f4a94e
...
@@ -5,8 +5,8 @@
...
@@ -5,8 +5,8 @@
<name>
REST API
</name>
<name>
REST API
</name>
<description>
Allows administration over a RESTful API.
</description>
<description>
Allows administration over a RESTful API.
</description>
<author>
Roman Soldatow
</author>
<author>
Roman Soldatow
</author>
<version>
1.1.
2
</version>
<version>
1.1.
3
</version>
<date>
08/
04
/2015
</date>
<date>
08/
15
/2015
</date>
<minServerVersion>
3.9.0
</minServerVersion>
<minServerVersion>
3.9.0
</minServerVersion>
<adminconsole>
<adminconsole>
...
...
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/controller/MsgArchiveController.java
0 → 100644
View file @
d9f4a94e
package
org
.
jivesoftware
.
openfire
.
plugin
.
rest
.
controller
;
import
org.jivesoftware.database.DbConnectionManager
;
import
org.jivesoftware.openfire.XMPPServer
;
import
org.slf4j.Logger
;
import
org.slf4j.LoggerFactory
;
import
org.xmpp.packet.JID
;
import
java.sql.Connection
;
import
java.sql.PreparedStatement
;
import
java.sql.ResultSet
;
import
java.sql.SQLException
;
/**
* The Class MsgArchiveController.
*/
public
class
MsgArchiveController
{
private
static
final
Logger
Log
=
LoggerFactory
.
getLogger
(
MsgArchiveController
.
class
);
/** The Constant INSTANCE. */
public
static
final
MsgArchiveController
INSTANCE
=
new
MsgArchiveController
();
/** The server. */
private
XMPPServer
server
;
private
static
final
String
USER_MESSAGE_COUNT
=
"select COUNT(1) from ofMessageArchive a "
+
"join ofPresence p on (a.sentDate > p.offlineDate) "
+
"WHERE a.toJID = ? AND p.username = ?"
;
/**
* Gets the single instance of MsgArchiveController.
*
* @return single instance of MsgArchiveController
*/
public
static
MsgArchiveController
getInstance
()
{
return
INSTANCE
;
}
/**
* Instantiates a new user service controller.
*/
private
MsgArchiveController
()
{
server
=
XMPPServer
.
getInstance
();
}
/**
* Returns the total number of messages that haven't been delivered to the user.
*
* @return the total number of user unread messages.
*/
public
int
getUnReadMessagesCount
(
JID
jid
)
{
int
messageCount
=
0
;
Connection
con
=
null
;
PreparedStatement
pstmt
=
null
;
ResultSet
rs
=
null
;
try
{
con
=
DbConnectionManager
.
getConnection
();
pstmt
=
con
.
prepareStatement
(
USER_MESSAGE_COUNT
);
pstmt
.
setString
(
1
,
jid
.
toBareJID
());
pstmt
.
setString
(
2
,
jid
.
getNode
());
rs
=
pstmt
.
executeQuery
();
if
(
rs
.
next
())
{
messageCount
=
rs
.
getInt
(
1
);
}
}
catch
(
SQLException
sqle
)
{
Log
.
error
(
sqle
.
getMessage
(),
sqle
);
}
finally
{
DbConnectionManager
.
closeConnection
(
rs
,
pstmt
,
con
);
}
return
messageCount
;
}
}
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/entity/MsgArchiveEntity.java
0 → 100644
View file @
d9f4a94e
package
org
.
jivesoftware
.
openfire
.
plugin
.
rest
.
entity
;
import
javax.xml.bind.annotation.XmlElement
;
import
javax.xml.bind.annotation.XmlRootElement
;
/**
* The Class MsgArchiveEntity.
*/
@XmlRootElement
(
name
=
"archive"
)
public
class
MsgArchiveEntity
{
@XmlElement
String
jid
;
/**
* unread messages count
*/
@XmlElement
int
count
;
public
MsgArchiveEntity
()
{
}
public
MsgArchiveEntity
(
String
jid
,
int
count
)
{
this
.
jid
=
jid
;
this
.
count
=
count
;
}
}
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/service/JerseyWrapper.java
View file @
d9f4a94e
...
@@ -82,6 +82,8 @@ public class JerseyWrapper extends ServletContainer {
...
@@ -82,6 +82,8 @@ public class JerseyWrapper extends ServletContainer {
prc
.
getClasses
().
add
(
SessionService
.
class
);
prc
.
getClasses
().
add
(
SessionService
.
class
);
prc
.
getClasses
().
add
(
RESTExceptionMapper
.
class
);
prc
.
getClasses
().
add
(
RESTExceptionMapper
.
class
);
prc
.
getClasses
().
add
(
MsgArchiveService
.
class
);
}
}
/**
/**
...
...
src/plugins/restAPI/src/java/org/jivesoftware/openfire/plugin/rest/service/MsgArchiveService.java
0 → 100644
View file @
d9f4a94e
package
org
.
jivesoftware
.
openfire
.
plugin
.
rest
.
service
;
import
org.jivesoftware.openfire.plugin.rest.controller.MsgArchiveController
;
import
org.jivesoftware.openfire.plugin.rest.entity.MsgArchiveEntity
;
import
org.jivesoftware.openfire.plugin.rest.exceptions.ServiceException
;
import
org.xmpp.packet.JID
;
import
javax.annotation.PostConstruct
;
import
javax.ws.rs.GET
;
import
javax.ws.rs.Path
;
import
javax.ws.rs.PathParam
;
import
javax.ws.rs.Produces
;
import
javax.ws.rs.core.MediaType
;
@Path
(
"restapi/v1/archive/messages/unread/{jid}"
)
public
class
MsgArchiveService
{
private
MsgArchiveController
archive
;
@PostConstruct
public
void
init
()
{
archive
=
MsgArchiveController
.
getInstance
();
}
@GET
@Produces
({
MediaType
.
APPLICATION_XML
,
MediaType
.
APPLICATION_JSON
})
public
MsgArchiveEntity
getUnReadMessagesCount
(
@PathParam
(
"jid"
)
String
jidStr
)
throws
ServiceException
{
JID
jid
=
new
JID
(
jidStr
);
int
msgCount
=
archive
.
getUnReadMessagesCount
(
jid
);
return
new
MsgArchiveEntity
(
jidStr
,
msgCount
);
}
}
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