Exemple #1
0
func getDM(api *anaconda.TwitterApi) dmThreads {
	// Get dms
	v := url.Values{}
	v.Set("count", "200")
	messages, _ := api.GetDirectMessages(v)

	// Sort dms into threads
	threads := make(dmThreads)
	timezone, _ := time.LoadLocation("Local")
	for _, message := range messages {
		t, _ := time.Parse("Mon Jan 2 15:04:05 -0700 2006", message.CreatedAt)
		if threads[message.SenderScreenName] == nil {
			threads[message.SenderScreenName] = &dmThread{to: message.SenderScreenName}
		}
		threads[message.SenderScreenName].messages = append(threads[message.SenderScreenName].messages, dm{from: message.SenderScreenName, text: message.Text, time: t.In(timezone)})
	}

	// Sort messages in threads
	for _, thread := range threads {
		sort.Sort(dmByDate(thread.messages))
	}

	return threads
}