Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
X
xabber-android
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
xabber-android
Commits
e510e180
Commit
e510e180
authored
Feb 06, 2013
by
Alexander Ivanov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix status tracking. Close #100.
parent
303dccc8
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
139 additions
and
64 deletions
+139
-64
AbstractChat.java
src/com/xabber/android/data/message/AbstractChat.java
+12
-1
ChatAction.java
src/com/xabber/android/data/message/ChatAction.java
+10
-12
MessageManager.java
src/com/xabber/android/data/message/MessageManager.java
+28
-1
RegularChat.java
src/com/xabber/android/data/message/RegularChat.java
+0
-36
AbstractContact.java
src/com/xabber/android/data/roster/AbstractContact.java
+2
-10
OnStatusChangeListener.java
...om/xabber/android/data/roster/OnStatusChangeListener.java
+51
-0
PresenceManager.java
src/com/xabber/android/data/roster/PresenceManager.java
+36
-4
No files found.
src/com/xabber/android/data/message/AbstractChat.java
View file @
e510e180
...
...
@@ -73,6 +73,11 @@ public abstract class AbstractChat extends BaseEntity {
*/
protected
boolean
active
;
/**
* Whether changes in status should be record.
*/
protected
boolean
trackStatus
;
/**
* Whether user never received notifications from this chat.
*/
...
...
@@ -109,6 +114,7 @@ public abstract class AbstractChat extends BaseEntity {
super
(
account
,
user
);
threadId
=
StringUtils
.
randomString
(
12
);
active
=
false
;
trackStatus
=
false
;
firstNotification
=
true
;
lastText
=
""
;
lastTime
=
null
;
...
...
@@ -264,6 +270,7 @@ public abstract class AbstractChat extends BaseEntity {
void
openChat
()
{
active
=
true
;
trackStatus
=
true
;
}
void
closeChat
()
{
...
...
@@ -271,6 +278,10 @@ public abstract class AbstractChat extends BaseEntity {
firstNotification
=
true
;
}
boolean
isStatusTrackingEnabled
()
{
return
trackStatus
;
}
/**
* @return Target address for sending message.
*/
...
...
@@ -390,7 +401,7 @@ public abstract class AbstractChat extends BaseEntity {
save
=
false
;
Date
timestamp
=
new
Date
();
if
(
notify
||
!
incoming
)
active
=
true
;
openChat
()
;
if
(!
incoming
)
notify
=
false
;
if
(
notify
&&
!
notifyAboutMessage
())
...
...
src/com/xabber/android/data/message/ChatAction.java
View file @
e510e180
...
...
@@ -14,12 +14,9 @@
*/
package
com
.
xabber
.
android
.
data
.
message
;
import
org.jivesoftware.smack.packet.Presence
;
import
org.jivesoftware.smack.packet.Presence.Mode
;
import
org.jivesoftware.smack.packet.Presence.Type
;
import
android.content.Context
;
import
com.xabber.android.data.account.StatusMode
;
import
com.xabber.androiddev.R
;
/**
...
...
@@ -180,20 +177,21 @@ public enum ChatAction {
*/
attention_requested
;
public
static
ChatAction
getChatAction
(
Presence
presenc
e
)
{
if
(
presence
.
getType
()
==
Typ
e
.
unavailable
)
public
static
ChatAction
getChatAction
(
StatusMode
statusMod
e
)
{
if
(
statusMode
==
StatusMod
e
.
unavailable
)
return
ChatAction
.
unavailable
;
Mode
mode
=
presence
.
getMode
();
if
(
mode
==
Mode
.
away
)
else
if
(
statusMode
==
StatusMode
.
available
)
return
ChatAction
.
available
;
else
if
(
statusMode
==
StatusMode
.
away
)
return
ChatAction
.
away
;
else
if
(
mode
==
Mode
.
chat
)
else
if
(
statusMode
==
Status
Mode
.
chat
)
return
ChatAction
.
chat
;
else
if
(
mode
==
Mode
.
dnd
)
else
if
(
statusMode
==
Status
Mode
.
dnd
)
return
ChatAction
.
dnd
;
else
if
(
mode
==
Mode
.
xa
)
else
if
(
statusMode
==
Status
Mode
.
xa
)
return
ChatAction
.
xa
;
else
return
ChatAction
.
available
;
throw
new
IllegalStateException
()
;
}
/**
...
...
src/com/xabber/android/data/message/MessageManager.java
View file @
e510e180
...
...
@@ -43,6 +43,7 @@ import com.xabber.android.data.account.AccountManager;
import
com.xabber.android.data.account.ArchiveMode
;
import
com.xabber.android.data.account.OnAccountArchiveModeChangedListener
;
import
com.xabber.android.data.account.OnAccountRemovedListener
;
import
com.xabber.android.data.account.StatusMode
;
import
com.xabber.android.data.connection.ConnectionItem
;
import
com.xabber.android.data.connection.OnDisconnectListener
;
import
com.xabber.android.data.connection.OnPacketListener
;
...
...
@@ -50,6 +51,7 @@ import com.xabber.android.data.entity.BaseEntity;
import
com.xabber.android.data.entity.NestedMap
;
import
com.xabber.android.data.extension.archive.MessageArchiveManager
;
import
com.xabber.android.data.extension.muc.RoomChat
;
import
com.xabber.android.data.roster.OnStatusChangeListener
;
import
com.xabber.android.data.roster.OnRosterReceivedListener
;
import
com.xabber.android.data.roster.RosterManager
;
import
com.xabber.android.utils.StringUtils
;
...
...
@@ -67,7 +69,8 @@ import com.xabber.xmpp.delay.Delay;
*/
public
class
MessageManager
implements
OnLoadListener
,
OnPacketListener
,
OnDisconnectListener
,
OnAccountRemovedListener
,
OnRosterReceivedListener
,
OnAccountArchiveModeChangedListener
{
OnRosterReceivedListener
,
OnAccountArchiveModeChangedListener
,
OnStatusChangeListener
{
/**
* Registered chats for bareAddresses in accounts.
...
...
@@ -581,4 +584,28 @@ public class MessageManager implements OnLoadListener, OnPacketListener,
return
ids
;
}
private
boolean
isStatusTrackingEnabled
(
String
account
,
String
bareAddress
)
{
if
(
SettingsManager
.
chatsShowStatusChange
()
!=
ChatsShowStatusChange
.
always
)
return
false
;
AbstractChat
abstractChat
=
getChat
(
account
,
bareAddress
);
return
abstractChat
!=
null
&&
abstractChat
instanceof
RegularChat
&&
abstractChat
.
isStatusTrackingEnabled
();
}
@Override
public
void
onStatusChanged
(
String
account
,
String
bareAddress
,
String
resource
,
String
statusText
)
{
if
(
isStatusTrackingEnabled
(
account
,
bareAddress
))
getChat
(
account
,
bareAddress
).
newAction
(
resource
,
statusText
,
ChatAction
.
status
);
}
@Override
public
void
onStatusChanged
(
String
account
,
String
bareAddress
,
String
resource
,
StatusMode
statusMode
,
String
statusText
)
{
if
(
isStatusTrackingEnabled
(
account
,
bareAddress
))
getChat
(
account
,
bareAddress
).
newAction
(
resource
,
statusText
,
ChatAction
.
getChatAction
(
statusMode
));
}
}
src/com/xabber/android/data/message/RegularChat.java
View file @
e510e180
...
...
@@ -25,9 +25,7 @@ import org.jivesoftware.smackx.packet.MUCUser;
import
com.xabber.android.data.LogManager
;
import
com.xabber.android.data.NetworkException
;
import
com.xabber.android.data.SettingsManager
;
import
com.xabber.android.data.SettingsManager.ChatsShowStatusChange
;
import
com.xabber.android.data.SettingsManager.SecurityOtrMode
;
import
com.xabber.android.data.account.StatusMode
;
import
com.xabber.android.data.extension.archive.MessageArchiveManager
;
import
com.xabber.android.data.extension.otr.OTRManager
;
import
com.xabber.android.data.extension.otr.OTRUnencryptedException
;
...
...
@@ -50,21 +48,9 @@ public class RegularChat extends AbstractChat {
*/
private
String
resource
;
/**
* Previous status text.
*/
private
String
statusText
;
/**
* Previous status mode.
*/
private
StatusMode
statusMode
;
RegularChat
(
String
account
,
String
user
)
{
super
(
account
,
user
);
resource
=
null
;
statusMode
=
null
;
statusText
=
null
;
}
public
String
getResource
()
{
...
...
@@ -139,28 +125,6 @@ public class RegularChat extends AbstractChat {
&&
presence
.
getType
()
==
Presence
.
Type
.
unavailable
&&
this
.
resource
.
equals
(
resource
))
this
.
resource
=
null
;
if
(
presence
.
getType
()
==
Presence
.
Type
.
error
)
return
true
;
StatusMode
mode
=
StatusMode
.
createStatusMode
(
presence
);
String
status
=
presence
.
getStatus
();
ChatAction
action
;
boolean
skip
=
statusText
==
null
;
if
(
status
==
null
)
status
=
""
;
if
(
mode
==
statusMode
&&
status
.
equals
(
statusText
))
return
true
;
if
(
mode
!=
statusMode
)
{
statusMode
=
mode
;
action
=
ChatAction
.
getChatAction
(
presence
);
}
else
{
action
=
ChatAction
.
status
;
}
statusText
=
status
;
if
(
skip
||
!
active
)
return
true
;
if
(
SettingsManager
.
chatsShowStatusChange
()
!=
ChatsShowStatusChange
.
always
)
return
true
;
newAction
(
resource
,
status
,
action
);
}
else
if
(
packet
instanceof
Message
)
{
final
Message
message
=
(
Message
)
packet
;
if
(
message
.
getType
()
==
Message
.
Type
.
error
)
...
...
src/com/xabber/android/data/roster/AbstractContact.java
View file @
e510e180
...
...
@@ -53,19 +53,11 @@ public class AbstractContact extends BaseEntity {
}
public
StatusMode
getStatusMode
()
{
ResourceItem
resourceItem
=
PresenceManager
.
getInstance
()
.
getResourceItem
(
account
,
user
);
if
(
resourceItem
==
null
)
return
StatusMode
.
unavailable
;
return
resourceItem
.
getStatusMode
();
return
PresenceManager
.
getInstance
().
getStatusMode
(
account
,
user
);
}
public
String
getStatusText
()
{
ResourceItem
resourceItem
=
PresenceManager
.
getInstance
()
.
getResourceItem
(
account
,
user
);
if
(
resourceItem
==
null
)
return
""
;
return
resourceItem
.
getStatusText
();
return
PresenceManager
.
getInstance
().
getStatusText
(
account
,
user
);
}
public
ClientSoftware
getClientSoftware
()
{
...
...
src/com/xabber/android/data/roster/OnStatusChangeListener.java
0 → 100644
View file @
e510e180
/**
* Copyright (c) 2013, Redsolution LTD. All rights reserved.
*
* This file is part of Xabber project; you can redistribute it and/or
* modify it under the terms of the GNU General Public License, Version 3.
*
* Xabber is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License,
* along with this program. If not, see http://www.gnu.org/licenses/.
*/
package
com
.
xabber
.
android
.
data
.
roster
;
import
com.xabber.android.data.BaseManagerInterface
;
import
com.xabber.android.data.account.StatusMode
;
/**
* Listen for changes in presence.
*
* @author alexander.ivanov
*
*/
public
interface
OnStatusChangeListener
extends
BaseManagerInterface
{
/**
* Notify when only status text changed.
*
* @param account
* @param bareAddress
* @param resource
* @param statusText
*/
void
onStatusChanged
(
String
account
,
String
bareAddress
,
String
resource
,
String
statusText
);
/**
* Notify when status mode changed.
*
* @param account
* @param bareAddress
* @param resource
* @param statusMode
* @param statusText
*/
void
onStatusChanged
(
String
account
,
String
bareAddress
,
String
resource
,
StatusMode
statusMode
,
String
statusText
);
}
src/com/xabber/android/data/roster/PresenceManager.java
View file @
e510e180
...
...
@@ -207,6 +207,20 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener,
return
container
.
getResourceItems
();
}
public
StatusMode
getStatusMode
(
String
account
,
String
bareAddress
)
{
ResourceItem
resourceItem
=
getResourceItem
(
account
,
bareAddress
);
if
(
resourceItem
==
null
)
return
StatusMode
.
unavailable
;
return
resourceItem
.
getStatusMode
();
}
public
String
getStatusText
(
String
account
,
String
bareAddress
)
{
ResourceItem
resourceItem
=
getResourceItem
(
account
,
bareAddress
);
if
(
resourceItem
==
null
)
return
""
;
return
resourceItem
.
getStatusText
();
}
@Override
public
void
onPacket
(
ConnectionItem
connection
,
String
bareAddress
,
Packet
packet
)
{
...
...
@@ -241,7 +255,10 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener,
resourceItem
=
null
;
else
resourceItem
=
resourceContainer
.
get
(
resource
);
StatusMode
previousStatusMode
=
getStatusMode
(
account
,
bareAddress
);
String
previousStatusText
=
getStatusText
(
account
,
bareAddress
);
if
(
presence
.
getType
()
==
Type
.
available
)
{
StatusMode
statusMode
=
StatusMode
.
createStatusMode
(
presence
);
String
statusText
=
presence
.
getStatus
();
int
priority
=
presence
.
getPriority
();
if
(
statusText
==
null
)
...
...
@@ -255,13 +272,11 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener,
resourceContainer
);
}
resourceContainer
.
put
(
resource
,
new
ResourceItem
(
verbose
,
StatusMode
.
createStatusMode
(
presence
),
statusText
,
priority
));
statusMode
,
statusText
,
priority
));
resourceContainer
.
updateBest
();
}
else
{
resourceItem
.
setVerbose
(
verbose
);
resourceItem
.
setStatusMode
(
StatusMode
.
createStatusMode
(
presence
));
resourceItem
.
setStatusMode
(
statusMode
);
resourceItem
.
setStatusText
(
statusText
);
resourceItem
.
setPriority
(
priority
);
resourceContainer
.
updateBest
();
...
...
@@ -276,6 +291,22 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener,
resourceContainer
.
updateBest
();
}
}
// Notify about changes
StatusMode
newStatusMode
=
getStatusMode
(
account
,
bareAddress
);
String
newStatusText
=
getStatusText
(
account
,
bareAddress
);
if
(
previousStatusMode
!=
newStatusMode
||
!
previousStatusText
.
equals
(
newStatusText
))
for
(
OnStatusChangeListener
listener
:
Application
.
getInstance
()
.
getManagers
(
OnStatusChangeListener
.
class
))
if
(
previousStatusMode
==
newStatusMode
)
listener
.
onStatusChanged
(
account
,
bareAddress
,
resource
,
newStatusText
);
else
listener
.
onStatusChanged
(
account
,
bareAddress
,
resource
,
newStatusMode
,
newStatusText
);
RosterContact
rosterContact
=
RosterManager
.
getInstance
()
.
getRosterContact
(
account
,
bareAddress
);
if
(
rosterContact
!=
null
)
{
...
...
@@ -286,6 +317,7 @@ public class PresenceManager implements OnArchiveModificationsReceivedListener,
OnRosterChangedListener
.
class
))
listener
.
onPresenceChanged
(
rosterContacts
);
}
RosterManager
.
getInstance
().
onContactChanged
(
account
,
bareAddress
);
}
else
if
(
packet
instanceof
RosterPacket
&&
((
RosterPacket
)
packet
).
getType
()
!=
IQ
.
Type
.
ERROR
)
{
...
...
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