|
1 | | - |
2 | | - |
3 | 1 | import DevChat, { LogEntry, LogOptions } from '../toolwrapper/devchat'; |
4 | | -import messageHistory from '../util/messageHistory'; |
5 | | -import { ApiKeyManager } from '../util/apiKey'; |
6 | | - |
7 | 2 |
|
8 | 3 | export interface LoadHistoryMessages { |
9 | 4 | command: string; |
@@ -62,57 +57,19 @@ export async function loadTopicHistoryLogs(topicId: string | undefined): Promise |
62 | 57 | return logEntries; |
63 | 58 | } |
64 | 59 |
|
65 | | -export function updateCurrentMessageHistory(topicId: string, logEntries: Array<LogEntry>): void { |
66 | | - messageHistory.clear(); |
67 | | - messageHistory.setTopic(topicId); |
68 | 60 |
|
69 | | - for (let i = 0; i < logEntries.length; i++) { |
70 | | - let entryOld = logEntries[i]; |
71 | | - let entryNew = { |
72 | | - date: entryOld.date, |
73 | | - hash: entryOld.hash, |
74 | | - request: entryOld.request, |
75 | | - text: entryOld.response, |
76 | | - user: entryOld.user, |
77 | | - parentHash: entryOld.parent, |
78 | | - context: entryOld.context, |
79 | | - }; |
80 | | - messageHistory.add(entryNew); |
81 | | - |
82 | | - } |
83 | | -} |
84 | | - |
85 | | -export function loadTopicHistoryFromCurrentMessageHistory(skip: number, count: number): LoadHistoryMessages { |
86 | | - const logEntries = messageHistory.getList(); |
87 | | - const newEntries = logEntries.map((entry) => { |
| 61 | +export async function loadTopicHistoryFromCurrentMessageHistory(topicId: string, skip: number, count: number): Promise< LoadHistoryMessages > { |
| 62 | + const logEntries = await loadTopicHistoryLogs(topicId); |
| 63 | + if (!logEntries) { |
88 | 64 | return { |
89 | | - hash: entry.hash, |
90 | | - parent: entry.parentHash, |
91 | | - user: entry.user, |
92 | | - date: entry.date, |
93 | | - request: entry.request, |
94 | | - response: entry.text, |
95 | | - context: entry.context, |
96 | | - } as LogEntry; |
97 | | - }); |
98 | | - |
99 | | - const logEntriesFlat = newEntries.reverse().slice(skip, skip + count).reverse(); |
100 | | - return { |
101 | | - command: 'loadHistoryMessages', |
102 | | - entries: logEntriesFlat, |
103 | | - } as LoadHistoryMessages; |
104 | | -} |
105 | | - |
106 | | -export async function historyMessagesBase(topicId: string): Promise<LoadHistoryMessages | undefined> { |
107 | | - const logEntriesFlat = await loadTopicHistoryLogs(topicId); |
108 | | - if (!logEntriesFlat) { |
109 | | - return undefined; |
| 65 | + command: 'loadHistoryMessages', |
| 66 | + entries: [], |
| 67 | + } as LoadHistoryMessages; |
110 | 68 | } |
111 | 69 |
|
112 | | - updateCurrentMessageHistory(topicId, logEntriesFlat); |
113 | | - |
| 70 | + const logEntriesFlat = logEntries.reverse().slice(skip, skip + count).reverse(); |
114 | 71 | return { |
115 | 72 | command: 'loadHistoryMessages', |
116 | | - entries: logEntriesFlat.length > 0 ? logEntriesFlat : [], |
| 73 | + entries: logEntriesFlat, |
117 | 74 | } as LoadHistoryMessages; |
118 | 75 | } |
0 commit comments