<commit_before>// This file is part of Ringot.
/*
Copyright 2016 tSU-RooT <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
	"fmt"
	"github.com/ChimeraCoder/anaconda"
	"github.com/mattn/go-runewidth"
	"net/url"
	"strconv"
	"strings"
)

type usertimelineview struct {
	*tweetview
	screenName string

	loading             lock
	loadNewTweetCh      chan []anaconda.Tweet
	loadIntervalTweetCh chan []anaconda.Tweet
}

func newUsertimelineview() *usertimelineview {
	return &usertimelineview{
		tweetview:           newTweetview(),
		loadNewTweetCh:      make(chan []anaconda.Tweet),
		loadIntervalTweetCh: make(chan []anaconda.Tweet),
	}
}

func (uv *usertimelineview) setUserScreenName(name string) {
	if uv.screenName != name {
		uv.screenName = name
		uv.tweets = []tweetstatus{tweetstatus{ReloadMark: true}}
	}
}

func (uv *usertimelineview) loadTweet(sinceID int64) {
	if uv.loading.isLocking() {
		return
	}
	uv.loading.lock()
	defer uv.loading.unlock()
	changeBufferState("Loading...")
	val := url.Values{}
	val.Add("count", strconv.Itoa(20))
	val.Add("screen_name", uv.screenName)
	if sinceID > 0 {
		val.Add("since_id", strconv.FormatInt(sinceID, 10))
	}
	timeline, err := api.GetUserTimeline(val)
	if err != nil {
		changeBufferState("Err:Loading")
		return
	}
	changeBufferState(fmt.Sprintf("Load!(%d tweets)", len(timeline)))
	uv.loadNewTweetCh <- timeline<commit_msg>Implement cache at UserTimeline View<commit_after>// This file is part of Ringot.
/*
Copyright 2016 tSU-RooT <<EMAIL>>

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package main

import (
	"fmt"
	"github.com/ChimeraCoder/anaconda"
	"github.com/mattn/go-runewidth"
	"net/url"
	"strconv"
	"strings"
)

type usertimelineview struct {
	*tweetview
	screenName string
	cache      map[string][]tweetstatus

	loading             lock
	loadNewTweetCh      chan []anaconda.Tweet
	loadIntervalTweetCh chan []anaconda.Tweet
}

func newUsertimelineview() *usertimelineview {
	return &usertimelineview{
		tweetview:           newTweetview(),
		cache:               make(map[string][]tweetstatus),
		loadNewTweetCh:      make(chan []anaconda.Tweet),
		loadIntervalTweetCh: make(chan []anaconda.Tweet),
	}
}

func (uv *usertimelineview) setUserScreenName(name string) {
	if name != uv.screenName {
		// Store
		uv.cache[uv.screenName] = uv.tweets

		if c, ok := uv.cache[name]; ok {
			uv.tweets = c
		} else {
			uv.tweets = []tweetstatus{tweetstatus{ReloadMark: true}}
		}
		uv.screenName = name
	}
}

func (uv *usertimelineview) loadTweet(sinceID int64) {
	if uv.loading.isLocking() {
		return
	}
	uv.loading.lock()
	defer uv.loading.unlock()
	changeBufferState("Loading...")
	val := url.Values{}
	val.Add("count", strconv.Itoa(20))
	val.Add("screen_name", uv.screenName)
	if sinceID > 0 {
		val.Add("since_id", strconv.FormatInt(sinceID, 10))
	}
	timeline, err := api.GetUserTimeline(val)
	if err != nil {
		changeBufferState("Err:Loading")
		return
	}
	changeBufferState(fmt.Sprintf("Load!(%d tweets)", len(timeline)))
	uv.loadNewTweetCh <- timeline
{'fraction_non_alphanumeric': 0.11399351459216762, 'fraction_numerical': 0.0074831628835120975, 'mean_word_length': 4.207792207792208, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5961812', 'n_tokens_mistral': 1446, 'n_tokens_neox': 1368, 'n_words': 368}