mirror of
https://github.com/balzack/databag.git
synced 2025-02-14 12:39:17 +00:00
sorting conversations by latest
This commit is contained in:
parent
8e14f51d58
commit
39372d8e0a
@ -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
|
||||
|
@ -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 };
|
||||
|
@ -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;
|
||||
}
|
||||
|
@ -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);
|
||||
|
Loading…
Reference in New Issue
Block a user