Skip to content

Commit

Permalink
Mark message as read if you quick reply (#19365)
Browse files Browse the repository at this point in the history
* Mark message as read if you quick reply

* Bail early
  • Loading branch information
MarcoPolo committed Sep 11, 2019
1 parent 44ca279 commit 7a59bd5
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 5 deletions.
21 changes: 19 additions & 2 deletions go/bind/notifications.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,9 @@ type ChatNotification struct {
BadgeCount int
}

func HandlePostTextReply(strConvID, tlfName string, body string) (err error) {
func HandlePostTextReply(strConvID, tlfName string, intMessageID int, body string) (err error) {
ctx := context.Background()
defer kbCtx.CTraceTimed(ctx, fmt.Sprintf("HandlePostTextReply()"), func() error { return flattenError(err) })()
outboxID, err := storage.NewOutboxID()
if err != nil {
return err
Expand All @@ -58,7 +60,22 @@ func HandlePostTextReply(strConvID, tlfName string, body string) (err error) {
return err
}
_, err = kbCtx.ChatHelper.SendTextByIDNonblock(context.Background(), convID, tlfName, body, &outboxID, nil)
return err

kbCtx.Log.CDebugf(ctx, "Marking as read from QuickReply: convID: %s", strConvID)
gc := globals.NewContext(kbCtx, kbChatCtx)
uid, err := utils.AssertLoggedInUID(ctx, gc)
if err != nil {
return err
}

msgID := chat1.MessageID(intMessageID)
if err = kbChatCtx.InboxSource.MarkAsRead(context.Background(), convID, uid, msgID); err != nil {
kbCtx.Log.CDebugf(ctx, "Failed to mark as read from QuickReply: convID: %s. Err: %s", strConvID, err)
// We don't want to fail this method call just because we couldn't mark it as aread
err = nil
}

return nil
}

func HandleBackgroundNotification(strConvID, body, serverMessageBody, sender string, intMembersType int,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void onReceive(Context context, Intent intent) {
if (messageBody != null) {

try {
WithBackgroundActive withBackgroundActive = () -> Keybase.handlePostTextReply(convData.convID, convData.tlfName, messageBody);
WithBackgroundActive withBackgroundActive = () -> Keybase.handlePostTextReply(convData.convID, convData.tlfName, convData.lastMsgId, messageBody);
withBackgroundActive.whileActive(context);
repliedNotification.setContentText("Replied");
} catch (Exception e) {
Expand All @@ -63,22 +63,26 @@ public void onReceive(Context context, Intent intent) {
class ConvData {
String convID;
String tlfName;
long lastMsgId;

ConvData(String convId, String tlfName) {
ConvData(String convId, String tlfName, long lastMsgId) {
this.convID = convId;
this.tlfName = tlfName;
this.lastMsgId = lastMsgId;
}

ConvData (Intent intent) {
Bundle data = intent.getBundleExtra("ConvData");
this.convID = data.getString("convID");
this.tlfName = data.getString("tlfName");
this.lastMsgId = data.getLong("lastMsgId");
}

public Intent intoIntent(Context context) {
Bundle data = new Bundle();
data.putString("convID", this.convID);
data.putString("tlfName", this.tlfName);
data.putLong("lastMsgId", this.lastMsgId);
Intent intent = new Intent(context, ChatBroadcastReceiver.class);
intent.putExtra("ConvData", data);
return intent;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ public void displayChatNotification(ChatNotification chatNotification) {
bundle.putString("convID", chatNotification.getConvID());
PendingIntent pending_intent = buildPendingIntent(bundle);

ConvData convData = new ConvData(chatNotification.getConvID(), chatNotification.getTlfName());
ConvData convData = new ConvData(chatNotification.getConvID(), chatNotification.getTlfName(), chatNotification.getMessage().getID());

NotificationCompat.Builder builder =
new NotificationCompat.Builder(this.context, KeybasePushNotificationListenerService.CHAT_CHANNEL_ID)
Expand Down

0 comments on commit 7a59bd5

Please sign in to comment.