Change OfflineMessageModule to support more differentiated return values and allow support for mobile devices and other non-viewer logins

avinationmerge
Melanie Thielker 2014-04-06 23:22:37 +02:00
parent a30ad71651
commit bb841ea9ce
1 changed files with 47 additions and 8 deletions

View File

@ -40,6 +40,13 @@ using OpenSim.Region.Framework.Scenes;
namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
{
public struct SendReply
{
public bool Success;
public string Message;
public int Disposition;
}
[Extension(Path = "/OpenSim/RegionModules", NodeName = "RegionModule", Id = "OfflineMessageModule")]
public class OfflineMessageModule : ISharedRegionModule
{
@ -50,6 +57,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
private string m_RestURL = String.Empty;
IMessageTransferModule m_TransferModule = null;
private bool m_ForwardOfflineGroupMessages = true;
private Dictionary<IClientAPI, List<UUID>> m_repliesSent= new Dictionary<IClientAPI, List<UUID>>();
public void Initialise(IConfigSource config)
{
@ -169,6 +177,12 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
private void OnNewClient(IClientAPI client)
{
client.OnRetrieveInstantMessages += RetrieveInstantMessages;
client.OnLogout += OnClientLoggedOut;
}
public void OnClientLoggedOut(IClientAPI client)
{
m_repliesSent.Remove(client);
}
private void RetrieveInstantMessages(IClientAPI client)
@ -228,7 +242,7 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
if (scene == null)
scene = m_SceneList[0];
bool success = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, bool>(
SendReply reply = SynchronousRestObjectRequester.MakeRequest<GridInstantMessage, SendReply>(
"POST", m_RestURL+"/SaveMessage/?scope=" +
scene.RegionInfo.ScopeID.ToString(), im);
@ -238,13 +252,38 @@ namespace OpenSim.Region.CoreModules.Avatar.InstantMessage
if (client == null)
return;
client.SendInstantMessage(new GridInstantMessage(
null, new UUID(im.toAgentID),
"System", new UUID(im.fromAgentID),
(byte)InstantMessageDialog.MessageFromAgent,
"User is not logged in. "+
(success ? "Message saved." : "Message not saved"),
false, new Vector3()));
if (reply.Message == String.Empty)
reply.Message = "User is not logged in. " + (reply.Success ? "Message saved." : "Message not saved");
bool sendReply = true;
switch (reply.Disposition)
{
case 0: // Normal
break;
case 1: // Only once per user
if (m_repliesSent.ContainsKey(client) && m_repliesSent[client].Contains(new UUID(im.toAgentID)))
{
sendReply = false;
}
else
{
if (!m_repliesSent.ContainsKey(client))
m_repliesSent[client] = new List<UUID>();
m_repliesSent[client].Add(new UUID(im.toAgentID));
}
break;
}
if (sendReply)
{
client.SendInstantMessage(new GridInstantMessage(
null, new UUID(im.toAgentID),
"System", new UUID(im.fromAgentID),
(byte)InstantMessageDialog.MessageFromAgent,
reply.Message,
false, new Vector3()));
}
}
}
}