Ensure timeline chat

This commit is contained in:
Andrea Maria Piana 2021-04-23 10:31:53 +02:00
parent 9c792986dd
commit 30d7f36eb7
No known key found for this signature in database
GPG Key ID: AA6CCA6DE0E06424
4 changed files with 49 additions and 4 deletions

View File

@ -1 +1 @@
0.76.4+hotfix.1
0.76.4+hotfix.2

View File

@ -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 == "" {

View File

@ -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() {

View File

@ -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
}