sorting conversations by latest

This commit is contained in:
Roland Osborne 2022-05-09 15:17:05 -07:00
parent 8e14f51d58
commit 39372d8e0a
4 changed files with 25 additions and 7 deletions

View File

@ -67,7 +67,7 @@ func GetChannels(w http.ResponseWriter, r *http.Request) {
}
} else {
if err := store.DB.Preload("Channel.Topics", func(db *gorm.DB) *gorm.DB {
return store.DB.Order("topics.id DESC").Limit(1)
return store.DB.Order("topics.id DESC")
}).Preload("Channel.Cards.CardSlot").Preload("Channel.Groups.GroupSlot").Where("account_id = ? AND channel_id != 0", account.ID).Find(&slots).Error; err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return
@ -110,7 +110,7 @@ func GetChannels(w http.ResponseWriter, r *http.Request) {
}
} else {
if err := store.DB.Preload("Channel.Topics", func(db *gorm.DB) *gorm.DB {
return store.DB.Order("topics.id DESC").Limit(1)
return store.DB.Order("topics.id DESC")
}).Preload("Channel.Cards").Preload("Channel.Groups.Cards").Where("account_id = ? AND channel_id != 0", account.ID).Find(&slots).Error; err != nil {
ErrResponse(w, http.StatusInternalServerError, err)
return

View File

@ -58,12 +58,30 @@ export function useChannels() {
card.state.cards.forEach((value, key, map) => {
cardChannels.current.push(...Array.from(value.channels.values()));
});
updateState({ channels: [ ...channels.current, ...cardChannels.current ]});
let merged = [ ...channels.current, ...cardChannels.current ];
merged.sort((a, b) => {
if (a?.data?.channelSummary?.lastTopic?.created > b?.data?.channelSummary?.lastTopic?.created) {
return -1;
}
return 1;
});
updateState({ channels: merged });
}, [card])
useEffect(() => {
channels.current = Array.from(channel.state.channels.values());
updateState({ channels: [ ...channels.current, ...cardChannels.current ]});
let merged = [ ...channels.current, ...cardChannels.current ];
merged.sort((a, b) => {
if (a?.data?.channelSummary?.lastTopic?.created > b?.data?.channelSummary?.lastTopic?.created) {
return -1;
}
return 1;
});
for (let i = 0; i < merged.length; i++) {
console.log(merged[i]);
console.log(merged[i]?.data?.channelSummary?.lastTopic?.created);
}
updateState({ channels: merged });
}, [channel])
return { state, actions };

View File

@ -124,7 +124,7 @@ export function useCardContext() {
}
cur.data.detailRevision = channel.data.detailRevision;
}
if (cur.data.detailRevision != channel.data.detailRevision) {
if (cur.data.topicRevision != channel.data.topicRevision) {
if (channel.data.channelSummary != null) {
cur.data.channelSummary = channel.data.channelSummary;
}

View File

@ -41,8 +41,8 @@ export function useChannelContext() {
cur.data.detailRevision = channel.data.detailRevision;
}
if (cur.data.topicRevision != channel.data.topicRevision) {
if (channel.data.channelDetail != null) {
cur.data.channelDetail = channel.data.channelDetail;
if (channel.data.channelSummary != null) {
cur.data.channelSummary = channel.data.channelSummary;
}
else {
let summary = await getChannelSummary(access.current, channel.id);