Skip to content

Commit

Permalink
Merge 3d5928d into 1a583ab
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonyi committed Jul 12, 2019
2 parents 1a583ab + 3d5928d commit 373e550
Show file tree
Hide file tree
Showing 10 changed files with 89 additions and 37 deletions.
4 changes: 2 additions & 2 deletions lib/src/auth.dart
Expand Up @@ -40,7 +40,7 @@ final Logger _logger = Logger('Authenticator');
abstract class Authenticator {
oauth2.AuthorizationCodeGrant _grant;
oauth2.Client _client;
DRAWConfigContext _config;
final DRAWConfigContext _config;

Authenticator(DRAWConfigContext config, oauth2.AuthorizationCodeGrant grant)
: _config = config,
Expand Down Expand Up @@ -421,7 +421,7 @@ class ReadOnlyAuthenticator extends Authenticator {
/// [documentation](https://github.com/reddit/reddit/wiki/OAuth2-App-Types)
/// for descriptions of valid app types.
class WebAuthenticator extends Authenticator {
Uri _redirect;
final Uri _redirect;

WebAuthenticator._(
DRAWConfigContext config, oauth2.AuthorizationCodeGrant grant)
Expand Down
6 changes: 4 additions & 2 deletions lib/src/listing/listing_generator.dart
Expand Up @@ -22,9 +22,11 @@ abstract class ListingGenerator {

static Stream<T> createBasicGenerator<T>(
final Reddit reddit, final String path,
{Map<String, String> params, bool objectify = true}) =>
{int limit, Map<String, String> params, bool objectify = true}) =>
generator<T>(reddit, path,
limit: getLimit(params), params: params, objectify: objectify);
limit: limit ?? getLimit(params),
params: params,
objectify: objectify);

/// An asynchronous iterator method used to make Reddit API calls as defined
/// by [api] in blocks of size [limit]. The default [limit] is specified by
Expand Down
40 changes: 29 additions & 11 deletions lib/src/listing/mixins/base.dart
Expand Up @@ -76,7 +76,8 @@ mixin BaseListingMixin {
Reddit get reddit;
String get path;

Stream<UserContent> _buildGenerator(Map<String, String> params, String sort) {
Stream<UserContent> _buildGenerator(
int limit, Map<String, String> params, String sort) {
Map<String, String> _params = params;
if ((this is RedditorRef) || (this is SubListing)) {
var arg = '';
Expand All @@ -86,41 +87,58 @@ mixin BaseListingMixin {
_params ??= Map<String, String>();
_params['sort'] = sort;
return ListingGenerator.generator<UserContent>(reddit, path + arg,
limit: ListingGenerator.getLimit(params), params: _params);
limit: limit ?? ListingGenerator.getLimit(params), params: _params);
}
return ListingGenerator.generator<UserContent>(reddit, path + sort,
limit: ListingGenerator.getLimit(_params), params: _params);
limit: limit ?? ListingGenerator.getLimit(_params), params: _params);
}

Stream<UserContent> _buildTimeFilterGenerator(
Stream<UserContent> _buildTimeFilterGenerator(int limit,
Map<String, String> params, String sort, TimeFilter timeFilter) {
if (timeFilter == null) {
throw DRAWArgumentError('Argument "timeFilter" cannot be null');
}
final _params = params ?? Map();
_params['t'] = timeFilterToString(timeFilter);
return _buildGenerator(_params, sort);
return _buildGenerator(limit, _params, sort);
}

/// Returns a [Stream] of controversial comments and submissions. [timeFilter]
/// is used to filter comments and submissions by time period.
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
Stream<UserContent> controversial(
{TimeFilter timeFilter = TimeFilter.all,
int limit,
Map<String, String> params}) =>
_buildTimeFilterGenerator(params, 'controversial', timeFilter);
_buildTimeFilterGenerator(limit, params, 'controversial', timeFilter);

/// Returns a [Stream] of hot comments and submissions.
Stream<UserContent> hot({Map<String, String> params}) =>
_buildGenerator(params, 'hot');
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
Stream<UserContent> hot({int limit, Map<String, String> params}) =>
_buildGenerator(limit, params, 'hot');

/// Returns a [Stream] of the newest comments and submissions.
Stream<UserContent> newest({Map<String, String> params}) =>
_buildGenerator(params, 'new');
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
Stream<UserContent> newest({int limit, Map<String, String> params}) =>
_buildGenerator(limit, params, 'new');

/// Returns a [Stream] of the top comments and submissions. [timeFilter] is
/// used to filter comments and submissions by time period.
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
Stream<UserContent> top(
{TimeFilter timeFilter = TimeFilter.all,
int limit,
Map<String, String> params}) =>
_buildTimeFilterGenerator(params, 'top', timeFilter);
_buildTimeFilterGenerator(limit, params, 'top', timeFilter);
}
9 changes: 7 additions & 2 deletions lib/src/listing/mixins/gilded.dart
Expand Up @@ -16,8 +16,13 @@ mixin GildedListingMixin {
String get path;

/// Returns a [Stream] of content that has been gilded.
Stream<UserContentInitialized> gilded({Map<String, String> params}) =>
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
Stream<UserContentInitialized> gilded(
{int limit, Map<String, String> params}) =>
ListingGenerator.createBasicGenerator<UserContentInitialized>(
reddit, path + 'gilded',
params: params);
limit: limit, params: params);
}
40 changes: 30 additions & 10 deletions lib/src/listing/mixins/redditor.dart
Expand Up @@ -33,43 +33,63 @@ mixin RedditorListingMixin {

/// Returns a [Stream] of content that the user has downvoted.
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
///
/// May raise an exception on access if the current user is not authorized to
/// access this list.
Stream<UserContent> downvoted({Map<String, String> params}) =>
Stream<UserContent> downvoted({int limit, Map<String, String> params}) =>
ListingGenerator.createBasicGenerator(reddit, path + 'downvoted',
params: params);
limit: limit, params: params);

/// Returns a [Stream] of content that the user has gilded.
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
///
/// May raise an exception on access if the current user is not authorized to
/// access this list.
Stream<UserContent> gildings({Map<String, String> params}) =>
Stream<UserContent> gildings({int limit, Map<String, String> params}) =>
ListingGenerator.createBasicGenerator(reddit, path + 'gilded/given',
params: params);
limit: limit, params: params);

/// Returns a [Stream] of content that the user has hidden.
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
///
/// May raise an exception on access if the current user is not authorized to
/// access this list.
Stream<UserContent> hidden({Map<String, String> params}) =>
Stream<UserContent> hidden({int limit, Map<String, String> params}) =>
ListingGenerator.createBasicGenerator(reddit, path + 'hidden',
params: params);
limit: limit, params: params);

/// Returns a [Stream] of content that the user has saved.
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
///
/// May raise an exception on access if the current user is not authorized to
/// access this list.
Stream<UserContent> saved({Map<String, String> params}) =>
Stream<UserContent> saved({int limit, Map<String, String> params}) =>
ListingGenerator.createBasicGenerator(reddit, path + 'saved',
params: params);
limit: limit, params: params);

/// Returns a [Stream] of content that the user has upvoted.
///
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
///
/// May raise an exception on access if the current user is not authorized to
/// access this list.
Stream<UserContent> upvoted({Map<String, String> params}) =>
Stream<UserContent> upvoted({int limit, Map<String, String> params}) =>
ListingGenerator.createBasicGenerator(reddit, path + 'upvoted',
params: params);
limit: limit, params: params);
}

class SubListing extends Object with BaseListingMixin {
Expand Down
10 changes: 8 additions & 2 deletions lib/src/listing/mixins/rising.dart
Expand Up @@ -14,12 +14,18 @@ mixin RisingListingMixin {
String get path;

/// Returns a random [UserContent] that is "rising".
Stream<UserContent> randomRising({Map<String, String> params}) =>
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
Stream<UserContent> randomRising({int limit, Map<String, String> params}) =>
ListingGenerator.createBasicGenerator(reddit, path + 'randomrising',
params: params);

/// Returns a [UserContent] that is "rising".
Stream<UserContent> rising({Map<String, String> params}) =>
/// `limit` is the maximum number of objects returned by Reddit per request
/// (the default is 100). `params` is a set of additional parameters that
/// will be forwarded along with the request.
Stream<UserContent> rising({int limit, Map<String, String> params}) =>
ListingGenerator.createBasicGenerator(reddit, path + 'rising',
params: params);
}
5 changes: 3 additions & 2 deletions lib/src/listing/mixins/subreddit.dart
Expand Up @@ -29,9 +29,10 @@ class CommentHelper extends RedditBase with GildedListingMixin {
final SubredditRef _subreddit;
CommentHelper(this._subreddit) : super(_subreddit.reddit);

Stream<Comment> call({Map<String, String> params}) =>
// TODO(bkonyi): document.
Stream<Comment> call({int limit, Map<String, String> params}) =>
ListingGenerator.generator<Comment>(reddit, _path(),
limit: ListingGenerator.getLimit(params), params: params);
limit: limit ?? ListingGenerator.getLimit(params), params: params);

String _path() => _subreddit.path + 'comments/';
}
6 changes: 3 additions & 3 deletions lib/src/models/comment_impl.dart
Expand Up @@ -54,9 +54,9 @@ void setRepliesInternal(commentLike, CommentForest comments) {
class MoreComments extends RedditBase with RedditBaseInitializedMixin {
static final RegExp _submissionRegExp = RegExp(r'{id}');
List _comments;
List<String> _children;
int _count;
String _parentId;
final List<String> _children;
final int _count;
final String _parentId;
SubmissionRef _submission;

List get children => _children;
Expand Down
2 changes: 1 addition & 1 deletion lib/src/models/submission_impl.dart
Expand Up @@ -401,7 +401,7 @@ class Submission extends SubmissionRef
class SubmissionRef extends UserContent {
static final RegExp _submissionRegExp = RegExp(r'{id}');
CommentForest _comments;
String _id;
final String _id;
final Map _commentsById = Map();

SubmissionRef.withPath(Reddit reddit, String path)
Expand Down
4 changes: 2 additions & 2 deletions lib/src/models/subreddit.dart
Expand Up @@ -1144,7 +1144,7 @@ String modmailSortToString(ModmailSort s) {

/// Provides modmail functions for a [Subreddit].
class Modmail {
SubredditRef _subreddit;
final SubredditRef _subreddit;
Modmail._(this._subreddit);

String _buildSubredditList(List<SubredditRef> otherSubreddits) {
Expand Down Expand Up @@ -1293,7 +1293,7 @@ class Modmail {

/// A representation of the number of unread Modmail conversations by state.
class ModmailUnreadStatistics {
Map<String, int> _data;
final Map<String, int> _data;
ModmailUnreadStatistics._(this._data);

int get archived => _data['archived'];
Expand Down

0 comments on commit 373e550

Please sign in to comment.