diff --git a/lib.go b/lib.go index 3f1b14d..c7733bb 100644 --- a/lib.go +++ b/lib.go @@ -461,9 +461,9 @@ func c_AcceptConversation(profilePtr *C.char, profileLen C.int, conversation_id // AcceptConversation takes in a profileOnion and a handle to either a group or a peer and authorizes the handle // for further action (e.g. messaging / connecting to the server / joining the group etc.) -func AcceptConversation(profileOnion string, conversation_id int) { +func AcceptConversation(profileOnion string, conversationID int) { profile := application.GetPeer(profileOnion) - profile.AcceptConversation(int(conversation_id)) + profile.AcceptConversation(conversationID) } //export c_BlockContact @@ -488,6 +488,7 @@ type EnhancedMessage struct { model.Message ID int // the actual ID of the message in the database (not the row number) ContactImage string + Attributes map[string]string } func GetMessage(profileOnion string, conversationID int, messageIndex int) string { @@ -510,6 +511,7 @@ func GetMessage(profileOnion string, conversationID int, messageIndex int) strin Timestamp: time, } message.ID = messages[0].ID + message.Attributes = messages[0].Attr message.ContactImage = utils.RandomProfileImage(message.PeerID) } } @@ -544,6 +546,7 @@ func GetMessageByID(profileOnion string, conversationID int, messageIndex int) s Timestamp: time, } message.ID = messageIndex + message.Attributes = attr message.ContactImage = utils.RandomProfileImage(message.PeerID) } } @@ -575,6 +578,7 @@ func GetMessagesByContentHash(profileOnion string, handle int, contentHash strin PeerID: messages[0].Attr[constants2.AttrAuthor], Timestamp: time, } + // TODO this is mostly unused at this point, consider cleaning is up in 1.6 indexedMessages = append(indexedMessages, model.LocallyIndexedMessage{LocalIndex: offset, Message: msg}) } else { log.Errorf("error fetching local index {} ", err) @@ -858,7 +862,7 @@ func c_SetMessageAttribute(profile_ptr *C.char, profile_len C.int, conversation_ // of if `UpdateMessageAttribute` fails func SetMessageAttribute(profileOnion string, conversationID int, channelID int, messageID int, attributeKey string, attributeValue string) { profile := application.GetPeer(profileOnion) - if profile != nil { + if profile == nil { log.Errorf("called SetMessageAttribute with invalid profile handle: %v", profileOnion) return } diff --git a/utils/eventHandler.go b/utils/eventHandler.go index e7383b4..53997a4 100644 --- a/utils/eventHandler.go +++ b/utils/eventHandler.go @@ -259,6 +259,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { } else { // TODO This Conversation May Not Exist Yet...But we are not in charge of creating it... log.Errorf("todo wait for contact to be added before processing this event...") + return "" } var exists bool ev.Event.Data["Nick"], exists = ci.GetAttribute(attr.LocalScope, attr.ProfileZone, constants.Name) @@ -283,7 +284,7 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { } } } - ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data[event.GroupID]) + ev.Event.Data["Picture"] = RandomProfileImage(ev.Event.Data[event.RemotePeer]) conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) profile.SetConversationAttribute(conversationID, attr.LocalScope.ConstructScopedZonedPath(attr.ProfileZone.ConstructZonedPath(constants2.Archived)), event.False) case event.PeerAcknowledgement: @@ -293,19 +294,35 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { } case event.ContactCreated: conversationID, _ := strconv.Atoi(ev.Event.Data[event.ConversationID]) - handle := ev.Event.Data[event.RemotePeer] count, err := profile.GetChannelMessageCount(conversationID, 0) if err != nil { log.Errorf("error fetching channel message count %v %v", conversationID, err) } + conversationInfo, err := profile.GetConversationInfo(conversationID) + if err != nil { + log.Errorf("error fetching conversation info for %v %v", conversationID, err) + } + + // Resolve Conversation Auth State + // TODO: Align this with ACLs + authorization := model.AuthUnknown + if conversationInfo.Accepted { + authorization = model.AuthApproved + } + + // If ACL has blocked conversation then hide them... + if acl, exists := conversationInfo.ACL[conversationInfo.Handle]; exists && acl.Blocked { + authorization = model.AuthBlocked + } + lastMessage, _ := profile.GetMostRecentMessages(conversationID, 0, 0, 1) - ev.Event.Data["unread"] = strconv.Itoa(1) // we've just created this contact so by definition this must be 1... - ev.Event.Data["picture"] = RandomProfileImage(handle) + ev.Event.Data["unread"] = strconv.Itoa(count) // if this is a new contact with messages attached then by-definition these are unread... + ev.Event.Data["picture"] = RandomProfileImage(conversationInfo.Handle) ev.Event.Data["numMessages"] = strconv.Itoa(count) - ev.Event.Data["nick"] = handle - ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(handle)] - ev.Event.Data["authorization"] = string(model.AuthUnknown) + ev.Event.Data["nick"] = conversationInfo.Handle + ev.Event.Data["status"] = connections.ConnectionStateName[profile.GetPeerState(conversationInfo.Handle)] + ev.Event.Data["authorization"] = string(authorization) ev.Event.Data["loading"] = "false" ev.Event.Data["lastMsgTime"] = strconv.Itoa(getLastMessageTime(lastMessage)) case event.GroupCreated: @@ -332,8 +349,9 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string { return "" // suppress events from our own profile... } + // We do not know who this is...don't send any event until we see a message from them + // (at that point the conversation will have been created...) if cxnState == connections.AUTHENTICATED && contact == nil { - profile.NewContactConversation(ev.Event.Data[event.RemotePeer], model.AccessControl{Read: false, Append: false, Blocked: false}, false) return "" }