Skip to content

Commit

Permalink
Upgrade to v5.10.4
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jan 14, 2021
1 parent f4ce87b commit e0b87ef
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 9 deletions.
48 changes: 47 additions & 1 deletion src/Chat/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
using ServiceStack.Configuration;
using ServiceStack.Auth;
using ServiceStack.Mvc;
using ServiceStack.Script;

namespace Chat
{
Expand Down Expand Up @@ -211,6 +212,27 @@ public class ClearChatHistory : IReturnVoid { }
[Route("/reset-serverevents")]
public class ResetServerEvents : IReturnVoid { }

[Route("/channels/{Channel}/object")]
public class PostObjectToChannel : IReturnVoid
{
public string ToUserId { get; set; }
public string Channel { get; set; }
public string Selector { get; set; }

public CustomType CustomType { get; set; }
public SetterType SetterType { get; set; }
}
public class CustomType
{
public int Id { get; set; }
public string Name { get; set; }
}
public class SetterType
{
public int Id { get; set; }
public string Name { get; set; }
}

public class ServerEventsServices : Service
{
public IServerEvents ServerEvents { get; set; }
Expand Down Expand Up @@ -250,14 +272,20 @@ public async Task<object> Any(PostChatToChannel request)

var channel = request.Channel;

var chatMessage = request.Message.IndexOf("{{", StringComparison.Ordinal) >= 0
? await HostContext.AppHost.ScriptContext.RenderScriptAsync(request.Message, new Dictionary<string, object> {
[nameof(Request)] = Request
})
: request.Message;

// Create a DTO ChatMessage to hold all required info about this message
var msg = new ChatMessage
{
Id = ChatHistory.GetNextMessageId(channel),
Channel = request.Channel,
FromUserId = sub.UserId,
FromName = sub.DisplayName,
Message = PclExportClient.Instance.HtmlEncode(request.Message),
Message = chatMessage.HtmlEncode(),
};

// Check to see if this is a private message to a specific user
Expand Down Expand Up @@ -314,6 +342,24 @@ public void Any(ResetServerEvents request)
{
ServerEvents.Reset();
}

public async Task Any(PostObjectToChannel request)
{
if (request.ToUserId != null)
{
if (request.CustomType != null)
await ServerEvents.NotifyUserIdAsync(request.ToUserId, request.Selector ?? Selector.Id<CustomType>(), request.CustomType);
if (request.SetterType != null)
await ServerEvents.NotifyUserIdAsync(request.ToUserId, request.Selector ?? Selector.Id<SetterType>(), request.SetterType);
}
else
{
if (request.CustomType != null)
await ServerEvents.NotifyChannelAsync(request.Channel, request.Selector ?? Selector.Id<CustomType>(), request.CustomType);
if (request.SetterType != null)
await ServerEvents.NotifyChannelAsync(request.Channel, request.Selector ?? Selector.Id<SetterType>(), request.SetterType);
}
}
}

[Route("/account")]
Expand Down
21 changes: 13 additions & 8 deletions src/Chat/wwwroot/default.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -46,20 +46,25 @@
<div id="users"></div>
<div id="examples" data-click="sendCommand">
<span style="position:absolute; top: 2px; right:7px" data-click="toggleExamples">hide</span>
<h4><a href="https://sharpscript.net">Example #Script</a></h4>
<div>{{ 'Cool' |&gt; padRight(7,'.') |&gt; repeat(3) }}</div>
<div>{{#each range(17)}}{{it * it}} {{/each}}</div>
<div>My UserAgent: {{ Request.UserAgent }}</div>
<div>@@me What's my IP? {{ Request.RemoteIP }}</div>
<h4><a href="https://github.com/NetCoreApps/Chat#global-event-handlers">Example Commands</a></h4>
<div>/cmd.announce This is your captain speaking ...</div>
<div>/cmd.toggle$#channels</div>
<h4><a href="https://github.com/NetCoreApps/Chat#modifying-css-via-jquery">CSS</a></h4>
<div>/css.background-image url(http://bit.ly/1oQqhtm)</div>
<div>@@me /css.background-image url(http://bit.ly/1yIJOBH)</div>
<div>/css.background-image url(https://bit.ly/3qho6GV)</div>
<div>@@me /css.background-image url(https://bit.ly/3qgNcWy)</div>
<div>/css.background$#top #673ab7</div>
<div>/css.background$#bottom #0091ea</div>
<div>/css.background$#right #fffde7</div>
<div>/css.color$#welcome #ff0</div>
<div>/css.visibility$img,a hidden</div>
<div>/css.visibility$img,a visible</div>
<h4><a href="https://github.com/NetCoreApps/Chat#receivers">Receivers</a></h4>
<div>/tv.watch http://youtu.be/518XP8prwZo</div>
<div>/tv.watch https://youtu.be/518XP8prwZo</div>
<div>/tv.watch https://servicestack.net/img/logo-220.png</div>
<div>@@me /tv.off</div>
<div>/document.title New Window Title</div>
Expand Down Expand Up @@ -164,7 +169,7 @@
$(this).toggle();
},
sendCommand: function () {
$("#txtMsg").val($(this).html()).focus();
$("#txtMsg").val($(this).text()).focus();
},
privateMsg: function () {
$txtMsg.val("@@" + this.innerHTML + " ").focus();
Expand Down Expand Up @@ -246,20 +251,20 @@
$txtMsg.keydown(function (e) {
var keycode = (e.keyCode ? e.keyCode : e.which);
if ($.ss.getSelection()) {
if (keycode == '9' || keycode == '13' || keycode == '32' || keycode == '39') {
if (keycode === 9 || keycode === 13 || keycode === 32 || keycode === 39) {
this.value += " ";
if (this.setSelectionRange) this.setSelectionRange(this.value.length, this.value.length);
return false;
}
}
if (keycode == '13') { //enter
if (keycode === 13) { //enter
postMsg();
} else if (keycode == '38') { //up arrow
} else if (keycode === 38) { //up arrow
historyIndex = Math.min(++historyIndex, msgHistory.length);
$txtMsg.val(msgHistory[msgHistory.length - 1 - historyIndex]);
return false;
}
else if (keycode == '40') { //down arrow
else if (keycode === 40) { //down arrow
historyIndex = Math.max(--historyIndex, -1);
$txtMsg.val(msgHistory[msgHistory.length - 1 - historyIndex]);
} else {
Expand Down

0 comments on commit e0b87ef

Please sign in to comment.