Skip to content
This repository was archived by the owner on Apr 7, 2023. It is now read-only.

Commit cc193bf

Browse files
committed
Allow setting "homeList" in ~/.nocturn
to replace timeline with list. Polling interval can be configured with "pollInterval".
1 parent d07f63f commit cc193bf

File tree

3 files changed

+34
-12
lines changed

3 files changed

+34
-12
lines changed

src/actions/tweets.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,20 @@ export const markAsRead = (tweet, account) => {
108108
return { type: MARK_AS_READ, tweet, account }
109109
}
110110

111-
export const loadHome = (account) => {
112-
return dispatch => {
113-
const client = new TwitterClient(account);
111+
const loadHomeOrList = (dispatch, account) => {
112+
const homeList = (account['homeList'] || '').split('/'); // k0kubun/listname
113+
const client = new TwitterClient(account);
114+
115+
if (homeList.length == 2) {
116+
const homeListOwner = homeList[0]; // k0kubun
117+
const homeListSlug = homeList[1]; // listname
118+
119+
client.listStatusesBySlug(homeListOwner, homeListSlug, 50, (tweets) => {
120+
for (let tweet of tweets) {
121+
dispatch(addTweet(tweet, account));
122+
}
123+
});
124+
} else {
114125
client.homeTimeline({ count: 50 }, (tweets) => {
115126
for (let tweet of tweets) {
116127
dispatch(addTweet(tweet, account));
@@ -119,17 +130,17 @@ export const loadHome = (account) => {
119130
}
120131
}
121132

133+
export const loadHome = (account) => {
134+
return dispatch => {
135+
loadHomeOrList(dispatch, account);
136+
}
137+
}
138+
122139
export const pollHome = (account) => {
123140
return dispatch => {
124141
const intervalSeconds = account['pollInterval'] || 60;
125-
const client = new TwitterClient(account);
126-
127142
setInterval(() => {
128-
client.homeTimeline({ count: 50 }, (tweets) => {
129-
for (let tweet of tweets) {
130-
dispatch(addTweet(tweet, account));
131-
}
132-
});
143+
loadHomeOrList(dispatch, account);
133144
}, intervalSeconds * 1000);
134145
}
135146
}
@@ -162,7 +173,7 @@ export const loadFavorites = (account) => {
162173
export const loadList = (listId, account, reset = false) => {
163174
return dispatch => {
164175
const client = new TwitterClient(account);
165-
client.listsStatuses(listId, 50, (tweets) => {
176+
client.listStatuses(listId, 50, (tweets) => {
166177
if (reset) {
167178
dispatch(clearAndSetTweets(tweets, account, 'lists'));
168179
} else {

src/utils/authentication.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export default class Authentication {
1313
// "accessTokenSecret": String,
1414
// "consumerKey": String, // optional
1515
// "consumerSecret": String, // optional
16+
// "homeList": String, // optional
1617
// "pollInterval": Integer, // optional
1718
// }
1819
static NOCTURN_CONFIG = '.nocturn';

src/utils/twitter-client.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ Nocturn prohibits over 20 mentions per minute.`);
159159
});
160160
}
161161

162-
listsStatuses(id, count, callback) {
162+
listStatuses(id, count, callback) {
163163
this.client.get('lists/statuses', { list_id: id, count: count }, (error, tweets, response) => {
164164
if (error) {
165165
console.log(JSON.stringify(error));
@@ -169,6 +169,16 @@ Nocturn prohibits over 20 mentions per minute.`);
169169
});
170170
}
171171

172+
listStatusesBySlug(owner, slug, count, callback) {
173+
this.client.get('lists/statuses', { owner_screen_name: owner, slug: slug, count: count }, (error, tweets, response) => {
174+
if (error) {
175+
console.log(JSON.stringify(error));
176+
return;
177+
}
178+
callback(tweets);
179+
});
180+
}
181+
172182
searchTweets(query, count, callback) {
173183
if (query === '') return;
174184

0 commit comments

Comments
 (0)