Skip to content

Commit

Permalink
Merge branch 'master' of github.com:ringe/JoMAR
Browse files Browse the repository at this point in the history
  • Loading branch information
Overhead committed Dec 9, 2011
2 parents a50e82a + a90d8ee commit cd9e6c4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 2 deletions.
20 changes: 20 additions & 0 deletions JoMAR/Global.asax.cs
Expand Up @@ -107,17 +107,37 @@ public void CacheItemRemoved(string k, object v, CacheItemRemovedReason r)
{
string[] text = Regex.Split(sms.txt, @"\W+");
bool found = false;

// If UserName found, post to private room
if (users.Contains(text[0].ToLower()))
{
found = true;
Profile user1 = Profile.GetProfile(user);
Profile user2 = Profile.GetProfile(user);
ChatRoom room = Rooms.Private(user1, user2, db);

// Prepare message
string msg = "";
foreach (string s in text)
if (s != text[0])
msg += s + " ";

// Post message to room
Rooms.Post(msg, user1.UserId, room.RoomID, db);

// Forward message to the other user
SMS.Send(user1.UserName + " said: " + msg, "JoMAR", user2.CellPhone);
//Debug.WriteLine("Found message to user '" + text[0] + "'");
}

// If Room found, post.
if (rooms.Contains(text[0].ToLower()))
{
found = true;
//Debug.WriteLine("Found message to room '" + text[0] + "'");
}

// Reply with not found if no room found.
if (!found)
SMS.Send("Thanks for you interest in us, but we didn't find the user or room you seek.", "JoMAR", sms.snd);
}
Expand Down
1 change: 1 addition & 0 deletions JoMAR/JoMAR.csproj
Expand Up @@ -87,6 +87,7 @@
<Compile Include="Models\ChatModels.cs" />
<Compile Include="Models\GlobalModel.cs" />
<Compile Include="Models\Profile.cs" />
<Compile Include="Models\Rooms.cs" />
<Compile Include="Models\Tools.cs" />
<Compile Include="Models\SMS.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
Expand Down
21 changes: 21 additions & 0 deletions JoMAR/Models/Rooms.cs
Expand Up @@ -81,5 +81,26 @@ public static ChatRoom Public(string name, JodADataContext db)
else // Return the first room found
return rooms.First();
}

/// <summary>
/// Post message to room.
/// </summary>
/// <param name="msg">The message.</param>
/// <param name="user">The user id</param>
/// <param name="room">The room id</param>
/// <param name="db">JodADataContext</param>
public static void Post(string msg, Guid user, Guid room, JodADataContext db)
{
ChatMessage message = new ChatMessage();
message.Date = DateTime.Now;
message.MessageID = Guid.NewGuid();
message.UserID = user;
message.RoomID = room;
message.Text = msg;

// Submit message to DB
db.ChatMessages.InsertOnSubmit(message);
db.SubmitChanges();
}
}
}
6 changes: 4 additions & 2 deletions JoMAR/Views/Shared/_LogOnPartial.cshtml
@@ -1,5 +1,7 @@
@if(Request.IsAuthenticated) {
@Html.Raw(@ViewBag.Profile.Image)
@if(@ViewBag.Profile != null) {
@Html.Raw(@ViewBag.Profile.Image)
}
@if(Request.IsAuthenticated) {
<text>Welcome <strong>@User.Identity.Name</strong>!
[ @Html.ActionLink("Log Off", "LogOff", "Account") ]</text>
}
Expand Down

0 comments on commit cd9e6c4

Please sign in to comment.