Get Twitter search results into the page by async
This commit is contained in:
@@ -1792,7 +1792,6 @@
|
||||
<Content Include="Views\Partials\Community\TermsAndConditions.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Members\ForgotPassword.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Members\Login.cshtml" />
|
||||
<Content Include="Views\MacroPartials\Community\TwitterSearchUmbraco.cshtml" />
|
||||
<None Include="Views\Partials\Forum\MemberBadge.cshtml" />
|
||||
<Content Include="Views\Search\Search.aspx" />
|
||||
<Content Include="Views\Web.config" />
|
||||
|
||||
@@ -58,12 +58,23 @@
|
||||
@if (Members.IsLoggedIn())
|
||||
{
|
||||
@Html.Partial("home/forumactivity")
|
||||
@Html.Partial("home/twittersearchumbraco")
|
||||
<div id="twitter-search"></div>
|
||||
@Html.Partial("home/documentation")
|
||||
}
|
||||
else
|
||||
{
|
||||
@Html.Partial("home/documentation")
|
||||
@Html.Partial("home/forumactivity")
|
||||
@Html.Partial("home/twittersearchumbraco")
|
||||
<div id="twitter-search"></div>
|
||||
}
|
||||
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
try {
|
||||
$("#twitter-search").load("@Url.Action("TwitterSearchResult", "TwitterSearch")");
|
||||
}
|
||||
catch (err) {
|
||||
console.log("Couldn't load Twitter feed", err.message);
|
||||
}
|
||||
});
|
||||
</script>
|
||||
@@ -1,89 +0,0 @@
|
||||
@using System.Configuration
|
||||
@using OurUmbraco.Forum.Extensions
|
||||
@using Tweetinvi
|
||||
@using Tweetinvi.Models
|
||||
@using Tweetinvi.Parameters
|
||||
@using Umbraco.Core.Cache
|
||||
@using Umbraco.Core.Logging
|
||||
@inherits Umbraco.Web.Macros.PartialViewMacroPage
|
||||
|
||||
@{
|
||||
ITweet[] tweets = {};
|
||||
ITweet[] filteredTweets = {};
|
||||
try
|
||||
{
|
||||
tweets = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem<ITweet[]>("UmbracoSearchedTweets",
|
||||
() =>
|
||||
{
|
||||
Auth.SetUserCredentials(ConfigurationManager.AppSettings["twitterConsumerKey"],
|
||||
ConfigurationManager.AppSettings["twitterConsumerSecret"],
|
||||
ConfigurationManager.AppSettings["twitterUserAccessToken"],
|
||||
ConfigurationManager.AppSettings["twitterUserAccessSecret"]);
|
||||
var user = Tweetinvi.User.GetAuthenticatedUser();
|
||||
|
||||
var searchParameter = new SearchTweetsParameters("umbraco") {SearchType = SearchResultType.Recent};
|
||||
return Search.SearchTweets(searchParameter).ToArray();
|
||||
}, TimeSpan.FromMinutes(1));
|
||||
|
||||
// TODO: make configurable in Umbraco
|
||||
var usernameFilter = "Technologx,Technologx4Real,SOAzure,AdamSmith1,UriSamuels,coding_jobfeeds,TechSparkUk,ItProjectBoard,liveedutv,AdeboyejoAde,VivacitySocial".ToLowerInvariant().Split(',');
|
||||
var wordFilter = "exegesis,#Job Alert:".ToLowerInvariant().Split(',');
|
||||
|
||||
filteredTweets = tweets.Where(
|
||||
x => x.CreatedBy.UserIdentifier.ScreenName.ToLowerInvariant().ContainsAny(usernameFilter) == false
|
||||
&& x.Text.ToLowerInvariant().ContainsAny(wordFilter) == false).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<ITweet>("Could not get tweets", ex);
|
||||
}
|
||||
}
|
||||
|
||||
@if (filteredTweets.Any())
|
||||
{
|
||||
<section class="forum">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-12">
|
||||
<h1 class="text-center">Twitter Activity</h1>
|
||||
<p>
|
||||
Recent activity on twitter, where people are talking about Umbraco.
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<small>Recent tweets</small>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 flex">
|
||||
@Column(filteredTweets)
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 goto-forum">
|
||||
<a class="button green" href="https://twitter.com/search?f=tweets&vertical=default&q=umbraco&src=typd">Join the conversation on Twitter →</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
|
||||
@helper Column(ITweet[] tweets)
|
||||
{
|
||||
foreach (var tweet in tweets.Take(6))
|
||||
{
|
||||
<a href="@tweet.Url" class="forum-thread">
|
||||
|
||||
<div class="avatar">
|
||||
<img src="@tweet.CreatedBy.ProfileImageUrl400x400" />
|
||||
</div>
|
||||
|
||||
<div class="meta">
|
||||
<div class="forum-thread-text">
|
||||
<h3>@tweet.Text</h3>
|
||||
<p>@tweet.CreatedAt.ConvertToRelativeTime() by @@@tweet.CreatedBy.UserIdentifier.ScreenName (@tweet.CreatedBy.Name)</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
}
|
||||
}
|
||||
@@ -1,2 +1,52 @@
|
||||
@inherits Umbraco.Web.Macros.PartialViewMacroPage
|
||||
@Umbraco.RenderMacro("TwitterSearchUmbraco")
|
||||
@using OurUmbraco.Forum.Extensions
|
||||
@using Tweetinvi.Models
|
||||
@model ITweet[]
|
||||
|
||||
@if (Model.Any())
|
||||
{
|
||||
<section class="forum">
|
||||
<div class="container">
|
||||
<div class="row">
|
||||
|
||||
<div class="col-md-12">
|
||||
<h1 class="text-center">Twitter Activity</h1>
|
||||
<p>
|
||||
Recent activity on twitter, where people are talking about Umbraco.
|
||||
</p>
|
||||
</div>
|
||||
<div class="col-md-12">
|
||||
<small>Recent tweets</small>
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 flex">
|
||||
@Column(Model)
|
||||
</div>
|
||||
|
||||
<div class="col-md-12 goto-forum">
|
||||
<a class="button green" href="https://twitter.com/search?f=tweets&vertical=default&q=umbraco&src=typd">Join the conversation on Twitter →</a>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
</div>
|
||||
</section>
|
||||
}
|
||||
|
||||
@helper Column(ITweet[] tweets)
|
||||
{
|
||||
foreach (var tweet in tweets.Take(6))
|
||||
{
|
||||
<a href="@tweet.Url" class="forum-thread">
|
||||
|
||||
<div class="avatar">
|
||||
<img src="@tweet.CreatedBy.ProfileImageUrl400x400" />
|
||||
</div>
|
||||
|
||||
<div class="meta">
|
||||
<div class="forum-thread-text">
|
||||
<h3>@tweet.Text</h3>
|
||||
<p>@tweet.CreatedAt.ConvertToRelativeTime() by @@@tweet.CreatedBy.UserIdentifier.ScreenName (@tweet.CreatedBy.Name)</p>
|
||||
</div>
|
||||
</div>
|
||||
</a>
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Configuration;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Web.Mvc;
|
||||
using Tweetinvi;
|
||||
using Tweetinvi.Models;
|
||||
using Tweetinvi.Parameters;
|
||||
using Umbraco.Core;
|
||||
using Umbraco.Core.Cache;
|
||||
using Umbraco.Core.Logging;
|
||||
using Umbraco.Web.Mvc;
|
||||
|
||||
namespace OurUmbraco.Community.Controllers
|
||||
{
|
||||
public class TwitterSearchController : SurfaceController
|
||||
{
|
||||
public ActionResult TwitterSearchResult(string searchWord = "umbraco")
|
||||
{
|
||||
ITweet[] filteredTweets = { };
|
||||
try
|
||||
{
|
||||
var tweets = ApplicationContext.ApplicationCache.RuntimeCache.GetCacheItem<ITweet[]>("UmbracoSearchedTweets",
|
||||
() =>
|
||||
{
|
||||
Auth.SetUserCredentials(ConfigurationManager.AppSettings["twitterConsumerKey"],
|
||||
ConfigurationManager.AppSettings["twitterConsumerSecret"],
|
||||
ConfigurationManager.AppSettings["twitterUserAccessToken"],
|
||||
ConfigurationManager.AppSettings["twitterUserAccessSecret"]);
|
||||
Tweetinvi.User.GetAuthenticatedUser();
|
||||
|
||||
var searchParameter = new SearchTweetsParameters(searchWord) { SearchType = SearchResultType.Recent };
|
||||
return Search.SearchTweets(searchParameter).ToArray();
|
||||
|
||||
}, TimeSpan.FromMinutes(2));
|
||||
|
||||
var usernameFilter = "Technologx,Technologx4Real,SOAzure,AdamSmith1,AdamSmitht1,UriSamuels,coding_jobfeeds,TechSparkUk,ItProjectBoard,liveedutv,AdeboyejoAde,VivacitySocial,CHHCInc,DevOpsBlogs,ItCrowdSource,EquiKey".ToLowerInvariant().Split(',');
|
||||
var wordFilter = "exegesis,#Job Alert:,#pigefodboldbsf".ToLowerInvariant().Split(',');
|
||||
|
||||
filteredTweets = tweets.Where(
|
||||
x => x.Urls.Any(u => u.ExpandedURL.Contains("umbraco-proxy.com")) == false
|
||||
&& x.CreatedBy.UserIdentifier.ScreenName.ToLowerInvariant().ContainsAny(usernameFilter) == false
|
||||
&& x.Text.ToLowerInvariant().ContainsAny(wordFilter) == false).ToArray();
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<ITweet>("Could not get tweets", ex);
|
||||
}
|
||||
|
||||
return PartialView("~/Views/Partials/Home/TwitterSearchUmbraco.cshtml", filteredTweets);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -37,7 +37,6 @@ namespace OurUmbraco.Our
|
||||
AddMarkAsSolutionReminderSent();
|
||||
UseNewLoginForm();
|
||||
UseNewForgotPasswordForm();
|
||||
TwitterSearchMacro();
|
||||
}
|
||||
|
||||
private void EnsureMigrationsMarkerPathExists()
|
||||
@@ -638,40 +637,5 @@ namespace OurUmbraco.Our
|
||||
LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
|
||||
}
|
||||
}
|
||||
|
||||
private void TwitterSearchMacro()
|
||||
{
|
||||
var migrationName = MethodBase.GetCurrentMethod().Name;
|
||||
|
||||
try
|
||||
{
|
||||
var path = HostingEnvironment.MapPath(MigrationMarkersPath + migrationName + ".txt");
|
||||
if (File.Exists(path))
|
||||
return;
|
||||
|
||||
var macroService = ApplicationContext.Current.Services.MacroService;
|
||||
var macroAlias = "TwitterSearchUmbraco";
|
||||
if (macroService.GetByAlias(macroAlias) == null)
|
||||
{
|
||||
// Run migration
|
||||
|
||||
var macro = new Macro
|
||||
{
|
||||
Name = macroAlias,
|
||||
Alias = macroAlias,
|
||||
ScriptingFile = "~/Views/MacroPartials/Community/TwitterSearchUmbraco.cshtml",
|
||||
UseInEditor = true
|
||||
};
|
||||
macro.Save();
|
||||
}
|
||||
|
||||
string[] lines = { "" };
|
||||
File.WriteAllLines(path, lines);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
LogHelper.Error<MigrationsHandler>(string.Format("Migration: '{0}' failed", migrationName), ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -293,6 +293,10 @@
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.5.6\lib\TidyNet.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="Tweetinvi, Version=1.2.0.0, Culture=neutral, PublicKeyToken=7247f14397bf67b9, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\TweetinviAPI.1.2.0\lib\net45\Tweetinvi.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
</Reference>
|
||||
<Reference Include="umbraco, Version=1.0.6185.24089, Culture=neutral, processorArchitecture=MSIL">
|
||||
<HintPath>..\packages\UmbracoCms.Core.7.5.6\lib\umbraco.dll</HintPath>
|
||||
<Private>True</Private>
|
||||
@@ -340,6 +344,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="CamelCaseFormatter.cs" />
|
||||
<Compile Include="Community\Controllers\TwitterSearchController.cs" />
|
||||
<Compile Include="CustomDateTimeConvertor.cs" />
|
||||
<Compile Include="Documentation\Busineslogic\ConventionExtensions.cs" />
|
||||
<Compile Include="Documentation\Busineslogic\DefaultVersion.cs" />
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
<package id="RestSharp" version="104.1" targetFramework="net451" />
|
||||
<package id="semver" version="1.1.2" targetFramework="net452" />
|
||||
<package id="SharpZipLib" version="0.86.0" targetFramework="net452" />
|
||||
<package id="TweetinviAPI" version="1.2.0" targetFramework="net452" />
|
||||
<package id="UmbracoCms.Core" version="7.5.6" targetFramework="net452" />
|
||||
<package id="UmbracoCms.IdentityExtensions" version="1.0.0" targetFramework="net451" />
|
||||
<package id="UmbracoCms.IdentityExtensions.Google" version="1.0.0" targetFramework="net451" />
|
||||
|
||||
Reference in New Issue
Block a user