106 */ |
106 */ |
107 @Override |
107 @Override |
108 public void destroyChat(IChat chat) throws RemoteException { |
108 public void destroyChat(IChat chat) throws RemoteException { |
109 // TODO gerer les resources egalement |
109 // TODO gerer les resources egalement |
110 Log.d(TAG, "destroy chat jid "+ chat.getParticipant().getJID()); |
110 Log.d(TAG, "destroy chat jid "+ chat.getParticipant().getJID()); |
111 ChatAdapter res = mChats.get(chat.getParticipant().getJID()); |
|
112 IChat c = mChats.remove(chat.getParticipant().getJID()); |
111 IChat c = mChats.remove(chat.getParticipant().getJID()); |
113 if (c == null) |
112 if (c == null) |
114 Log.w(TAG, "CA devrait pas 1!!" + chat.getParticipant().getJID()); |
113 Log.w(TAG, "CA devrait pas 1!!" + chat.getParticipant().getJID()); |
115 } |
114 } |
116 |
115 |
139 /** |
138 /** |
140 * {@inheritDoc} |
139 * {@inheritDoc} |
141 */ |
140 */ |
142 @Override |
141 @Override |
143 public void chatCreated(Chat chat, boolean locally) { |
142 public void chatCreated(Chat chat, boolean locally) { |
144 Log.d(TAG,"new chat"); |
|
145 IChat newchat = getChat(chat); |
143 IChat newchat = getChat(chat); |
146 if (!locally) { |
144 if (!locally) { |
147 // chat.addMessageListener(mChatListener); |
145 // chat.addMessageListener(mChatListener); |
148 Log.d(TAG, "new local chat"); |
|
149 notifyNewChat(newchat); |
146 notifyNewChat(newchat); |
150 } |
147 } |
151 else |
|
152 Log.d(TAG, "reuse local chat"); |
|
153 chat.addMessageListener(mChatListener); |
148 chat.addMessageListener(mChatListener); |
154 final int n = mRemoteChatCreationListeners.beginBroadcast(); |
149 final int n = mRemoteChatCreationListeners.beginBroadcast(); |
155 |
150 |
156 for (int i = 0; i < n; i++) { |
151 for (int i = 0; i < n; i++) { |
157 IChatManagerListener listener = mRemoteChatCreationListeners.getBroadcastItem(i); |
152 IChatManagerListener listener = mRemoteChatCreationListeners.getBroadcastItem(i); |
182 notif.setLatestEventInfo(mService, text, mService.getString(R.string.BeemChatManagerNewMessage), |
177 notif.setLatestEventInfo(mService, text, mService.getString(R.string.BeemChatManagerNewMessage), |
183 PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT)); |
178 PendingIntent.getActivity(mService, 0, intent, PendingIntent.FLAG_ONE_SHOT)); |
184 int id = chat.hashCode(); |
179 int id = chat.hashCode(); |
185 mService.sendNotification(id, notif); |
180 mService.sendNotification(id, notif); |
186 } catch (RemoteException e) { |
181 } catch (RemoteException e) { |
187 // TODO Auto-generated catch block |
182 Log.e(TAG, "notification error", e); |
188 e.printStackTrace(); |
|
189 } |
183 } |
190 } |
184 } |
191 |
185 |
192 @Override |
186 @Override |
193 public void processMessage(Chat chat, Message message) { |
187 public void processMessage(Chat chat, Message message) { |
194 IChat newchat = getChat(chat); |
188 IChat newchat = getChat(chat); |
|
189 |
195 try { |
190 try { |
|
191 |
196 if (message.getBody() != null) |
192 if (message.getBody() != null) |
197 newchat.addToLastMessages(message.getBody()); |
193 newchat.addToLastMessages(message.getBody()); |
198 final int n = mRemoteMessageListeners.beginBroadcast(); |
194 final int n = mRemoteMessageListeners.beginBroadcast(); |
199 for (int i = 0; i < n; i++) { |
195 for (int i = 0; i < n; i++) { |
200 IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i); |
196 IMessageListener listener = mRemoteMessageListeners.getBroadcastItem(i); |
201 listener.processMessage(newchat, new com.beem.project.beem.service.Message(message)); |
197 listener.processMessage(newchat, new com.beem.project.beem.service.Message(message)); |
202 } |
198 } |
203 mRemoteMessageListeners.finishBroadcast(); |
199 mRemoteMessageListeners.finishBroadcast(); |
|
200 if (newchat.isOpen() == false) { |
|
201 notifyNewChat(newchat); |
|
202 } |
204 } catch (RemoteException e) { |
203 } catch (RemoteException e) { |
205 // The RemoteCallbackList will take care of removing the |
204 // The RemoteCallbackList will take care of removing the |
206 // dead listeners. |
205 // dead listeners. |
207 Log.w(TAG, "Error while triggering remote connection listeners", e); |
206 Log.w(TAG, "Error while triggering remote connection listeners", e); |
208 } |
207 } |