Skip to content

Commit

Permalink
guild results are now sorted by time desc
Browse files Browse the repository at this point in the history
  • Loading branch information
slatinsky committed Oct 20, 2022
1 parent e107013 commit f39b9e2
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 19 deletions.
51 changes: 34 additions & 17 deletions src/routes/channels/[guildId]/SearchFilter.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -264,29 +264,46 @@
// return a.timestamp < b.timestamp;
// });
// add searchPrevMessage and searchNextMessage to all messages
for (let i = 0; i < channelMessages.length; i++) {
let message = channelMessages[i];
let prevMessage = channelMessages[i - 1];
let nextMessage = channelMessages[i + 1];
if (prevMessage) {
message.searchPrevMessageChannelId = prevMessage.channelId;
} else {
message.searchPrevMessageChannelId = 'first';
}
if (nextMessage) {
message.searchNextMessageChannelId = nextMessage.channelId;
} else {
message.searchNextMessageChannelId = 'last';
}
}
found_messages_temp.push(...channelMessages);
$searched = true;
}
found_messages_temp = found_messages_temp.sort((a, b) => {
console.log(a.id, b.id, BigInt(a.id) < BigInt(b.id));
return BigInt(a.id) > BigInt(b.id) ? -1 : 1;
});
// loop through found messages and print channel name
for (let i = 0; i < found_messages_temp.length; i++) {
let message = found_messages_temp[i];
let channel = guild.channels[message.channelId]?.name
// console.log('channel', channel);
console.log('id', message.id);
}
// add searchPrevMessage and searchNextMessage to all messages
for (let i = 0; i < found_messages_temp.length; i++) {
let message = found_messages_temp[i];
let prevMessage = found_messages_temp[i - 1];
let nextMessage = found_messages_temp[i + 1];
if (prevMessage) {
message.searchPrevMessageChannelId = prevMessage.channelId;
} else {
message.searchPrevMessageChannelId = 'first';
}
if (nextMessage) {
message.searchNextMessageChannelId = nextMessage.channelId;
} else {
message.searchNextMessageChannelId = 'last';
}
}
console.log('found messages', found_messages_temp);
// set found messages
$found_messages = found_messages_temp;
}
console.log('----', guild.channels);
Expand Down
2 changes: 1 addition & 1 deletion src/routes/channels/[guildId]/[channelId]/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
</div>
{/if}
{/key}
<Messages messages={data.messages} guild={data.guild} guildId={data.guildId} channelId={data.channelId}/>
<Messages messages={Object.values(data.messages)} guild={data.guild} guildId={data.guildId} channelId={data.channelId}/>
<div id="bottom" />
</div>
</div>
Expand Down
2 changes: 1 addition & 1 deletion src/routes/channels/[guildId]/[channelId]/Messages.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

{#key channelId}
{#if messages}
<MessageGroup messages={messages} splitMessages={Object.values(messages)} {guild} {search}></MessageGroup>
<MessageGroup messages={messages} splitMessages={messages} {guild} {search}></MessageGroup>
{:else}
<div class="no-messages">No messages</div>
{/if}
Expand Down

0 comments on commit f39b9e2

Please sign in to comment.