Skip to content
This repository has been archived by the owner on Sep 2, 2021. It is now read-only.

Commit

Permalink
progress on #407 bookmarks
Browse files Browse the repository at this point in the history
- now adds and removes bookmarks as needed
- still need to implement loading of bookmarks from server for new accounts
  • Loading branch information
iamironrabbit committed May 30, 2018
1 parent b7bfc6c commit 52de466
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -654,7 +654,6 @@ public void reconnectAll ()
ChatGroup group = mGroups.get(muc.getRoom().toString());

addMucListeners(reMuc, group);
// mBookmarkManager.addBookmarkedConference(muc.getSubject(),muc.getRoom(),true,muc.getNickname(),null);

} catch (Exception e) {
Log.w(TAG,"unable to join MUC: " + e.getMessage());
Expand Down Expand Up @@ -729,6 +728,8 @@ public void autoJoinFailed(MultiUserChat multiUserChat, Exception e) {
if (chatGroup != null && muc !=null)
{

mBookmarkManager.addBookmarkedConference(muc.getSubject(),muc.getRoom(),true,muc.getNickname(),null);

if (!muc.isJoined()) {
DiscussionHistory history = new DiscussionHistory();
muc.createOrJoin(Resourcepart.from(nickname), null, history, SmackConfiguration.getDefaultPacketReplyTimeout());
Expand All @@ -754,6 +755,9 @@ public void autoJoinFailed(MultiUserChat multiUserChat, Exception e) {

muc = mucMgr.getMultiUserChat(JidCreate.entityBareFrom(chatRoomJid));
boolean mucCreated = false;

// mBookmarkManager.addBookmarkedConference(muc.getSubject(),muc.getRoom(),true,muc.getNickname(),null);

try {
if (!muc.isJoined()) {
DiscussionHistory history = new DiscussionHistory();
Expand Down Expand Up @@ -782,6 +786,7 @@ public void autoJoinFailed(MultiUserChat multiUserChat, Exception e) {
mMUCs.put(chatRoomJid, muc);

if (mucCreated) {

try {

int historyFetchMax = 20;
Expand Down Expand Up @@ -906,7 +911,6 @@ public void autoJoinFailed(MultiUserChat multiUserChat, Exception e) {
}

addMucListeners(muc,chatGroup);
// mBookmarkManager.addBookmarkedConference(muc.getSubject(),muc.getRoom(),true,muc.getNickname(),null);

return true;

Expand Down Expand Up @@ -971,6 +975,8 @@ public void joinChatGroupAsync(Address address, String reason) {
if (mConnection == null || (!mConnection.isConnected()))
return;

mBookmarkManager.addBookmarkedConference(address.getUser(),JidCreate.entityBareFrom(chatRoomJid),true,null,null);

// Create a MultiUserChat using a Connection for a room
MultiUserChatManager mucMgr = MultiUserChatManager.getInstanceFor(mConnection);
mucMgr.setAutoJoinOnReconnect(true);
Expand All @@ -993,7 +999,7 @@ public void joinChatGroupAsync(Address address, String reason) {
mMUCs.put(chatRoomJid, muc);

addMucListeners(muc, chatGroup);
// mBookmarkManager.addBookmarkedConference(muc.getSubject(),muc.getRoom(),true,muc.getNickname(),null);

} catch (Exception e) {
debug(TAG,"error joining MUC",e);
}
Expand Down Expand Up @@ -1118,7 +1124,8 @@ public void subjectUpdated(String subject, EntityFullJid from) {
XmppAddress xa = new XmppAddress(from.toString());
MultiUserChat muc = mChatGroupManager.getMultiUserChat(xa.getBareAddress());
ChatGroup chatGroup = mChatGroupManager.getChatGroup(xa);
chatGroup.setName(subject);
if (chatGroup != null)
chatGroup.setName(subject);
}
}
};
Expand Down Expand Up @@ -1206,6 +1213,11 @@ public void leaveChatGroupAsync(ChatGroup group) {

if (mMUCs.containsKey(chatRoomJid))
{
try {
mBookmarkManager.removeBookmarkedConference(JidCreate.entityBareFrom(chatRoomJid));
}
catch (Exception e){}

MultiUserChat muc = mMUCs.get(chatRoomJid);
try {
muc.leave();
Expand All @@ -1218,10 +1230,6 @@ public void leaveChatGroupAsync(ChatGroup group) {

mMUCs.remove(chatRoomJid);

try {
// mBookmarkManager.removeBookmarkedConference(JidCreate.entityBareFrom(chatRoomJid));
}
catch (Exception e){}
}

}
Expand Down Expand Up @@ -1776,7 +1784,7 @@ public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc,
if (participant != null)
session = mSessionManager.createChatSession(participant, true);

if (session != null)
if (session != null && session.getParticipant() != null)
((ChatGroup) session.getParticipant()).setName(muc.getSubject());


Expand All @@ -1798,9 +1806,6 @@ public void invitationReceived(XMPPConnection xmppConnection, MultiUserChat muc,

conn.login(mUsername, mPassword, Resourcepart.from(mResource));

//mStreamHandler.notifyInitialLogin();
initServiceDiscovery();

mChatStateManager = ChatStateManager.getInstance(conn);

getContactListManager().loadContactListsAsync();
Expand Down Expand Up @@ -2337,7 +2342,10 @@ public void run() {
public void connected(XMPPConnection connection) {
debug(TAG, "connected");

try { initOmemo((XMPPTCPConnection)connection); }
try {
initOmemo((XMPPTCPConnection)connection);

}
catch (Exception e)
{
debug("OMEMO","There was a problem init'g omemo",e);
Expand All @@ -2355,6 +2363,8 @@ public void authenticated(XMPPConnection connection, boolean resumed) {
ReconnectionManager manager = ReconnectionManager.getInstanceFor(mConnection);
manager.disableAutomaticReconnection();

initServiceDiscovery();

}

@Override
Expand Down Expand Up @@ -2709,7 +2719,7 @@ private ChatSession findOrCreateSession(String address, boolean groupChat, boole
if (session == null) {
ImEntity participant = findOrCreateParticipant(xAddr.getAddress(), true);
session = mSessionManager.createChatSession(participant, true);
if (session != null)
if (session != null && session.getParticipant() != null)
((ChatGroup) session.getParticipant()).setName(muc.getSubject());
}
}
Expand Down Expand Up @@ -3159,12 +3169,6 @@ private void do_loadContactLists() {
return;
}

mLastActivityManager = LastActivityManager.getInstanceFor(mConnection);
mLastActivityManager.enable();

mBookmarkManager = BookmarkManager.getBookmarkManager(mConnection);
mPrivateManager = PrivateDataManager.getInstanceFor(mConnection);

ContactList cl;

try {
Expand Down Expand Up @@ -4106,6 +4110,24 @@ private void initServiceDiscovery() {
DeliveryReceiptManager.getInstanceFor(mConnection).autoAddDeliveryReceiptRequests();
DeliveryReceiptManager.getInstanceFor(mConnection).setAutoReceiptMode(DeliveryReceiptManager.AutoReceiptMode.disabled);

mLastActivityManager = LastActivityManager.getInstanceFor(mConnection);
mLastActivityManager.enable();

mBookmarkManager = BookmarkManager.getBookmarkManager(mConnection);
mPrivateManager = PrivateDataManager.getInstanceFor(mConnection);

try {
debug(TAG,"is Private Data supported?" + mPrivateManager.isSupported());
} catch (SmackException.NoResponseException e) {
e.printStackTrace();
} catch (SmackException.NotConnectedException e) {
e.printStackTrace();
} catch (InterruptedException e) {
e.printStackTrace();
} catch (XMPPException.XMPPErrorException e) {
e.printStackTrace();
}

}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@ public IChatSession createMultiUserChatSession(String roomAddress, String subjec
groupMan.createChatGroupAsync(roomAddress, subject, nickname);

ChatGroup chatGroup = groupMan.getChatGroup(address);
chatGroup.setName(subject);
if (chatGroup != null)
chatGroup.setName(subject);

if (chatGroup != null && mConnection.getState() == ImConnection.LOGGED_IN)
{
Expand Down

0 comments on commit 52de466

Please sign in to comment.