aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
diff options
context:
space:
mode:
Diffstat (limited to 'OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs')
-rw-r--r--OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs112
1 files changed, 83 insertions, 29 deletions
diff --git a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
index c75920d..76023bd 100644
--- a/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
+++ b/OpenSim/Region/CoreModules/Avatar/InstantMessage/OfflineMessageModule.cs
@@ -40,6 +40,13 @@ using OpenSim.Region.Framework.Scenes;
40 40
41namespace OpenSim.Region.CoreModules.Avatar.InstantMessage 41namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
42{ 42{
43 public struct SendReply
44 {
45 public bool Success;
46 public string Message;
47 public int Disposition;
48 }
49
43 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")] 50 [Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")]
44 public class OfflineMessageModule : ISharedRegionModule 51 public class OfflineMessageModule : ISharedRegionModule
45 { 52 {
@@ -50,6 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
50 private string m_RestURL = String.Empty; 57 private string m_RestURL = String.Empty;
51 IMessageTransferModule m_TransferModule = null; 58 IMessageTransferModule m_TransferModule = null;
52 private bool m_ForwardOfflineGroupMessages = true; 59 private bool m_ForwardOfflineGroupMessages = true;
60 private Dictionary<IClientAPI, List<UUID>> m_repliesSent= new Dictionary<IClientAPI, List<UUID>>();
53 61
54 public void Initialise(IConfigSource config) 62 public void Initialise(IConfigSource config)
55 { 63 {
@@ -169,11 +177,21 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
169 private void OnNewClient(IClientAPI client) 177 private void OnNewClient(IClientAPI client)
170 { 178 {
171 client.OnRetrieveInstantMessages += RetrieveInstantMessages; 179 client.OnRetrieveInstantMessages += RetrieveInstantMessages;
180 client.OnLogout += OnClientLoggedOut;
181 }
182
183 public void OnClientLoggedOut(IClientAPI client)
184 {
185 m_repliesSent.Remove(client);
172 } 186 }
173 187
174 private void RetrieveInstantMessages(IClientAPI client) 188 private void RetrieveInstantMessages(IClientAPI client)
175 { 189 {
176 if (m_RestURL != "") 190 if (m_RestURL == String.Empty)
191 {
192 return;
193 }
194 else
177 { 195 {
178 m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId); 196 m_log.DebugFormat("[OFFLINE MESSAGING]: Retrieving stored messages for {0}", client.AgentId);
179 197
@@ -181,28 +199,28 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
181 = SynchronousRestObjectRequester.MakeRequest<UUID, List<GridInstantMessage>>( 199 = SynchronousRestObjectRequester.MakeRequest<UUID, List<GridInstantMessage>>(
182 "POST", m_RestURL + "/RetrieveMessages/", client.AgentId); 200 "POST", m_RestURL + "/RetrieveMessages/", client.AgentId);
183 201
184 if (msglist == null) 202 if (msglist != null)
185 { 203 {
186 m_log.WarnFormat("[OFFLINE MESSAGING]: WARNING null message list."); 204 foreach (GridInstantMessage im in msglist)
187 return;
188 }
189
190 foreach (GridInstantMessage im in msglist)
191 {
192 if (im.dialog == (byte)InstantMessageDialog.InventoryOffered)
193 // send it directly or else the item will be given twice
194 client.SendInstantMessage(im);
195 else
196 { 205 {
197 // Send through scene event manager so all modules get a chance 206 if (im.dialog == (byte)InstantMessageDialog.InventoryOffered)
198 // to look at this message before it gets delivered. 207 // send it directly or else the item will be given twice
199 // 208 client.SendInstantMessage(im);
200 // Needed for proper state management for stored group 209 else
201 // invitations 210 {
202 // 211 // Send through scene event manager so all modules get a chance
203 Scene s = FindScene(client.AgentId); 212 // to look at this message before it gets delivered.
204 if (s != null) 213 //
205 s.EventManager.TriggerIncomingInstantMessage(im); 214 // Needed for proper state management for stored group
215 // invitations
216 //
217
218 im.offline = 1;
219
220 Scene s = FindScene(client.AgentId);
221 if (s != null)
222 s.EventManager.TriggerIncomingInstantMessage(im);
223 }
206 } 224 }
207 } 225 }
208 } 226 }
@@ -214,11 +232,13 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
214 im.dialog != (byte)InstantMessageDialog.MessageFromAgent && 232 im.dialog != (byte)InstantMessageDialog.MessageFromAgent &&
215 im.dialog != (byte)InstantMessageDialog.GroupNotice && 233 im.dialog != (byte)InstantMessageDialog.GroupNotice &&
216 im.dialog != (byte)InstantMessageDialog.GroupInvitation && 234 im.dialog != (byte)InstantMessageDialog.GroupInvitation &&
217 im.dialog != (byte)InstantMessageDialog.InventoryOffered) 235 im.dialog != (byte)InstantMessageDialog.InventoryOffered &&
236 im.dialog != (byte)InstantMessageDialog.TaskInventoryOffered)
218 { 237 {
219 return; 238 return;
220 } 239 }
221 240
241<<<<<<< HEAD
222 if (!m_ForwardOfflineGroupMessages) 242 if (!m_ForwardOfflineGroupMessages)
223 { 243 {
224 if (im.dialog == (byte)InstantMessageDialog.GroupNotice || 244 if (im.dialog == (byte)InstantMessageDialog.GroupNotice ||
@@ -228,6 +248,15 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
228 248
229 bool success = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>( 249 bool success = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>(
230 "POST", m_RestURL+"/SaveMessage/", im, 10000); 250 "POST", m_RestURL+"/SaveMessage/", im, 10000);
251=======
252 Scene scene = FindScene(new UUID(im.fromAgentID));
253 if (scene == null)
254 scene = m_SceneList[0];
255
256 SendReply reply = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, SendReply>(
257 "POST", m_RestURL+"/SaveMessage/?scope=" +
258 scene.RegionInfo.ScopeID.ToString(), im);
259>>>>>>> avn/ubitvar
231 260
232 if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent) 261 if (im.dialog == (byte)InstantMessageDialog.MessageFromAgent)
233 { 262 {
@@ -235,13 +264,38 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
235 if (client == null) 264 if (client == null)
236 return; 265 return;
237 266
238 client.SendInstantMessage(new GridInstantMessage( 267 if (reply.Message == String.Empty)
239 null, new UUID(im.toAgentID), 268 reply.Message = "User is not logged in. " + (reply.Success ? "Message saved." : "Message not saved");
240 "System", new UUID(im.fromAgentID), 269
241 (byte)InstantMessageDialog.MessageFromAgent, 270 bool sendReply = true;
242 "User is not logged in. "+ 271
243 (success ? "Message saved." : "Message not saved"), 272 switch (reply.Disposition)
244 false, new Vector3())); 273 {
274 case 0: // Normal
275 break;
276 case 1: // Only once per user
277 if (m_repliesSent.ContainsKey(client) && m_repliesSent[client].Contains(new UUID(im.toAgentID)))
278 {
279 sendReply = false;
280 }
281 else
282 {
283 if (!m_repliesSent.ContainsKey(client))
284 m_repliesSent[client] = new List<UUID>();
285 m_repliesSent[client].Add(new UUID(im.toAgentID));
286 }
287 break;
288 }
289
290 if (sendReply)
291 {
292 client.SendInstantMessage(new GridInstantMessage(
293 null, new UUID(im.toAgentID),
294 "System", new UUID(im.fromAgentID),
295 (byte)InstantMessageDialog.MessageFromAgent,
296 reply.Message,
297 false, new Vector3()));
298 }
245 } 299 }
246 } 300 }
247 } 301 }