NewMessageByID, Suppress Network Tests
continuous-integration/drone/pr Build is pending Details

This commit is contained in:
Sarah Jamie Lewis 2021-11-26 14:26:26 -08:00
parent edff87f77c
commit 92d2925622
2 changed files with 51 additions and 11 deletions

53
lib.go
View File

@ -476,7 +476,6 @@ func BlockContact(profileOnion string, conversationID int) {
profile.BlockConversation(conversationID)
}
//export c_GetMessage
// the pointer returned from this function **must** be Freed by c_Free
func c_GetMessage(profile_ptr *C.char, profile_len C.int, conversation_id C.int, message_index C.int) *C.char {
@ -518,6 +517,40 @@ func GetMessage(profileOnion string, conversationID int, messageIndex int) strin
return string(bytes)
}
//export c_GetMessageByID
// the pointer returned from this function **must** be Freed by c_Free
func c_GetMessageByID(profile_ptr *C.char, profile_len C.int, conversation_id C.int, message_index C.int) *C.char {
profile := C.GoStringN(profile_ptr, profile_len)
return C.CString(GetMessageByID(profile, int(conversation_id), int(message_index)))
}
func GetMessageByID(profileOnion string, conversationID int, messageIndex int) string {
var message EnhancedMessage
// There is an edge case that can happen on Android when the app is shutdown while fetching messages...
// The worker threads that are spawned can become activated again when the app is opened attempt to finish their job...
// In that case we skip processing and just return the empty message...
// Note: This is far less likely to happen now that the UI only requests messages *after* syncing has happened and
// these requests complete almost immediately v.s. being stalled for seconds to minutes on large groups.
if application != nil {
profile := application.GetPeer(profileOnion)
dbmessage, attr, err := profile.GetChannelMessage(conversationID, 0, messageIndex)
if err == nil {
time, _ := time.Parse(time.RFC3339Nano, attr[constants2.AttrSentTimestamp])
message.Message = model.Message{
Message: dbmessage,
Acknowledged: attr[constants2.AttrAck] == constants2.True,
Error: attr[constants2.AttrErr],
PeerID: attr[constants2.AttrAuthor],
Timestamp: time,
}
message.ID = messageIndex
message.ContactImage = utils.RandomProfileImage(message.PeerID)
}
}
bytes, _ := json.Marshal(message)
return string(bytes)
}
//export c_GetMessagesByContentHash
// the pointer returned from this function **must** be freed by calling c_Free
func c_GetMessagesByContentHash(profile_ptr *C.char, profile_len C.int, conversation_id C.int, contenthash_ptr *C.char, contenthash_len C.int) *C.char {
@ -534,15 +567,15 @@ func GetMessagesByContentHash(profileOnion string, handle int, contentHash strin
if err == nil {
messages, err := profile.GetMostRecentMessages(handle, 0, offset, 1)
if err == nil {
time, _ := time.Parse(time.RFC3339Nano, messages[0].Attr[constants2.AttrSentTimestamp])
msg := model.Message{
Message: messages[0].Body,
Acknowledged: messages[0].Attr[constants2.AttrAck] == constants2.True,
Error: messages[0].Attr[constants2.AttrErr],
PeerID: messages[0].Attr[constants2.AttrAuthor],
Timestamp: time,
}
indexedMessages = append(indexedMessages, model.LocallyIndexedMessage{LocalIndex: offset, Message: msg})
time, _ := time.Parse(time.RFC3339Nano, messages[0].Attr[constants2.AttrSentTimestamp])
msg := model.Message{
Message: messages[0].Body,
Acknowledged: messages[0].Attr[constants2.AttrAck] == constants2.True,
Error: messages[0].Attr[constants2.AttrErr],
PeerID: messages[0].Attr[constants2.AttrAuthor],
Timestamp: time,
}
indexedMessages = append(indexedMessages, model.LocallyIndexedMessage{LocalIndex: offset, Message: msg})
} else {
log.Errorf("error fetching local index {} ", err)
}

View File

@ -300,6 +300,10 @@ func (eh *EventHandler) handleProfileEvent(ev *EventProfileEnvelope) string {
cxnState := connections.ConnectionStateToType()[ev.Event.Data[event.ConnectionState]]
contact, _ := profile.FetchConversationInfo(ev.Event.Data[event.RemotePeer])
if ev.Event.Data[event.RemotePeer] == profile.GetOnion() {
return "" // suppress events from our own profile...
}
if cxnState == connections.AUTHENTICATED && contact == nil {
profile.NewContactConversation(ev.Event.Data[event.RemotePeer], model.AccessControl{Read: false, Append: false, Blocked: false}, false)
return ""
@ -345,7 +349,11 @@ func unwrap(original *EventProfileEnvelope) *event.Event {
func (eh *EventHandler) startHandlingPeer(onion string) {
eventBus := eh.app.GetEventBus(onion)
q := event.NewQueue()
// eventBus.Subscribe(event.NetworkStatus, q)
eventBus.Subscribe(event.NewMessageFromPeer, q)
eventBus.Subscribe(event.UpdatedProfileAttribute, q)
eventBus.Subscribe(event.PeerAcknowledgement, q)
eventBus.Subscribe(event.DeleteContact, q)
eventBus.Subscribe(event.AppError, q)
@ -364,7 +372,6 @@ func (eh *EventHandler) startHandlingPeer(onion string) {
eventBus.Subscribe(event.SendMessageToPeerError, q)
eventBus.Subscribe(event.ServerStateChange, q)
eventBus.Subscribe(event.PeerStateChange, q)
eventBus.Subscribe(event.NetworkStatus, q)
eventBus.Subscribe(event.ChangePasswordSuccess, q)
eventBus.Subscribe(event.ChangePasswordError, q)
eventBus.Subscribe(event.NewRetValMessageFromPeer, q)