mirror of
https://github.com/status-im/status-go.git
synced 2025-02-06 03:44:38 +00:00
Ensure timeline chat
This commit is contained in:
parent
9c792986dd
commit
30d7f36eb7
@ -33,7 +33,11 @@ const (
|
||||
ChatTypeCommunityChat
|
||||
)
|
||||
|
||||
const pkStringLength = 68
|
||||
const (
|
||||
// timelineChatID is a magic ID for the singleton timeline chat
|
||||
timelineChatID = "@timeline70bd746ddcc12beb96b2c9d572d0784ab137ffc774f5383e50585a932080b57cca0484b259e61cecbaa33a4c98a300a"
|
||||
pkStringLength = 68
|
||||
)
|
||||
|
||||
type Chat struct {
|
||||
// ID is the id of the chat, for public chats it is the name e.g. status, for one-to-one
|
||||
@ -285,6 +289,16 @@ func CreateOneToOneChat(name string, publicKey *ecdsa.PublicKey, timesource comm
|
||||
}
|
||||
}
|
||||
|
||||
func CreateTimelineChat(timesource common.TimeSource) *Chat {
|
||||
return &Chat{
|
||||
ID: timelineChatID,
|
||||
Name: "#" + timelineChatID,
|
||||
Timestamp: int64(timesource.GetCurrentTime()),
|
||||
Active: true,
|
||||
ChatType: ChatTypeTimeline,
|
||||
}
|
||||
}
|
||||
|
||||
func CreateCommunityChat(orgID, chatID string, orgChat *protobuf.CommunityChat, timesource common.TimeSource) *Chat {
|
||||
color := orgChat.Identity.Color
|
||||
if color == "" {
|
||||
|
@ -3071,7 +3071,16 @@ func (m *Messenger) MessageByChatID(chatID, cursor string, limit int) ([]*common
|
||||
return nil, "", err
|
||||
}
|
||||
|
||||
if chat.Timeline() {
|
||||
if chatID == timelineChatID {
|
||||
// If no timeline chat exists, creates it
|
||||
if chat == nil {
|
||||
err = m.ensureTimelineChat()
|
||||
if err != nil {
|
||||
return nil, "", err
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
var chatIDs = []string{"@" + contactIDFromPublicKey(&m.identity.PublicKey)}
|
||||
contacts, err := m.persistence.Contacts()
|
||||
if err != nil {
|
||||
@ -4172,7 +4181,14 @@ func (m *Messenger) EmojiReactionsByChatID(chatID string, cursor string, limit i
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if chat.Timeline() {
|
||||
if chatID == timelineChatID {
|
||||
if chat == nil {
|
||||
err = m.ensureTimelineChat()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
|
||||
var chatIDs = []string{"@" + contactIDFromPublicKey(&m.identity.PublicKey)}
|
||||
m.allContacts.Range(func(contactID string, contact *Contact) (shouldContinue bool) {
|
||||
if contact.IsAdded() {
|
||||
|
@ -228,3 +228,18 @@ func (m *Messenger) Join(chat *Chat) ([]*transport.Filter, error) {
|
||||
return nil, errors.New("chat is neither public nor private")
|
||||
}
|
||||
}
|
||||
|
||||
func (m *Messenger) ensureTimelineChat() error {
|
||||
chat, err := m.persistence.Chat(timelineChatID)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
if chat == nil {
|
||||
chat = CreateTimelineChat(m.getTimesource())
|
||||
}
|
||||
|
||||
m.allChats.Store(timelineChatID, chat)
|
||||
|
||||
return nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user