mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-29 08:48:18 -05:00
Replace reddit_first cookie with client side logic.
This commit is contained in:
@@ -107,7 +107,7 @@ from r2.models import (
|
||||
NEVER = datetime(2037, 12, 31, 23, 59, 59)
|
||||
DELETE = datetime(1970, 01, 01, 0, 0, 1)
|
||||
|
||||
cache_affecting_cookies = ('reddit_first', 'over18', '_options')
|
||||
cache_affecting_cookies = ('over18', '_options')
|
||||
|
||||
class Cookies(dict):
|
||||
def add(self, name, value, *k, **kw):
|
||||
@@ -287,45 +287,6 @@ def read_mod_cookie():
|
||||
if cook:
|
||||
set_user_cookie('mod', '')
|
||||
|
||||
def firsttime():
|
||||
if (request.user_agent and
|
||||
('iphone' in request.user_agent.lower() or
|
||||
'android' in request.user_agent.lower()) and
|
||||
not get_redditfirst('mobile_suggest')):
|
||||
set_redditfirst('mobile_suggest', 'first')
|
||||
return 'mobile_suggest'
|
||||
elif get_redditfirst('firsttime'):
|
||||
return False
|
||||
else:
|
||||
set_redditfirst('firsttime', 'first')
|
||||
return True
|
||||
|
||||
def get_redditfirst(key, default=None):
|
||||
try:
|
||||
val = c.cookies['reddit_first'].value
|
||||
# on cookie presence, return as much
|
||||
if default is None:
|
||||
default = True
|
||||
cookie = simplejson.loads(val)
|
||||
return cookie[key]
|
||||
except (ValueError, TypeError, KeyError), e:
|
||||
# it's not a proper json dict, or the cookie isn't present, or
|
||||
# the key isn't part of the cookie; we don't really want a
|
||||
# broken cookie to propogate an exception up
|
||||
return default
|
||||
|
||||
def set_redditfirst(key, val):
|
||||
try:
|
||||
cookie = simplejson.loads(c.cookies['reddit_first'].value)
|
||||
cookie[key] = val
|
||||
except (ValueError, TypeError, KeyError), e:
|
||||
# invalid JSON data; we'll just construct a new cookie
|
||||
cookie = {key: val}
|
||||
|
||||
c.cookies['reddit_first'] = Cookie(simplejson.dumps(cookie),
|
||||
expires=NEVER)
|
||||
|
||||
|
||||
def over18():
|
||||
if c.user.pref_over_18 or c.user_is_admin:
|
||||
return True
|
||||
@@ -693,7 +654,6 @@ class MinimalController(BaseController):
|
||||
c.cname,
|
||||
request.fullpath,
|
||||
c.over18,
|
||||
c.firsttime,
|
||||
c.extension,
|
||||
c.render_style,
|
||||
cookies_key)
|
||||
@@ -940,8 +900,6 @@ class RedditController(MinimalController):
|
||||
for cookietype, count in cookie_counts.iteritems():
|
||||
g.stats.simple_event("cookie.%s" % cookietype, count)
|
||||
|
||||
c.firsttime = firsttime()
|
||||
|
||||
# the user could have been logged in via one of the feeds
|
||||
maybe_admin = False
|
||||
is_otpcookie_valid = False
|
||||
|
||||
@@ -170,9 +170,6 @@ class Reddit(Templated):
|
||||
infotext = strings.heavy_load_msg
|
||||
elif g.read_only_mode:
|
||||
infotext = strings.read_only_msg
|
||||
elif (c.firsttime == 'mobile_suggest' and
|
||||
c.render_style != 'compact'):
|
||||
infotext = strings.iphone_first
|
||||
elif g.live_config.get("announcement_message"):
|
||||
infotext = g.live_config["announcement_message"]
|
||||
|
||||
@@ -189,7 +186,7 @@ class Reddit(Templated):
|
||||
if not self.infobar:
|
||||
self.infobar = InfoBar(message=strings.all_minus_gold_only, extra_class="gold")
|
||||
|
||||
if c.firsttime:
|
||||
if not c.user_is_loggedin:
|
||||
self.welcomebar = WelcomeBar()
|
||||
|
||||
self.srtopbar = None
|
||||
|
||||
@@ -121,7 +121,7 @@ string_dict = dict(
|
||||
|
||||
submit_link = _("""You are submitting a link. The key to a successful submission is interesting content and a descriptive title."""),
|
||||
submit_text = _("""You are submitting a text-based post. Speak your mind. A title is required, but expanding further in the text field is not. Beginning your title with "vote up if" is violation of intergalactic law."""),
|
||||
iphone_first = _("You should consider using [reddit's mobile interface](http://i.reddit.com/)."),
|
||||
compact_suggest = _("Looks like you're browsing on a small screen. Would you like to try [reddit's mobile interface](%(url)s)?"),
|
||||
verify_email = _("we're going to need to verify your email address for you to proceed."),
|
||||
verify_email_submit = _("you'll be able to submit more frequently once you verify your email address"),
|
||||
email_verified = _("your email address has been verfied"),
|
||||
|
||||
@@ -1170,6 +1170,7 @@ a.author { margin-right: 0.5em; }
|
||||
}
|
||||
|
||||
.infobar.welcome {
|
||||
display: none;
|
||||
background: url(../welcome-lines.png) top center;
|
||||
border: 1px solid #ff8b60;
|
||||
padding: 0;
|
||||
|
||||
@@ -1,3 +1,33 @@
|
||||
r.ui.init = function() {
|
||||
// welcome bar
|
||||
if ($.cookie('reddit_first')) {
|
||||
// save welcome seen state and delete obsolete cookie
|
||||
$.cookie('reddit_first', null, {domain: r.config.cur_domain})
|
||||
store.set('ui.shown.welcome', true)
|
||||
} else if (store.get('ui.shown.welcome') != true) {
|
||||
$('.infobar.welcome').show()
|
||||
store.set('ui.shown.welcome', true)
|
||||
}
|
||||
|
||||
// mobile suggest infobar
|
||||
var smallScreen = window.matchMedia
|
||||
? matchMedia('(max-device-width: 700px)').matches
|
||||
: $(window).width() < 700,
|
||||
onFrontPage = $.url().attr('path') == '/'
|
||||
if (smallScreen && onFrontPage && r.config.renderstyle != 'compact') {
|
||||
var infobar = $('<div class="infobar mellow">')
|
||||
.html(r.utils.formatMarkdownLinks(
|
||||
r.strings('compact_suggest', {
|
||||
url: location + '.compact'
|
||||
})
|
||||
))
|
||||
$('body > .content > :not(.infobar):first').before(infobar)
|
||||
}
|
||||
|
||||
r.ui.HelpBubble.init()
|
||||
r.ui.PermissionEditor.init()
|
||||
}
|
||||
|
||||
r.ui.Form = function(el) {
|
||||
r.ui.Base.call(this, el)
|
||||
this.$el.submit($.proxy(function(e) {
|
||||
@@ -369,8 +399,3 @@ r.ui.PermissionEditor.prototype = $.extend(new r.ui.Base(), {
|
||||
this.hide()
|
||||
}
|
||||
})
|
||||
|
||||
r.ui.init = function() {
|
||||
r.ui.HelpBubble.init()
|
||||
r.ui.PermissionEditor.init()
|
||||
}
|
||||
|
||||
@@ -46,5 +46,12 @@ r.utils = {
|
||||
}
|
||||
return params[fieldName]
|
||||
})
|
||||
},
|
||||
|
||||
_mdLinkRe: /\[(.*?)\]\((.*?)\)/g,
|
||||
formatMarkdownLinks: function(str) {
|
||||
return _.escape(str).replace(this._mdLinkRe, function(match, text, url) {
|
||||
return '<a href="' + url + '">' + text + '</a>'
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,8 +32,6 @@
|
||||
</head>
|
||||
<body>
|
||||
<script type="text/javascript">
|
||||
$.cookie_write({name: "reddit_first", data: {firsttime: true},
|
||||
domain: "${c.site.domain}" });
|
||||
%if thing.login:
|
||||
$.cookie_write({name: "redditSession", data: "cname",
|
||||
domain: "${c.site.domain}" });
|
||||
|
||||
Reference in New Issue
Block a user