Skip to content

Commit

Permalink
Prepare for 0.9.2 release
Browse files Browse the repository at this point in the history
  • Loading branch information
bkonyi committed Mar 25, 2021
1 parent 26a2593 commit c26065f
Show file tree
Hide file tree
Showing 37 changed files with 119 additions and 72 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
@@ -1,6 +1,9 @@
Change Log
=================================

## Version 0.9.2 (2021/03/25)
* Fixed issues with `limit` parameter for listing generators.

## Version 0.9.1 (2020/01/09)
* Fixed issue where `SubredditRef.search` would throw a type error.

Expand Down
1 change: 1 addition & 0 deletions lib/draw.dart
Expand Up @@ -21,6 +21,7 @@ export 'package:draw/src/listing/mixins/base.dart'
show BaseListingMixin, Sort, TimeFilter;
export 'package:draw/src/listing/mixins/gilded.dart';
export 'package:draw/src/listing/mixins/redditor.dart';
export 'package:draw/src/listing/mixins/rising.dart';
export 'package:draw/src/listing/mixins/subreddit.dart';
export 'package:draw/src/models/message.dart';
export 'package:draw/src/models/multireddit.dart'
Expand Down
7 changes: 4 additions & 3 deletions lib/src/listing/listing_generator.dart
Expand Up @@ -4,6 +4,7 @@
// can be found in the LICENSE file.

import 'dart:async';
import 'dart:developer';

import 'package:draw/src/reddit.dart';

Expand Down Expand Up @@ -44,12 +45,12 @@ abstract class ListingGenerator {
bool objectify = true}) async* {
final kLimitKey = 'limit';
final kAfterKey = 'after';
final nullLimit = 1024;
final nullLimit = 100;
final paramsInternal = (params == null)
? Map<String, String>()
: Map<String, String>.from(params);
final _limit = limit ?? nullLimit;
paramsInternal[kLimitKey] = _limit.toString();
final _limit = limit;
paramsInternal[kLimitKey] = (_limit ?? nullLimit).toString();

// If after is provided, we'll start getting objects older than the object
// ID specified.
Expand Down
58 changes: 50 additions & 8 deletions lib/src/models/mixins/voteable.dart
Expand Up @@ -15,6 +15,17 @@ enum VoteState {
downvoted,
}

int _voteStateToIndex(VoteState vote) {
switch (vote) {
case VoteState.none:
return 0;
case VoteState.upvoted:
return 1;
case VoteState.downvoted:
return -1;
}
}

/// A mixin which provides voting functionality for [Comment] and [Submission].
mixin VoteableMixin implements RedditBaseInitializedMixin {
Reddit get reddit;
Expand Down Expand Up @@ -46,22 +57,53 @@ mixin VoteableMixin implements RedditBaseInitializedMixin {
}
}

Future<void> _vote(String direction, bool waitForResponse) async {
void _updateScore(VoteState newVote) {
if (vote == VoteState.upvoted) {
if (newVote == VoteState.downvoted) {
data['score'] = score - 2;
} else if (newVote == VoteState.none) {
data['score'] = score - 1;
}
} else if (vote == VoteState.none) {
if (newVote == VoteState.downvoted) {
data['score'] = score - 1;
} else if (newVote == VoteState.upvoted) {
data['score'] = score + 1;
}
} else if (vote == VoteState.downvoted) {
if (newVote == VoteState.upvoted) {
data['score'] = score + 2;
} else if (newVote == VoteState.none) {
data['score'] = score + 1;
}
}
}

Future<void> _vote(VoteState direction, bool waitForResponse) async {
if (vote == direction) {
return;
}
final response = reddit.post(
apiPath['vote'], {'dir': direction, 'id': fullname},
apiPath['vote'],
{
'dir': _voteStateToIndex(direction).toString(),
'id': fullname,
},
discardResponse: true);
if (waitForResponse) {
await response;
}

_updateScore(direction);

switch (direction) {
case '0':
case VoteState.none:
data['likes'] = null;
break;
case '1':
case VoteState.upvoted:
data['likes'] = true;
break;
case '-1':
case VoteState.downvoted:
data['likes'] = false;
}
}
Expand All @@ -72,21 +114,21 @@ mixin VoteableMixin implements RedditBaseInitializedMixin {
/// voting by bots). See Reddit rules for more details on what is considered
/// vote cheating or manipulation.
Future<void> clearVote({bool waitForResponse = true}) async =>
_vote('0', waitForResponse);
_vote(VoteState.none, waitForResponse);

/// Clear the authenticated user's vote on the object.
///
/// Note: votes must be cast on behalf of a human user (i.e., no automatic
/// voting by bots). See Reddit rules for more details on what is considered
/// vote cheating or manipulation.
Future<void> downvote({bool waitForResponse = true}) async =>
_vote('-1', waitForResponse);
_vote(VoteState.downvoted, waitForResponse);

/// Clear the authenticated user's vote on the object.
///
/// Note: votes must be cast on behalf of a human user (i.e., no automatic
/// voting by bots). See Reddit rules for more details on what is considered
/// vote cheating or manipulation.
Future<void> upvote({bool waitForResponse = true}) async =>
_vote('1', waitForResponse);
_vote(VoteState.upvoted, waitForResponse);
}
2 changes: 1 addition & 1 deletion pubspec.yaml
@@ -1,5 +1,5 @@
name: draw
version: 0.9.1
version: 0.9.2
description: 'A fully-featured Reddit API wrapper for Dart, inspired by PRAW.'
homepage: 'https://github.com/draw-dev/DRAW'

Expand Down
2 changes: 1 addition & 1 deletion test/inbox/lib_inbox_all.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/inbox/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/inbox/lib_inbox_comment_replies.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/comments/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
6 changes: 3 additions & 3 deletions test/inbox/lib_inbox_mark_read_unread.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/unread/",
"{mark: false, limit: 1024}"
"{mark: false, limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down Expand Up @@ -58,7 +58,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/unread/",
"{mark: false, limit: 1024}"
"{mark: false, limit: 100}"
],
"response": {
"kind": "Listing",
Expand All @@ -84,7 +84,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/unread/",
"{mark: false, limit: 1024}"
"{mark: false, limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/inbox/lib_inbox_mentions.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/mentions",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/inbox/lib_inbox_messages.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/messages/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/inbox/lib_inbox_sent.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/sent/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/inbox/lib_inbox_submission_replies.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/selfreply/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/inbox/lib_inbox_unread.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/message/unread/",
"{mark: false, limit: 1024}"
"{mark: false, limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/submission/lib_submission_hide_unhide.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/new",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/submission/lib_submission_hide_unhide_multiple.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/new",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
6 changes: 3 additions & 3 deletions test/subreddit/lib_subreddit_banned.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/about/banned/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down Expand Up @@ -275,7 +275,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/about/banned/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down Expand Up @@ -307,7 +307,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/about/banned/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
4 changes: 2 additions & 2 deletions test/subreddit/lib_subreddit_contributor.json
Expand Up @@ -258,7 +258,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/about/contributors/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down Expand Up @@ -299,7 +299,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/about/contributors/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"kind": "Listing",
Expand Down
2 changes: 1 addition & 1 deletion test/subreddit/lib_subreddit_flair_call.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": [
Expand Down
4 changes: 2 additions & 2 deletions test/subreddit/lib_subreddit_flair_delete.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": [
Expand Down Expand Up @@ -31,7 +31,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": []
Expand Down
6 changes: 3 additions & 3 deletions test/subreddit/lib_subreddit_flair_delete_all.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": [
Expand All @@ -19,7 +19,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": [
Expand Down Expand Up @@ -50,7 +50,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": []
Expand Down
4 changes: 2 additions & 2 deletions test/subreddit/lib_subreddit_flair_set_flair.json
Expand Up @@ -3,7 +3,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": [
Expand Down Expand Up @@ -31,7 +31,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": [
Expand Down
4 changes: 2 additions & 2 deletions test/subreddit/lib_subreddit_flair_update.json
Expand Up @@ -24,7 +24,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": [
Expand Down Expand Up @@ -66,7 +66,7 @@
"always": false,
"request": [
"https://oauth.reddit.com/r/drawapitesting/api/flairlist/",
"{limit: 1024}"
"{limit: 100}"
],
"response": {
"users": []
Expand Down

0 comments on commit c26065f

Please sign in to comment.